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

Add husky to run markdownlint #745

Merged
merged 1 commit into from
Oct 16, 2019
Merged

Conversation

adam-resdiary
Copy link
Contributor

I've added husky to run the markdownlint check as a pre-commit hook.

I've also added lint-staged, which does a couple of things for us:

  • It will only run linters if any files have been changed matching certain patterns. For example, it'll only run the markdownlint check if any *.md files have been changed.
  • It makes sure that your staged changes are valid so you don't fix a problem then forget to stage it before committing.

Fixes #741

Here's what it looks like if you try to commit a file with a failing markdown check:

$ git commit -m"Test commit"
husky > pre-commit (node v11.6.0)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running tasks... [started]
Running tasks for *.md [started]
npm run --silent markdownlint [started]
npm run --silent markdownlint [failed]
→
Running tasks for *.md [failed]
→
Running tasks... [failed]



× npm run --silent markdownlint found some errors. Please fix them and try committing again.

C:/Users/AdamConnelly/github.com/adamrpconnelly/promitor/CODE_OF_CONDUCT.md: 49: MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
CODE_OF_CONDUCT.md: 49: MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
husky > pre-commit hook failed (add --no-verify to bypass)

Here's what it looks like if there's no problems:

$ git commit -m"Test commit"
husky > pre-commit (node v11.6.0)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running tasks... [started]
Running tasks for *.md [started]
npm run --silent markdownlint [started]
npm run --silent markdownlint [completed]
Running tasks for *.md [completed]
Running tasks... [completed]
[husky 67c77e4] Test commit
 3 files changed, 1431 insertions(+)

Here's what it looks like if no files that need linting have been changed:

$ git commit -m"Test commit"
husky > pre-commit (node v11.6.0)
No staged files match any of provided globs.
[husky 610cc1f] Add husky to run markdownlint
 Date: Wed Oct 16 17:20:36 2019 +0100
 2 files changed, 1429 insertions(+)

@tomkerkhove if you want to try this out, just pull this branch, run npm install, make a change to a markdown file that causes an error and make a commit.

I've added [husky](https://github.com/typicode/husky) to run the markdownlint check as a pre-commit hook.

I've also added [lint-staged](https://github.com/okonet/lint-staged), which does a couple of things for us:

- It will only run linters if any files have been changed matching certain patterns. For example, it'll only run the markdownlint check if any `*.md` files have been changed.
- It makes sure that your staged changes are valid so you don't fix a problem then forget to stage it before committing.

Fixes tomkerkhove#741
@tomkerkhove
Copy link
Owner

Awesome, thanks!

@tomkerkhove tomkerkhove merged commit b4ed187 into tomkerkhove:master Oct 16, 2019
@adamconnelly adamconnelly deleted the husky branch February 3, 2020 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Husky to share git hooks
3 participants