我在 JS 项目中集成了 eslint,但我收到一个类属性错误。 例如,在这种情况下:
class RateLimit {
delay = 2 * 1000;
...
}
我收到“解析错误:意外的标记=”。 这是我的 eslint 配置:
module.exports = {
"env": {
"node": true,
"es2017": true
},
"extends": [
"eslint:recommended",
"prettier"
],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
"no-unused-vars": [ 2, { "args": "all", "argsIgnorePattern": "_$" } ],
"semi": [ "error", "always" ],
"no-undef": "error",
"indent": [ "error", 2 ],
"quotes": [ "error", "double" ],
"arrow-parens": [ "error", "always" ],
"no-extra-semi": "error",
"no-magic-numbers": [ "warn", { ignore: [ -1, 0, 1 ] } ],
"eqeqeq": [ "warn", "always" ],
"comma-spacing": [ "error", { before: false, after: true } ],
"array-bracket-spacing": [ "error", "always" ],
"object-curly-spacing": [ "error", "always" ],
"no-debugger":"off",
"no-multiple-empty-lines": [ "error", { max: 1 } ]
},
};
我想知道我可以添加到规则对象中的正确密钥是什么, 或者我如何才能仅针对所有规则禁用该行?
我尝试过添加
/* eslint-disable-next-line */
和
// eslint-disable-next-line no-unexpected-token
但这些都不起作用。
我可以通过在解析器选项中将 ECMA 版本更改为 2022 来修复错误
要禁用所有规则:
/* eslint-disable */
const max = 10;
这将禁用以下代码的 eslint 规则,直到文件结束
要禁用特定代码块的规则:
/* eslint-disable */
const max = 10;
if(max === 10) {
console.log("Reached the limit");
}
/* eslint-enable */