@ 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,但只能用于正则表达式。其他所有内容都会被转译。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...