Lint-staged: Linting happening on unstaged files

Created on 13 Aug 2016  ·  4Comments  ·  Source: okonet/lint-staged

So things seem to work as I would expect in 1.0.1 but not in 2.0.3 or @next.

I have 2 changed .scss files. One contains a linting error, the other does not.

In 1.0.1 I am able to do the following with no issues.

git add non-error-file.scss
git commit -m 'test'

It seems in v2+, the linter runs on staged and unstaged files as I get an error about the unstaged error-file.scss. Is this the intended behavior? I have no issues being on version 1 but I generally like to keep up to date on things.

Most helpful comment

Ok, I found the problem. In your config you have

"eslint": "eslint --ext .js static",
"stylelint": "stylelint 'static/sass/**/*.scss'",

including extensions. lint-staged is looking at the package.json for scripts with the names you specified in lint-staged section:

"lint-staged": {
    "*.js": "eslint",
    "*.scss": "stylelint"
  }

So in this case it will call npm run stylelint that will lint _all_ your files that match the glob.

The most easy change would be to rename those tasks so they don't collide with real bin names. See https://github.com/okcoker/lint-staged-problem/pull/1

All 4 comments

It doesn't happen to me and it isn't how it should be. Can you put a repo with your files and your config so i can reproduce it on my own?

Here ya go.

Add a new line to nonerror.scss or nonerror.js and try to commit them. Here's a screenshot of the problem too.

screenshot 2016-08-15 06 32 57

Ok, I found the problem. In your config you have

"eslint": "eslint --ext .js static",
"stylelint": "stylelint 'static/sass/**/*.scss'",

including extensions. lint-staged is looking at the package.json for scripts with the names you specified in lint-staged section:

"lint-staged": {
    "*.js": "eslint",
    "*.scss": "stylelint"
  }

So in this case it will call npm run stylelint that will lint _all_ your files that match the glob.

The most easy change would be to rename those tasks so they don't collide with real bin names. See https://github.com/okcoker/lint-staged-problem/pull/1

Ah interesting. This works for me, thanks! Successfully upgraded.

Was this page helpful?
0 / 5 - 0 ratings