eslint 在将特定文件添加到ignorePatterns时会忽略所有文件

问题描述 投票:0回答:1

我正在尝试在 Next.js 项目中实现 eslint,但我不希望

next.config.js
被 linted。 我尝试将
ignorePatterns
添加到
.eslintrc.json
,添加
.eslintignore
文件并将
eslintIgnore
属性添加到我的
package.json
,它们似乎都有相同的错误行为。

仅保留目录路径时,它会按预期工作:

// .eslintrc.json

{
  "env": {
    "browser": true
  },
  "extends": ["airbnb", "plugin:@typescript-eslint/recommended"],
  "plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
  "parser": "@typescript-eslint/parser",
  "ignorePatterns": ["graphql/generated/", "third-party/"],
  "rules": { /* ... */ },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "typescript": {}
    },
    "polyfills": ["fetch"]
  }
}

输出为:

/Users/mac-user/development/my-project/next.config.js
  1:18  error  Require statement not part of import statement  @typescript-eslint/no-var-requires
  2:17  error  Require statement not part of import statement  @typescript-eslint/no-var-requires

✖ 2 problems (2 errors, 0 warnings)

为了消除这两个错误,我尝试将

next.config.js
添加到
ignorePatterns
,如下所示:

  "ignorePatterns": ["graphql/generated/", "third-party/", "next.config.js"],

但这就是我得到的输出:

Oops! Something went wrong! :(

ESLint: 6.7.2.

You are linting ".", but all of the files matching the glob pattern "." are ignored.

If you don't want to lint these files, remove the pattern "." from the list of arguments passed to ESLint.

If you do want to lint these files, try the following solutions:

* Check your .eslintignore file, or the eslintIgnore property in package.json, to ensure that the files are not configured to be ignored.
* Explicitly list the files from this glob that you'd like to lint on the command-line, rather than providing a glob as an argument.

这没有任何意义,因为我没有模式

.
。我可以向
next.congif.js
添加内联注释以显式忽略引发错误的行,但最好完全忽略该文件。顺便说一句,除了我想忽略的文件之外,我的项目中确实还有很多其他文件。

我错过了什么吗?有没有其他方法可以忽略项目中的特定文件?

javascript node.js typescript eslint eslintignore
1个回答
0
投票

只需将文件的完整相对路径放在 eslint 配置文件中

© www.soinside.com 2019 - 2024. All rights reserved.