Skip to content

Commit cf30e5f

Browse files
Add automated linting setup using Husky and lint-staged to guide
1 parent 39614ab commit cf30e5f

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

guides/eslint.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,34 @@ Add the following scripts to your `package.json` file:
8282
}
8383
```
8484

85-
### 4 - Add ESLint to your development workflow
85+
### 4 - Add ESLint to your development workflow (optional)
8686

87-
You can now run ESLint manually by executing the following command in your terminal:
87+
#### A - Run it automatically before committing (recommended)
88+
89+
If you want to run ESLint automatically before committing any changes, you can use a tool like [Husky](https://typicode.github.io/husky/) to set up a pre-commit hook and [lint-staged](https://www.npmjs.com/package/lint-staged) to only lint staged files. This will help ensure that your code is always linted before it is committed.
90+
91+
To set this up, first install `Husky` and `lint-staged` as development dependencies:
92+
93+
```bash
94+
npm install --save-dev husky lint-staged
95+
```
96+
97+
Then, add the following configuration to your `package.json` file:
98+
99+
```json
100+
"husky": {
101+
"hooks": {
102+
"pre-commit": "lint-staged"
103+
}
104+
},
105+
"lint-staged": {
106+
"*.{js,mjs}": "eslint --fix"
107+
}
108+
```
109+
110+
#### B - Run it manually before committing (optional)
111+
112+
You can run ESLint manually by executing the following command in your terminal:
88113

89114
```bash
90115
npm run lint

0 commit comments

Comments
 (0)