简体   繁体   English

Eslint 不检查 .ts 或 .tsx 文件

[英]Eslint isn't checking .ts or .tsx files

When I run yarn lint or eslint directly, it's not checking my .ts or .tsx files at all.当我直接运行yarn linteslint ,它根本不检查我的.ts.tsx文件。

Have tried fiddling with various configuration options.尝试摆弄各种配置选项。 I've installed the appropriate plugins and parsers.我已经安装了适当的插件和解析器。

{
  "extends": ["airbnb", "eslint", "eslint:recommended", "plugin:react/recommended", "plugin:import/typescript"],
  "parser": "@typescript-eslint/parser",
  "env": {
    "browser": true
  },
  "plugins": ["react", "jsx-a11y", "import", "@typescript-eslint"],
  "parserOptions": {
    "ecmaVersion": 7,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "max-len": [
      "error",
      120,
      2,
      {
        "ignoreUrls": true,
        "ignoreStrings": true,
        "ignoreComments": true,
        "ignoreTrailingComments": true,
        "ignoreRegExpLiterals": true
      }
    ],
    "import/extensions": ["error", "never", { "packages": "always" }],
    "react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }],
  },
  "settings": {
    "import/resolver": {
      "babel-module": {},
      "node": {
        "extensions": [".js", ".jsx", ".json", ".ts", ".tsx"]
      }
    },
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    }   
  }
}

If I pass --ext "ts,tsx" to eslint, the errors I get are completely off (it seems to be treating the files like JS files).如果我将--ext "ts,tsx"传递给 eslint,我得到的错误将完全关闭(它似乎将文件视为 JS 文件)。

I have VSCode and VSCode seems to be linting all my files correctly (js as JS, ts and tsx as Typescript).我有 VSCode 并且 VSCode 似乎正确地整理了我的所有文件(js 作为 JS,ts 和 tsx 作为 Typescript)。

尝试运行yarn run eslint src/**/*.{js,ts,tsx}其中src是您想要 lint 的目录

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

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