一些使用eslint检查的报错、原因和处理

1.error Expected an assignment or function call and instead saw an expression no-unused-expressions

需要有一个声明或者函数的调用而不是单单看到一个表达式在这里插入代码片

2.‘xxx’ is assigned a value but never used no-unused-vars
2.1 ‘xxx’ is defined a value but never used no-unused-vars

分配了值但未被使用, 定义了未使用
一般注释处理

3.Unexpected mutation of “xxx” prop vue/no-mutating-props

vue2中单项数据流的概念,这是Vue官方防止从子组件意外变更父级组件的状态内容
解决:
props:{
  flag: Boolean
}
data(){
  selfFlag: this.flag
}

4.error Expected error to be handled handle-callback-err

异常没有处理,如catch,对error处理一下就🆗

5.error Unexpected use of comma operator no-sequences

符号不对,检查一下标点符号

6.error Expected an assignment or function call and inststead saw an expression no-unused-expressions

期望一个赋值或函数调用,却看到一个表达式未使用表达式

7.error Unexpected lexical declaration in case block no-case-declarations

该规则禁止词法声明 (letconstfunctionclass) 出现在 casedefault 子句中。
原因是,词法声明在整个 switch 语句块中是可见的,
但是它只有在运行到它定义的 case 语句时,才会进行初始化操作。

为了保证词法声明语句只在当前 case 语句中有效,将你子句包裹在块中。
正确写法:switch前声明变量,或用var声明,或用{}将语句在case里包裹起来

const a = 0;
switch (foo) {
    case 1: {
        let x = 1;
        break;
    }
    case 2: {
        const y = 2;
        break;
    }
    case 3: {
        function f() {}
        break;
    }
    case 4:
        var z = 4;
        break;
    default: {
        class C {}
    }
}

8.error Expected the Promise rejection reason to be an Error prefer-promise-reject-errors

promise的reject中需要传入的是一个Error对象.:
reject(new Error('err'))

9.error Expected an assignment or function call and instead saw an
expression no-unused-expressions

期望是赋值或函数调用, 不能是一个表达式 ( 意思就是函数没有调用,要加括号=>"()" )

10.error Unexpected use of comma operator no-sequences

写错逗号了,比如将语句结束的";" 
写成了"," // 此情况也会导致 第9点的出现

例子:
getTodo(params).then(({code, message, data}) => {
    this.current++, // 本该是 ';'
    ......
  }
  this.loading = false;
});

430:10  error  Expected an assignment or function call and instead saw an 
expression  no-unused-expressions
446:11  error  Unexpected use of comma operator
            no-sequences
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值