.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / docs / user-guide / cli.md
1 # The stylelint CLI
2
3 ## Installation
4
5 stylelint is an [npm package](https://www.npmjs.com/package/stylelint). Install it using:
6
7 ```shell
8 npm install -g stylelint
9 ```
10
11 ## Usage
12
13 `stylelint --help` prints the CLI documentation.
14
15 The CLI outputs formatted results into `process.stdout`, which you can read with your human eyes or pipe elsewhere (e.g. write the information to a file).
16
17 ### Examples
18
19 When you run commands similar to the examples below, be sure to include the quotation marks around file globs. This ensures that you can use the powers of node-glob (like the `**` globstar) regardless of your shell.
20
21 Looking for `.stylelintrc` and linting all `.css` files in the `foo` directory:
22
23 ```shell
24 stylelint "foo/*.css"
25 ```
26
27 Looking for `.stylelintrc` and linting all `<style>` blocks within the `.html` files in the `bar` directory:
28
29 ```shell
30 stylelint "bar/*.html"
31 ```
32
33 Looking for `.stylelintrc` and linting `stdin`:
34
35 ```shell
36 echo "a { color: pink; }" | stylelint
37 ```
38
39 Using `bar/mySpecialConfig.json` as config to lint all `.css` files in the `foo` directory, then writing the output to `myTestReport.txt`:
40
41 ```shell
42 stylelint "foo/*.css" --config bar/mySpecialConfig.json > myTestReport.txt
43 ```
44
45 Using `bar/mySpecialConfig.json` as config, with quiet mode on, to lint all `.css` files in the `foo` directory and any of its subdirectories and also all `.css` files in the `bar directory`, then writing the JSON-formatted output to `myJsonReport.json`:
46
47 ```shell
48 stylelint "foo/**/*.css bar/*.css" -q -f json --config bar/mySpecialConfig.json > myJsonReport.json
49 ```
50
51 Linting all `.css` files except those within `docker` subfolders, using negation in the input glob:
52
53 ```shell
54 stylelint "**/*.css, !**/docker/**"
55 ```
56
57 Caching processed `.scss` files in order to operate only on changed ones in the `foo` directory, using the `cache` and `cache-location` options:
58
59 ```shell
60 stylelint "foo/**/*.scss" --cache --cache-location "/Users/user/.stylelintcache/"
61 ```
62
63 Linting all the `.css` files in the `foo` directory, using the `syntax` option:
64
65 ```shell
66 stylelint "foo/**/*.css" --syntax scss
67 ```
68
69 In addition to `--syntax scss`, stylelint supports `--syntax less` and `--syntax sugarss` by default. If you're using one of the default syntaxes, you may not need to provide a `--syntax` option as non-standard syntaxes can be automatically inferred from the following:
70
71 -   The following file extensions: `.less`, `.scss`, and `.sss`.
72 -   The following values for the `lang` or `type` attribute on `<style>` tags (e.g. `lang="scss"`, `type="text/scss"`): `scss`, `less` and `sugarss`.
73 -   The following Markdown code fencing markers (e.g. ```` ```scss ````): `scss`, `less` and `sugarss`.
74
75 Additionally, stylelint can accept a custom [PostCSS-compatible syntax](https://github.com/postcss/postcss#syntaxes). To use a custom syntax, supply a syntax module name or path to the syntax file: `--custom-syntax custom-syntax` or `--custom-syntax ./path/to/custom-syntax`.
76
77 Note, however, that stylelint can provide no guarantee that core rules will work with syntaxes other than the defaults listed above.
78
79 ### Recursively linting a directory
80
81 To recursively lint a directory, using the `**` globstar:
82
83 ```shell
84 stylelint "foo/**/*.scss"
85 ```
86
87 The quotation marks around the glob are important because they will allow stylelint to interpret the glob, using node-glob, instead of your shell, which might not support all the same features.
88
89 ### Autofixing errors
90
91 With `--fix` option stylelint will fix as many errors as possible. The fixes are made to the actual source files. All unfixed errors will be reported.
92
93 Linting all `.css` files in the `foo` directory. And fixing source files if violated rules support autofixing:
94
95 ```shell
96 stylelint "foo/*.css" --fix
97 ```
98
99 **Note:** It's an _experimental_ feature. It currently does not respect special comments for disabling stylelint within sources (e. g. `/* stylelint-disable */`). Autofixing will be applied regardless of these comments.
100
101 If you're using both these special comments and autofixing, please run stylelint twice as a temporary solution. On the first run, some violations could be missed, or some violations might be reported incorrectly.
102
103 For CSS with standard syntax, stylelint will use [postcss-safe-parser](https://github.com/postcss/postcss-safe-parser) to fix syntax errors.
104
105 ## Syntax errors
106
107 The CLI informs you about syntax errors in your CSS.
108 It uses the same format as it uses for linting violations.
109 The error name is `CssSyntaxError`.
110
111 ## Exit codes
112
113 The CLI can exit the process with the following exit codes:
114
115 -   1: Something unknown went wrong.
116 -   2: At least one rule with an "error"-level severity triggered at least one violations.
117 -   78: There was some problem with the configuration file.
118 -   80: A file glob was passed, but it found no files.