Lint-staged: Updating to lint-staged v9 issue -- using .eslintignore throws warnings!

Created on 9 Oct 2019  ·  7Comments  ·  Source: okonet/lint-staged

Recently we've updated to use the latest version of eslint from v6. It appears that lint-staged no longer allows an advanced config. Instead of configuring lint-staged directly, you recommend using .prettierignore (or in our case .eslintignore) to ignore files.

Unfortunately this doesn't work very well because with .eslintignore we get a warning in the console. Here's what it looks like in my terminal:

git commit -am "test"
husky > pre-commit (node v10.16.3)
🔍  Finding changed files since git revision 200ebaddb.
🎯  Found 0 changed files.
✅  Everything is awesome!
  ↓ Stashing changes... [skipped]
    → No partially staged files found...
  ❯ Running tasks...
    ❯ Running tasks for client/**/*.js|server/src/**/*.js|e2e-tests/cypress/**/*.js
      ✖ eslint --rule 'react/jsx-curly-brace-presence: 1' --fix --max-warnings=0
        node addCopyright.js
        git add



✖ eslint --rule 'react/jsx-curly-brace-presence: 1' --fix --max-warnings=0 found some errors. Please fix them and try committing again.

/Users/tnrich/Sites/hde/server/src/data-lib/entities/aaSequence/countAASequence.js
0:0  warning  File ignored because of a matching ignore pattern. Use "--no-ignore" to override

✖ 1 problem (0 errors, 1 warning)

The crucial part is that warning File ignored because of a matching ignore pattern.. Lint staged now passes all the files eslint which is causing the ignore warning.

Not quite sure what to do here. Any suggestions @okonet ?

All 7 comments

Quick update, it look like there is an rfc in eslint to fix it on their end: https://github.com/eslint/eslint/issues/12206

Re-opening this until some solution is worked out either on the lint-staged side or on the eslint side. For some reason that rfc was closed and a new one will be needed.

I don't see the problem here. It works as expected so I'm not sure what's this is about. We don't change the behavior at any time.

@okonet this has been an issue since I've upgraded to v9 and it hasn't gone away. Either the advanced config option was taken away needs to be brought back or eslint needs a way to prevent this warning from being issued -- warning File ignored because of a matching ignore pattern.

Until that happens our precommit hook will continue to fail in cases where we want it to pass. Definitely STILL an issue!

I don't get why is the waning failing your pre-commit hook. It's probably because you're using --max-warnings=0 so my suggestion is to use a config as a function and filter files there or fix the issue on the ESLint side (that's really weird it's the same severity as a warning of the linter)

Just to clarify: we won't add support for the legacy advanced config back since it's been migrated to functions format: https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands

Thanks for the help @okonet not your fault. I think that eslint needs to add an option to not throw a warning if a file is ignored by .eslintignore but is specifically passed to eslint like eslint myIgnoreFile.js.

In the meantime I find that this is a decent workaround:

//lint-staged.config.js
const fs = require("fs");
const micromatch = require("micromatch");

const ignore = fs.readFileSync(".eslintignore", "utf8");
const lines = ignore.match(/[^\r\n]+/g);
const jsRunners = files => {
    const match = micromatch.not(files, lines);
    return match.map(
      file =>
        `eslint ${file} --rule 'react/jsx-curly-brace-presence: 1' --fix --max-warnings=0`
    );
  };

module.exports = {
  "client/**/*.js": jsRunners,
  "server/src/**/*.js": jsRunners,
  "e2e-tests/cypress/**/*.js": jsRunners,
  "tg-iso-lims/src/**/*.js|cypress/**/*.js": jsRunners,
  "*.css": ["node addCopyright.js", "git add"]
};
Was this page helpful?
0 / 5 - 0 ratings

Related issues

okonet picture okonet  ·  5Comments

jasonslyvia picture jasonslyvia  ·  3Comments

OriginUnknown picture OriginUnknown  ·  4Comments

thedamon picture thedamon  ·  3Comments

hadrienl picture hadrienl  ·  8Comments