简体   繁体   English

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

[英]@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.我为我的测试文件配置了 ecmaVersion 6,但它不包含 ecma6 中不可用的 lint 功能。 Rules are working fine.规则运行良好。

.eslintrc.js .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 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预期结果因为 Object.values() 是 ecma 2017 中引入的一个特性,它应该 lint 该行,因为我指定了 ecmaVersion 6 aka 2015

Actual Result It's not linting实际结果不是掉毛

Additional Info It's not linting in IntelliJ and also not via console.附加信息它不是在 IntelliJ 中 linting,也不是通过控制台。 No errors in console.控制台中没有错误。 Upgraded @typescript-eslint/parser 2.25.0 to 4.1 but that didn't help.将 @typescript-eslint/parser 2.25.0 升级到 4.1 但这没有帮助。

Versions版本

  • @typescript-eslint/parser 2.25.0 @typescript-eslint/解析器 2.25.0
  • TypeScript 3.9.2打字稿 3.9.2
  • ESLint 6.3.0 ESLint 6.3.0
  • node 14.4.0节点 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.好的,根据开发人员的说法,ecmaVersion 与@typescript-eslint/parser 结合使用并没有太大作用。 I'm now using eslint-plugin-es to lint ecma features.我现在使用 eslint-plugin-es 来 lint ecma 功能。 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.如果您使用 typescript(新的 regexp 语法除外),则不需要对 ecma6 中不可用的功能进行 lint,因为 typescript 会将新功能转换为 ecma6。

You can use eslint-plugin-es, but only for regular expressions.您可以使用 eslint-plugin-es,但只能用于正则表达式。 Everything else gets transpiled.其他一切都会被转译。

暂无
暂无

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

相关问题 env.es6=true 和 parserOptions.ecmaVersion=6 at.eslintrc.js 有什么区别? - What the difference between env.es6=true and parserOptions.ecmaVersion=6 at .eslintrc.js? 为什么 eslint 考虑 JSX 或一些反应 @types undefined,因为将 typescript-eslint/parser 升级到版本 4.0.0 - Why eslint consider JSX or some react @types undefined, since upgrade typescript-eslint/parser to version 4.0.0 eslint 缩进和@typescript-eslint/indent 冲突 - eslint indent and @typescript-eslint/indent conflict 无法加载在 'package.json » eslint-config-react-app#overrides[0]' 中声明的解析器 '@typescript-eslint/parser':找不到模块 'typescript' - Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript' ESLint 无法识别“@typescript-eslint/eslint-plugin” - ESLint is not recognizing "@typescript-eslint/eslint-plugin" angular-eslint 和 typescript-eslint 之间的区别 - Difference between angular-eslint and typescript-eslint ESLint:8.0.0 无法加载插件'@typescript-eslint' - ESLint: 8.0.0 Failed to load plugin '@typescript-eslint' @typescript-eslint/no-unsafe-* 规则的新 eslint 错误 - New eslint errors with the @typescript-eslint/no-unsafe-* rules TypeScript 和 typescript-eslint 有重叠的用途吗? - Do TypeScript and typescript-eslint have overlapping purposes? @typescript-eslint/no-unused-vars 类型声明中的误报 - @typescript-eslint/no-unused-vars false positive in type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM