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

时间:2019-12-09 19:21:54

标签: javascript node.js typescript eslint eslintignore

我正在尝试在Next.js项目中实现eslint,但我不希望next.config.js受到限制。 我尝试将ignorePatterns添加到.eslintrc.json,添加.eslintignore文件并将eslintIgnore属性添加到我的package.json,它们似乎都具有相同的错误行为。 / p>

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

// .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)

要消除这2个错误,我尝试将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中添加内联注释,以显式忽略出现错误的行,但是最好完全忽略该文件。顺便说一下,除了要忽略的文件之外,我的项目中确实还有很多其他文件。

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

0 个答案:

没有答案