【发布时间】:2020-12-26 18:47:23
【问题描述】:
我为我的测试文件配置了 ecmaVersion 6,但它不会检查 ecma6 中不可用的功能。规则运行良好。
.eslintrc.js
module.exports = {
root: true,
extends: ['airbnb-base', '.eslintrc.airbnbonlywarnings.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 6,
ecmaFeatures: {
blockBindings: false,
forOf: false
},
project: 'tsconfig.json',
tsconfigRootDir: __dirname
},
plugins: ['@typescript-eslint'],
env: {
browser: true,
jasmine: true,
node: true,
mocha: false,
amd: true
},
overrides: [{
files: ['**/e2e/**/*.ts', '**/e2e/**/*.js'],
parserOptions: {
ecmaVersion: 6,
project: 'tsconfig.e2e.json'
}
}]
}
tsconfig.e2e.json
{
"compilerOptions": {
"rootDir": ".",
"outDir": "build-e2e",
"allowJs": true,
"incremental": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es6",
"noEmitOnError": true,
"strict": false,
"typeRoots" :[
"./@types",
"./node_modules/@types"
],
"removeComments": false,
"sourceMap": false
},
"include": [
"@types/**/*.d.ts",
"test/protractor/**/*.ts",
"test/protractor/**/*.js",
"src/**/test/e2e/**/*.ts",
"src/**/test/e2e/**/*.js",
"grunt/users/**/fake.config.ts"
],
"exclude":[
"./node_modules",
"./customer_bundles"
]
}
示例代码:
const myObj = { a: 'somestring', b: 42, c: false };
const tmp = Object.values(object1);
预期结果 因为 Object.values() 是 ecma 2017 中引入的一项功能,所以它应该对该行进行 lint,因为我指定了 ecmaVersion 6 aka 2015
实际结果 不是掉毛
其他信息 它不是 IntelliJ 中的 linting,也不是通过控制台。控制台没有错误。 将 @typescript-eslint/parser 2.25.0 升级到 4.1,但这没有帮助。
版本
- @typescript-eslint/解析器 2.25.0
- TypeScript 3.9.2
- ESLint 6.3.0
- 节点 14.4.0
那么我做错了什么?
【问题讨论】:
-
我没有在您的 .eslint 文件中看到“env”。检查eslint.org/docs/user-guide/…
-
我认为它与我的用例无关,但它在代码中,我现在在上面的示例中添加了它。
-
添加 "env": { "es6": true } } 并检查
标签: javascript eslint ecma typescript-eslintparser