Skip to content

Commit

Permalink
feat: add a skip-formatting ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang committed Feb 21, 2023
1 parent 1227b8f commit b5933a9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@ module.exports = {
}
```

This configuration is the most straightward way to use ESLint with Prettier.

It disables all rules that are unnecessary or might conflict with Prettier.
It also enables the `eslint-plugin-prettier` plugin, which runs Prettier as an ESLint rule and reports differences as individual ESLint issues.

By default all formatting issues are reported as warnings, and will be automatically fixed during `eslint --fix`.

## Use Separate Commands for Linting and Formatting

While the above setup is very straightforward, it is not necessarily the best way.

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.
[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.

So we offered an additional ruleset to support this workflow:

```js
require("@rushstack/eslint-patch/modern-module-resolution")

module.exports = {
extends: [
// ... other configs
"@vue/eslint-config-prettier/skip-formatting"
]
}
```

Formatting issues won't be reported with this config.

You can run `prettier --check .` separately to check for formatting issues, or `prettier --write .` to fix them.

## Further Reading

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.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "eslint-config-prettier for Vue",
"main": "index.js",
"files": [
"index.js"
"index.js",
"skip-formatting.js"
],
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -43,6 +44,6 @@
]
},
"scripts": {
"lint": "eslint index.js --fix"
"lint": "eslint *.js --fix"
}
}
6 changes: 6 additions & 0 deletions skip-formatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: [require.resolve("./index.js")],
rules: {
"prettier/prettier": "off",
},
};

0 comments on commit b5933a9

Please sign in to comment.