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

build tools: add an eslint --fix Git precommit hook #4985

Merged
merged 1 commit into from
Feb 16, 2018

Conversation

ntwb
Copy link
Member

@ntwb ntwb commented Feb 10, 2018

Description

This pull requests seeks to add a Git "precommit hook" so that the ESLint command eslint --fix is run against any JavaScript files staged for commit during git commit

How Has This Been Tested?

  1. To test this PR, remove a semi-colon from a file, e.g /date.index.js and save the file
  2. Stage the file change for commit git add date/index.js
  3. Commit the change `git commit -m "Test ESLint Fix Precommit Hook"
  4. Confirm that the semi-colon removed from date/index.js has been restored

The above can be seen in this shell screencast: https://asciinema.org/a/UXeTZyHbF3IbW6IhNU0cvrVcj

Screenshots (jpeg or gifs if applicable):

Types of changes

Build tooling change

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

p.s. The package-lock.json has also been regenareated from scratch, becasue, npm /shrug

@ntwb ntwb added the [Type] Build Tooling Issues or PRs related to build tooling label Feb 10, 2018
@ntwb ntwb requested a review from aduth February 10, 2018 01:08
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable addition to the workflow 👍

@ntwb ntwb merged commit 41cde56 into master Feb 16, 2018
@ntwb ntwb deleted the add/precommit-lint-hook branch February 16, 2018 06:36
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found that this conflicts with patch/partial commits, at least those made via the GitHub Desktop client, presumably because git add will add all changes from the tested files, even though I'd already made only a partial selection to commit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aduth Hmmm, I think it relates to this lint-staged issue:
lint-staged/lint-staged#62
There's an active WIP PR, but it's doesn't look like landing in the short term
lint-staged/lint-staged#75

Maybe we should drop this and revert until a solution for the above lands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants