govuk-frontend icon indicating copy to clipboard operation
govuk-frontend copied to clipboard

For discussion: Add Git hook to lint `.(m)js` and `.scss` file `pre-commit`

Open romaricpascal opened this issue 1 year ago • 0 comments

Not a PR to merge, but more to initiate a discussion around running linting before commit to prevent discovering linting issues only on CI.

It relies on two tools:

  • lint-staged which handles detecting which files are being commited and running the linting on them. It stashes/unstashes any changes that are not staged so the linting runs on the files in the state they are actually commited, in case you're using git add -p. Thought there'd be some caution to have around the package and dist folder to avoid messing with compiled files, but standard is already configured to avoid those
  • husky which handles the creation and installation of Git hooks, mostly pointing Git to the relevant scripts in .husky (configurable) through its core.hooksPath config.

Happy to park it for now if it's not something we'd want to dip our toes into, but thought it'd be best discussed alongside how it could look as these two tools make managing the situation a bit less scary than it sounds.

romaricpascal avatar Sep 14 '22 17:09 romaricpascal