Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not added to commit still being linted #755

Closed
ivnnv opened this issue Dec 16, 2019 · 11 comments
Closed

File not added to commit still being linted #755

ivnnv opened this issue Dec 16, 2019 · 11 comments

Comments

@ivnnv
Copy link

ivnnv commented Dec 16, 2019

Description

After reading the famous issue + feature #62 I think it doesn't cover the case when you have some files with changes and you want to ignore them from now (because you know they are not ready yet for committing).
But lint-staged is still checking for those files so husk rejects the commit because the file has a (known) error.

Steps to reproduce

  1. I try to make a commit with all changed files, except one.

lint-staged

  1. lint-staged runs "*.{js,jsx}": ["eslint . --fix", "git add"] and finds that DateList.js has an error (but I already know this and thats why I didnt added the file to the commit)

Theres a way to prevent this behaviour using lint-staged or may I need to manually stage the file and unstage after the commit is done?

Thanks.

Environment

  • OS: macOS Mojave 10.14.6
  • Node.js: v12.13.1
  • lint-staged: 9.5.0
  • git gui: SourceTree 3.2.1
@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

That’s a faulty behavior and should not happen. Can you please run lint-stages in debug mode and add the output to the issue (as the new issue template asks you to). Thanks.

@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

I think since your command contains eslint ., it will always check every file. This might not be related to lint-staged.

Try using simply eslint --fix.

@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

Ah yeah that’s a good catch. I missed that fact.

@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

@iiroj since it’s a most common mistake with the library I’m wondering there is a way to detect that and warn users about wrong configuration. Ideas?

@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

@okonet we already detect git add in the v10 beta. I’m wondering if a generic soluction for matching command strings would work, like a Map(testString-> warningMessage).

@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

it could I think if we’d manage the list of marchers and warnings. Not too much of the work I think.

@ivnnv
Copy link
Author

ivnnv commented Dec 16, 2019

@iiroj thanks for the suggestion, worked like a charm!

test

working

Maybe its worth mentioning this in the Readme? Honestly I just started using this tool today and the articles I read on implementing this (+ husky) suggest the ["eslint . --fix", "git add"] (with dot) rule to be added to the pre-commit.

And of course thanks @okonet for this package, I wish I applied on my repo before so I didn't woke up this morning with a broken app because last's night no-undef bug (😅)

Cheers!

@iiroj
Copy link
Member

iiroj commented Dec 16, 2019

We do have a lot of advanced function examples, so maybe we should add some basic examples as well. I'll create a separate issue.

@okonet
Copy link
Collaborator

okonet commented Dec 16, 2019

What article suggest this config? We should fix that.

@ivnnv
Copy link
Author

ivnnv commented Dec 17, 2019

What article suggest this config? We should fix that.

@okonet I meant random Medium/blog articles where people suggest how to use husky + lint-staged.
But then after reading the readme too, I didn't found any reference if whether or not I had to include the dot or not in the config line, hence my suggestion.

@okonet
Copy link
Collaborator

okonet commented Dec 17, 2019

Please feel free to improve the readme based on your experience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants