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

Chore: Add linting to git commit #11556

Merged
merged 6 commits into from Apr 24, 2019

Conversation

Projects
None yet
6 participants
@nzakas
Copy link
Member

commented Mar 26, 2019

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:

Infrastructure - add git commit hook

What changes did you make? (Give an overview)

Added an installable pre-commit hook that automatically runs ESLint when .js files are staged during git commit. (This will work for anyone who pulls the source from Git without any additional configuration or steps.)

The hook automatically runs ESLint with --fix and then re-adds the fixed JS files (if any) to the commit. If there is a lint error that can't be autofixed, then the commit operation fails:

$ git commit -m "Chore: Add linting to git commit"
 > running pre-commit hook: lint-staged
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running linters... [started]
Running tasks for *.js [started]
eslint --fix [started]
eslint --fix [failed]
→
Running tasks for *.js [failed]
→
Running linters... [failed]



× eslint --fix found some errors. Please fix them and try committing again.

C:\Users\Nicholas\Documents\projects\eslint\bin\eslint.js:16
onst useStdIn = (process.argv.indexOf("--stdin") > -1),
   ^^^^^^^^

SyntaxError: Unexpected identifier
  at new Script (vm.js:79:7)
  at createScript (vm.js:251:10)
  at Object.runInThisContext (vm.js:303:10)
  at Module._compile (internal/modules/cjs/loader.js:656:28)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
  at Module.load (internal/modules/cjs/loader.js:598:32)
  at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
  at Function.Module._load (internal/modules/cjs/loader.js:529:3)
  at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
  at startup (internal/bootstrap/node.js:285:19)

pre-commit hook failed (add --no-verify to bypass)

Is there anything you'd like reviewers to focus on?

Is this useful to you? I find it useful because I have a bad habit of forgetting to run ESLint before updating my commit.

@platinumazure
Copy link
Member

left a comment

LGTM, thanks!

@not-an-aardvark

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

Is this opt-in, or does it automatically get installed as a git hook? Personally, I often create WIP local commits before fixing lint errors, so I probably wouldn't want to have this running locally, but I'm fine with it if it doesn't get installed automatically and/or if there's a way to disable it.

Show resolved Hide resolved package.json
@aladdin-add

This comment has been minimized.

Copy link
Member

commented Mar 27, 2019

To skip the linting, a contributor can use git commit -n. worth mentioned in contributing guide?

@mysticatea
Copy link
Member

left a comment

It's fine for me, but I have a question.

Show resolved Hide resolved package.json Outdated
Show resolved Hide resolved package.json Outdated

@nzakas nzakas added do not merge and removed do not merge labels Mar 27, 2019

@nzakas

This comment has been minimized.

Copy link
Member Author

commented Mar 27, 2019

@not-an-aardvark It gets installed automatically, but you can skip it using --no-verify.

@aladdin-add It's probably a good idea to mention that there is some verification going on, though I wouldn't want to tell people how to bypass it because 1) most of the time, you shouldn't bypass it and 2) the console tells you how to bypass the check if there's an error.

@nzakas nzakas added the do not merge label Mar 27, 2019

@nzakas nzakas removed the do not merge label Mar 28, 2019

@nzakas

This comment has been minimized.

Copy link
Member Author

commented Mar 28, 2019

I've updated this PR to:

  • Use the local ESLint instead of a separate package
  • Also lint Markdown files using markdownlint (I had to do a bit of refactoring in Makefile.js for that)
@platinumazure
Copy link
Member

left a comment

LGTM, thanks! Just left one question to make sure I understood the lint-staged configuration.

"node ./bin/eslint.js --fix",
"git add"
],
"*.md": "markdownlint"

This comment has been minimized.

Copy link
@platinumazure

platinumazure Mar 28, 2019

Member

Just to make sure I understand: We need git add in the *.js section because eslint --fix might make changes, so we need to stage those; but we don't need it here, because markdownlint doesn't autofix, but rather only reports errors.

Have I got that right?

@aladdin-add

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

What do you think of merging it? @platinumazure

@platinumazure

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

Yes, we can merge. My question was just for curiosity. Sorry for holding this up.

aladdin-add added some commits Apr 24, 2019

@aladdin-add aladdin-add merged commit 8b4dba6 into master Apr 24, 2019

4 checks passed

commit-message PR title follows commit message guidelines
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details
release-monitor No patch release is pending
Details

@aladdin-add aladdin-add deleted the githooks branch Apr 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.