Tag Archives: ESLint

The body of a for-in should be wrapped in an if statement to filter unwanted properties from the pro

In ESLint mode, for in will report an error when traversing the object, which can be solved as follows:

let  val  = { shu: [ 1 , 2 , 3 ]} ;
for  (let  item  in  val) {
  if  (val.hasOwnProperty(item)) { 
    console.log(item);
  }
}

Because we should judge whether the object has its own properties (non-inheritance) before traversing an object. If the object is an empty object, then there is no need to traverse it to improve the efficiency of the code.

Arrow function should not return assignment no-return-assign

Arrow function should not return assignment no return assignment.

This paper describes the problems encountered in learning p221 of the latest Vue and vuejs in 2019, from introduction to mastery. Because the checking code of eslint is referenced, the checking error is reported. There is no problem with the code, it is the problem of eslint checking.
Solutions: 1. Remove eslint
2. Modify the code to conform to eslint
original code

   if (this.isSelectAll) {
        this.cartList.forEach(item => item.checked = false)
      } else {
        this.cartList.forEach(item => item.checked = true)
      }

Changed code

   if (this.isSelectAll) {
        this.cartList.forEach(item => { item.checked = false })
      } else {
        this.cartList.forEach(item => { item.checked = true })
      }

After learning the arrow function, we can know that the {} added can be omitted, but the rule of eslint requires this.