我用——template typescript创建了一个新的React Native项目

我删除了作为样板的一部分的模板目录。

然后我继续添加ESLint:

module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  extends: ["airbnb-typescript-prettier"]
};

然而,当我打开babel.config.js时,我得到这个错误

解析错误:"parserOptions. "已经为@typescript-eslint/parser设置了Project "。 该文件与您的项目配置不匹配:/Users/Dan/site/babel.config.js。 该文件必须包含在至少一个提供的项目中。eslint


当前回答

只需在.eslintrc.js文件中添加以下代码。

ignorePatterns: ['.eslintrc.js']

其他回答

我的问题是在PHPStorm中,我设置了工作导览:

我清除了它,一切都工作了:\

您需要将该文件添加到tsconfig include数组中。 更多细节请参见typescript-eslint/typescript-eslint#967。

经过大量的努力和尝试来纠正这个错误。我知道我的问题是我把忽略文件保存为eslintignore而不是。eslintignore。

因此,它不能忽略。js,。d。Ts文件dist被忽略。

在".eslintignore"中添加一行:

.eslintrc.js

你可以为eslint配置创建一个单独的TypeScript配置文件(tsconfig.eslint.json)。该文件扩展了tsconfig配置和设置,包括必须检测的文件的key。

.eslint.js:

// ...
parserOptions: {
  // ...
  project: "./tsconfig.eslint.json",
  // ...
},
// ...

tsconfig.eslint.json:

{
  "extends": "./tsconfig.json",
  "include": [
    // ...
    "babel.config.js"
  ]
}

或者如果你想忽略它,你可以把它放在。eslintignore。

eslintignore:

// ...
babel.config.js