Skip to content

Commit

Permalink
fix doc for formatting (#214)
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <[email protected]>
  • Loading branch information
strawberry-choco authored Jan 8, 2024
1 parent 2e05569 commit e41827f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/eslint-plugin-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ module.exports = {
```

With the command `eslint . --config .eslintrc.format.js` your project can be checked for formatting violations.

### Pre-Commit Hook

The reason we created another eslint config file just for formatting instead of adding it to the existing one is to separate between linting and formatting, which are two different concerns. Furthermore, with the separation we also gain the ability to fix the formatting automatically before commit. Automatically fixing linting bugs with `eslint --fix` is not recommended, since it changes the intent of the code.

To automatically format your code before committing, set up [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) with the following content in your `package.json`.

```json
{
// ...
"lint-staged": {
"*.html": "eslint --config .eslintrc.format.cjs --fix",
"*.ts": "eslint --config .eslintrc.format.cjs --fix"
}
}
```
2 changes: 1 addition & 1 deletion packages/eslint-plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ To automatically format your code before committing, set up [husky](https://typi
{
// ...
"lint-staged": {
"**/*": "eslint --config .eslintrc.format.js --fix"
"*.ts": "eslint --config .eslintrc.format.cjs --fix"
}
}
```

0 comments on commit e41827f

Please sign in to comment.