1 | # Linting
|
2 |
|
3 | A linter is a tool that analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.
|
4 |
|
5 | You can use a linter with a pretty printer and a validator. There are, however, usually overlaps between these three types of tools.
|
6 |
|
7 | ## Pretty printers
|
8 |
|
9 | There are two approaches to enforcing stylistic conventions:
|
10 |
|
11 | - a machine algorithmically pretty prints the code (usually based on a maximum line length)
|
12 | - a human initially formats the code, and a machine fixes-up/warns-about any mistakes
|
13 |
|
14 | The former is handled by pretty printers, like [prettier](https://github.com/prettier/prettier), whereas the latter is catered for by the built-in [stylistic rules](../user-guide/rules/list.md#stylistic-issues). If you use a pretty printer, you'll want to use [`stylelint-config-recommended`](https://github.com/stylelint/stylelint-config-recommended), which only turns on [possible error](../user-guide/rules/list.md#possible-errors) rules.
|
15 |
|
16 | Additionally, the built-in stylistic rules and plugins are configurable to support a diverse range of stylistic conventions. For example, ordering properties within declaration blocks is a divisive topic, where there isn't a dominant convention. The [`stylelint-order`](https://www.npmjs.com/package/stylelint-order) plugin can be configured to lint and fix a diverse range of ordering conventions.
|
17 |
|
18 | Another example is the use of single-line rules for sets of _related_ rules, e.g.
|
19 |
|
20 |
|
21 | ```css
|
22 | /* Single-line related classes */
|
23 | .class-1 { top: 0; bottom: 0; }
|
24 | .class-2 { top: 5px; right: 0; }
|
25 | .class-3 { top: 8px; left: 0; }
|
26 | ```
|
27 |
|
28 | You can configure the built-in stylistic rules to allow both multi-line and single-line rules. The choice of when to use each belongs to the user.
|
29 |
|
30 | ## Validators
|
31 |
|
32 | Validators like [csstree](https://github.com/csstree/csstree) identify invalid code such as misformed hex colors and unknown language features.
|
33 |
|
34 | However, as a stop-gap, while these tools mature stylelint provides rules for the simplest of cases.
|