Skip to content

samit4me/precommit-eslint-fix-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Small repo to demo an issue I am having with a git pre-commit hook that automatically fixes linting issues via eslint --fix. The pre-commit hook works fine if I stage the changes (e.g. git add filename) before commiting, but fails when committing a file directly (e.g. git commit -m "Test" filename). I don't normally do this, but it seems to be the default behaviour of IntelliJ.

To reproduce the issue:

  1. Copy the pre-commit file into your git hooks directory cp pre-commit .git/hooks/.
  2. Remove the semicolon from the last line of index.js and save.
  3. Run git commit -m "Test" index.js.
  4. The file is fixed (semicolon added) and committed.
  5. If I run git status the same file is both staged and not staged.
  6. If I run git diff the staged file is GOOD (has semicolon) and the not staged file is BAD (NO semicolon).

The only way I've been able to resolve this issue is by using a post-commit hook to git reset the files that were committed. I'm definitely NOT a Git Guru, so if anyone has experience with this or can help in any way it will be greatly appreciated.

To use the post-commit method:

  1. Copy the post-commit file into your git hooks directory cp post-commit .git/hooks/.
  2. Follow steps 2. and 3. from above.
  3. Now everything should be as expected.

CREDIT: the pre-commit file was based on a pre-commit gist by @broofa.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published