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
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,9 +82,46 @@ 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
+
"lint-staged": {
101
+
"*.{js,mjs}": "eslint --fix"
102
+
}
103
+
```
104
+
105
+
And also in the `package.json` file, add the following lines to the `scripts` section:
106
+
107
+
```json
108
+
"scripts": {
109
+
"prepare": "husky",
110
+
}
111
+
```
112
+
113
+
Create a pre-commit hook by running the following commandin your terminal:
114
+
115
+
```bash
116
+
npx husky init
117
+
echo"npx lint-staged"> .husky/pre-commit
118
+
```
119
+
120
+
This will set up `Husky` to run the `lint-staged`command before committing any changes. The `lint-staged`command will only lint the files that are staged for commit, which can save time and resources.
121
+
122
+
#### B - Run it manually before committing (optional)
123
+
124
+
You can run ESLint manually by executing the following commandin your terminal:
0 commit comments