簡體   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