【问题标题】:@typescript-eslint/parser parserOptions.ecmaVersion ignored / not linting@typescript-eslint/parser parserOptions.ecmaVersion 被忽略/不 linting
【发布时间】: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


【解决方案1】:

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

你可以使用 eslint-plugin-es,但只能用于正则表达式。其他所有内容都会被转译。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-01
      • 2023-03-25
      • 2020-02-18
      • 2020-12-28
      • 1970-01-01
      • 2020-05-23
      • 1970-01-01
      • 2018-08-31
      相关资源
      最近更新 更多