【问题标题】:ESLint - Getting error - 'expect' is assigned a value but never usedESLint - 出现错误 - 'expect' 被赋值但从未使用过
【发布时间】:2017-02-28 15:39:55
【问题描述】:
const supertest = require('supertest-as-promised');  
const expect = require('chai').expect;  

const request = supertest(process.env.BASE_URI);`

我收到这个 ESLint 错误:

'expect' 被赋值但从未使用'

对于expect 声明。我可以进行哪些更改来消除所有 .js 文件中的这些错误?

【问题讨论】:

    标签: javascript eslint supertest


    【解决方案1】:

    您遇到了来自 ESLint 的 no-unused-vars 规则。您可以从他们的documentation 了解更多相关信息。

    ESLint 向您发出警告的原因是您已声明 expect 并为其分配了值。

    const expect = require('chai').expect; 
    

    但是你没有在任何地方使用它。

    要消除错误,您需要在某处使用expect

    describe('A test', () => {
      it('should do something', () => {
        expect(something).to.be.true;
      });
    });
    

    【讨论】:

    • 作为改进给出的示例 - expect(something).to.be.true - 触发 ESLint 警告 no-unused-expressions
    【解决方案2】:

    可以在 .eslint 文件中使用它

    {
    "rules": {
        "no-unused-vars": ["error", { "vars": "local", "args": "after-used", "ignoreRestSiblings": true }]
      }
    }
    

    欲了解更多信息,请查看此链接 http://eslint.org/docs/rules/no-unused-vars

    【讨论】:

      猜你喜欢
      • 2021-04-09
      • 2021-12-05
      • 2019-08-12
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 2019-05-08
      • 2018-04-20
      • 2012-04-18
      相关资源
      最近更新 更多