7

我正在尝试在 Next.js 项目中实现 eslint,但我不想next.config.js被 lint。我尝试添加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明确忽略引发错误的行,但最好完全忽略该文件。顺便说一句,除了那些我想忽略的文件之外,我的项目中还有很多其他文件。

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

4

0 回答 0