简体   繁体   中英

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

I configured ecmaVersion 6 for my test files but it does not lint features that are not available in ecma6. Rules are working fine.

.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"
    ]
}

Example code:

const myObj = { a: 'somestring', b: 42, c: false };
const tmp = Object.values(object1);

Expected Result Because Object.values() is a feature introduced in ecma 2017 it should lint that line because I specified ecmaVersion 6 aka 2015

Actual Result It's not linting

Additional Info It's not linting in IntelliJ and also not via console. No errors in console. Upgraded @typescript-eslint/parser 2.25.0 to 4.1 but that didn't help.

Versions

  • @typescript-eslint/parser 2.25.0
  • TypeScript 3.9.2
  • ESLint 6.3.0
  • node 14.4.0

So what I'm doing wrong?

Ok, the ecmaVersion doesn't do much in combination with @typescript-eslint/parser according to the developer. I'm now using eslint-plugin-es to lint ecma features. That works as intended.

You do not need to lint for features unavailable in ecma6 if you are using typescript (except for new regexp syntax), because typescript will transpile new features to ecma6.

You can use eslint-plugin-es, but only for regular expressions. Everything else gets transpiled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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