繁体   English   中英

@typescript-eslint/parser parserOptions.ecmaVersion 忽略/不检查

[英]@typescript-eslint/parser parserOptions.ecmaVersion ignored / not linting

我为我的测试文件配置了 ecmaVersion 6,但它不包含 ecma6 中不可用的 lint 功能。 规则运行良好。

.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
  • 打字稿 3.9.2
  • ESLint 6.3.0
  • 节点 14.4.0

那么我做错了什么?

好的,根据开发人员的说法,ecmaVersion 与@typescript-eslint/parser 结合使用并没有太大作用。 我现在使用 eslint-plugin-es 来 lint ecma 功能。 这按预期工作。

如果您使用 typescript(新的 regexp 语法除外),则不需要对 ecma6 中不可用的功能进行 lint,因为 typescript 会将新功能转换为 ecma6。

您可以使用 eslint-plugin-es,但只能用于正则表达式。 其他一切都会被转译。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM