Files
test-repo/docs/integrating-with-linters.md
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
2.2 KiB
Markdown
Raw Normal View History

2019-04-07 23:32:24 -07:00
---
id: integrating-with-linters
title: Integrating with Linters
---
Linters usually contain not only code quality rules, but also stylistic rules. Most stylistic rules are unnecessary when using Prettier, but worse – they might conflict with Prettier! Use Prettier for code formatting concerns, and linters for code-quality concerns, as outlined in [Prettier vs. Linters](comparison.md).
2019-04-07 23:32:24 -07:00
Luckily it’s easy to turn off rules that conflict or are unnecessary with Prettier, by using these pre-made configs:
2019-04-07 23:32:24 -07:00
- [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier)
2019-04-07 23:32:24 -07:00
Check out the above links for instructions on how to install and set things up.
2019-04-07 23:32:24 -07:00
## Notes
2019-04-07 23:32:24 -07:00
When searching for both Prettier and your linter on the Internet you’ll probably find more related projects. These are **generally not recommended,** but can be useful in certain circumstances.
2019-04-07 23:32:24 -07:00
First, we have plugins that let you run Prettier as if it was a linter rule:
2019-04-07 23:32:24 -07:00
- [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier)
- [stylelint-prettier](https://github.com/prettier/stylelint-prettier)
2019-04-07 23:32:24 -07:00
These plugins were especially useful when Prettier was new. By running Prettier inside your linters, you didn’t have to set up any new infrastructure and you could re-use your editor integrations for the linters. But these days you can run `prettier --check .` and most editors have Prettier support.
2019-04-07 23:32:24 -07:00
The downsides of those plugins are:
2019-04-07 23:32:24 -07:00
- You end up with a lot of red squiggly lines in your editor, which gets annoying. Prettier is supposed to make you forget about formatting – and not be in your face about it!
- They are slower than running Prettier directly.
- They’re yet one layer of indirection where things may break.
2019-04-07 23:32:24 -07:00
2022-08-29 15:21:18 +02:00
Finally, we have tools that run `prettier` and then immediately lint files by running, for example, `eslint --fix` on them.
2019-04-07 23:32:24 -07:00
- [prettier-eslint](https://github.com/prettier/prettier-eslint)
- [prettier-stylelint](https://github.com/hugomrdias/prettier-stylelint)
2019-04-07 23:32:24 -07:00
Those are useful if some aspect of Prettier’s output makes Prettier completely unusable to you. Then you can have for example `eslint --fix` fix that up for you. The downside is that these tools are much slower than just running Prettier.