Skip to content

Commit b5933a9

Browse files
committed
feat: add a skip-formatting ruleset
1 parent 1227b8f commit b5933a9

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,37 @@ module.exports = {
3434
}
3535
```
3636

37+
This configuration is the most straightward way to use ESLint with Prettier.
38+
39+
It disables all rules that are unnecessary or might conflict with Prettier.
40+
It also enables the `eslint-plugin-prettier` plugin, which runs Prettier as an ESLint rule and reports differences as individual ESLint issues.
41+
42+
By default all formatting issues are reported as warnings, and will be automatically fixed during `eslint --fix`.
43+
44+
## Use Separate Commands for Linting and Formatting
45+
46+
While the above setup is very straightforward, it is not necessarily the best way.
47+
48+
Running prettier inside the linter slows down the linting process, might clutter the editor with annoying warnings, and adds one layer of indirection where things may break.
49+
[Prettier's official documentation](https://prettier.io/docs/en/integrating-with-linters.html) recommends using separate commands for linting and formatting, i.e., Prettier for code formatting concerns and ESLint for code-quality concerns.
50+
51+
So we offered an additional ruleset to support this workflow:
52+
53+
```js
54+
require("@rushstack/eslint-patch/modern-module-resolution")
55+
56+
module.exports = {
57+
extends: [
58+
// ... other configs
59+
"@vue/eslint-config-prettier/skip-formatting"
60+
]
61+
}
62+
```
63+
64+
Formatting issues won't be reported with this config.
65+
66+
You can run `prettier --check .` separately to check for formatting issues, or `prettier --write .` to fix them.
67+
3768
## Further Reading
3869

3970
The default config is based on the recommended configuration of [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier/#recommended-configuration), which also depends on [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier). Please refer to their corresponding documentations for more implementation details.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "eslint-config-prettier for Vue",
55
"main": "index.js",
66
"files": [
7-
"index.js"
7+
"index.js",
8+
"skip-formatting.js"
89
],
910
"publishConfig": {
1011
"access": "public"
@@ -43,6 +44,6 @@
4344
]
4445
},
4546
"scripts": {
46-
"lint": "eslint index.js --fix"
47+
"lint": "eslint *.js --fix"
4748
}
4849
}

skip-formatting.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: [require.resolve("./index.js")],
3+
rules: {
4+
"prettier/prettier": "off",
5+
},
6+
};

0 commit comments

Comments
 (0)