Skip to content

Commit

Permalink
build: Enable lint-staged
Browse files Browse the repository at this point in the history
This commit introduces `lint-staged` to automate code formatting before
committing changes.

Previously, the `.husky/pre-commit` hook relied on
`npm run prettier:check`, which only performed a check for code style
violations but did not automatically fix them.  This meant that
developers had to manually run `prettier` to format their code before
committing.

Most notably, using Husky to achieve this automatically formats only the
files that are to be committed, saving developers bot time and sanity.

The changes implement the following:

- **Update `.husky/pre-commit`:** The hook is now configured to run
`npm run pre-commit` which executes `lint-staged`  to automatically
format code changes.
- **Add `pre-commit` script to `package.json`:**  This script runs
`lint-staged` with the `--concurrent false` flag, ensuring that
formatting happens sequentially for improved compatibility with eslint
and reliability.
- **Modify `lint-staged` configuration in `package.json`:**  The
configuration now targets specific file types
(`*.{css,html,js,json,md,twig,yml}`) for formatting. This clarifies the
scope of automatic formatting.

This change simplifies the development workflow by automating the code
formatting process, ensuring all commits adhere to the project's style
guidelines without manual intervention. This improves code consistency
and reduces the possibility of style-related issues in the codebase.
  • Loading branch information
MikeRatcliffe committed Sep 30, 2024
1 parent 780d7ce commit 70866f7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run prettier:check
npm run pre-commit
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dist-win": "electron-builder -w",
"dist-mac": "electron-builder -m",
"dist-linux": "electron-builder -l",
"pre-commit": "lint-staged --concurrent false",
"prettier:check": "prettier --check \"**/*.{css,js,json,md,twig,yml}\"",
"prettier:format": "prettier --write \"**/*.{css,js,json,md,twig,yml}\"",
"postdist": "npm run pack-win && npm run pack-mac",
Expand All @@ -44,7 +45,7 @@
"prepare": "husky"
},
"lint-staged": {
"{**/*,*}.{css,js,json,md,twig,yml}": "prettier --write"
"*.{css,html,js,json,md,twig,yml}": "prettier --write"
},
"build": {
"appId": "com.sidenoder.app",
Expand Down

0 comments on commit 70866f7

Please sign in to comment.