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 for pre-commit formatting hooks #17625

Merged
merged 6 commits into from
Sep 14, 2022
Merged

Conversation

queengooborg
Copy link
Collaborator

This PR adds husky as a dependency for pre-commit hooks to format all of the files before creating a commit.

@github-actions github-actions bot added dependencies ⛓️ Pull requests that update a dependency package or file. infra 🏗️ Infrastructure issues (npm, GitHub Actions, releases) of this project labels Aug 31, 2022
@nschonni
Copy link
Contributor

Might be worth looking at combining this with https://www.npmjs.com/package/lint-staged so that descrete actions can be hooked depending on the file type. EX: https://github.com/w3c/aria-practices/blob/6aaf4d48fc690a9d5ddbfbec32cfc7f15a16dd40/package.json#L63-L74

@queengooborg
Copy link
Collaborator Author

queengooborg commented Sep 1, 2022

That's the eventual plan!

Edit: actually, we might as well add lint-staged now 'cause why not? 😛

Copy link
Contributor

@nschonni nschonni left a comment

Choose a reason for hiding this comment

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

You can also do some cool triggers on individual files if you need to run regeneration when a schema changes

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

node node_modules/.bin/lint-staged
Copy link
Contributor

Choose a reason for hiding this comment

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

Think this is a little friendly for cross platform. I think only Windows does the .bin or maybe I have that reversed

Suggested change
node node_modules/.bin/lint-staged
npx lint-staged

.lintstagedrc Outdated Show resolved Hide resolved
Copy link
Member

@Elchi3 Elchi3 left a comment

Choose a reason for hiding this comment

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

Let's ask in the next owner's meeting about pre-commit hooks. I'm not against it per se, just want to make sure the majority appreciates these ergonomics. Also, might be nice to mention this in the contribution docs if we introduce them.

@queengooborg
Copy link
Collaborator Author

MDN content just landed this, so let's land this here as well!

@queengooborg queengooborg merged commit 9d42eba into mdn:main Sep 14, 2022
@queengooborg queengooborg deleted the husky branch September 14, 2022 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies ⛓️ Pull requests that update a dependency package or file. infra 🏗️ Infrastructure issues (npm, GitHub Actions, releases) of this project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants