如何解决@ typescript-eslint / parser parserOptions.ecmaVersion已忽略/不掉毛
我为我的测试文件配置了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中引入的功能,所以应该删除该行,因为我指定了ecmaVersion 6 aka 2015
实际结果 不掉毛
其他信息 它不是在IntelliJ中也没有通过控制台。控制台中没有错误。 将@ typescript-eslint / parser 2.25.0升级到4.1,但这没有帮助。
版本
- @ typescript-eslint / parser 2.25.0
- TypeScript 3.9.2
- ESLint 6.3.0
- 节点14.4.0
那我做错了吗?
解决方法
好的,根据开发人员的说法,ecmaVersion与@ typescript-eslint / parser结合使用的功能不多。我现在使用eslint-plugin-es来完成ecma功能。可以按预期工作。
,如果您使用的是 typescript(新的正则表达式语法除外),则不需要对 ecma6 中不可用的功能进行 lint,因为 typescript 会将新功能转换为 ecma6。
您可以使用 eslint-plugin-es,但只能用于正则表达式。其他所有内容都会被转译。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。