[英]@typescript-eslint/parser parserOptions.ecmaVersion ignored / not linting
I configured ecmaVersion 6 for my test files but it does not lint features that are not available in ecma6.我为我的测试文件配置了 ecmaVersion 6,但它不包含 ecma6 中不可用的 lint 功能。 Rules are working fine.
规则运行良好。
.eslintrc.js .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 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"
]
}
Example code:示例代码:
const myObj = { a: 'somestring', b: 42, c: false };
const tmp = Object.values(object1);
Expected Result Because Object.values() is a feature introduced in ecma 2017 it should lint that line because I specified ecmaVersion 6 aka 2015预期结果因为 Object.values() 是 ecma 2017 中引入的一个特性,它应该 lint 该行,因为我指定了 ecmaVersion 6 aka 2015
Actual Result It's not linting实际结果不是掉毛
Additional Info It's not linting in IntelliJ and also not via console.附加信息它不是在 IntelliJ 中 linting,也不是通过控制台。 No errors in console.
控制台中没有错误。 Upgraded @typescript-eslint/parser 2.25.0 to 4.1 but that didn't help.
将 @typescript-eslint/parser 2.25.0 升级到 4.1 但这没有帮助。
Versions版本
So what I'm doing wrong?那么我做错了什么?
Ok, the ecmaVersion doesn't do much in combination with @typescript-eslint/parser according to the developer.好的,根据开发人员的说法,ecmaVersion 与@typescript-eslint/parser 结合使用并没有太大作用。 I'm now using eslint-plugin-es to lint ecma features.
我现在使用 eslint-plugin-es 来 lint ecma 功能。 That works as intended.
这按预期工作。
You do not need to lint for features unavailable in ecma6 if you are using typescript (except for new regexp syntax), because typescript will transpile new features to ecma6.如果您使用 typescript(新的 regexp 语法除外),则不需要对 ecma6 中不可用的功能进行 lint,因为 typescript 会将新功能转换为 ecma6。
You can use eslint-plugin-es, but only for regular expressions.您可以使用 eslint-plugin-es,但只能用于正则表达式。 Everything else gets transpiled.
其他一切都会被转译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.