You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/eslint.md
+27-2Lines changed: 27 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,9 +82,34 @@ Add the following scripts to your `package.json` file:
82
82
}
83
83
```
84
84
85
-
### 4 - Add ESLint to your development workflow
85
+
### 4 - Add ESLint to your development workflow (optional)
86
86
87
-
You can now run ESLint manually by executing the following commandin 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 commandin your terminal:
0 commit comments