11

I'm trying to implement eslint in a Next.js project but I don't want next.config.js to be linted. I tried adding ignorePatterns to .eslintrc.json, adding a .eslintignore file and adding eslintIgnore property to my package.json and they all seem to have the same erroneous behavior.

When leaving only directory paths it works as expected:

// .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"]
  }
}

and the output is:

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

To remove those 2 errors I try to add next.config.js to ignorePatterns like this:

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

but then this is the output I get:

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.

Which makes no sense since I don't have a pattern .. I could add inline comments to next.congif.js to explicit ignore the lines there are throwing the errors, but it would be best to ignore the file altogether. By the way I do have a bunch of other files in my project apart from those I want to ignore.

Am I missing anything? Is there any other way to ignore specific files from the project?

Thiago Loddi
  • 2,212
  • 4
  • 21
  • 35
  • 8
    Actually from the bunch of files I had, none of them were `.js`, and since eslint only reads `.js` by default I was indeed ignoring all files in the project. I fixed it adding the `--ext` flag: `eslint . --ext js,jsx,ts,tsx` – Thiago Loddi Dec 09 '19 at 20:11
  • Give @Thiago Loddi an oscars please! – Kumar Abhirup Mar 29 '20 at 06:49

0 Answers0