UNPKG

2.69 kBMarkdownView Raw
1# Ignoring code
2
3You can ignore:
4
5- within files
6- files entirely
7
8## Within files
9
10You can temporarily turn off rules using special comments in your CSS. For example, you can either turn all the rules off:
11
12<!-- prettier-ignore -->
13```css
14/* stylelint-disable */
15a {}
16/* stylelint-enable */
17```
18
19Or you can turn off individual rules:
20
21<!-- prettier-ignore -->
22```css
23/* stylelint-disable selector-no-id, declaration-no-important */
24#id {
25 color: pink !important;
26}
27/* stylelint-enable selector-no-id, declaration-no-important */
28```
29
30You can turn off rules for individual lines with a `/* stylelint-disable-line */` comment, after which you do not need to explicitly re-enable them:
31
32<!-- prettier-ignore -->
33```css
34#id { /* stylelint-disable-line */
35 color: pink !important; /* stylelint-disable-line declaration-no-important */
36}
37```
38
39You can also turn off rules for _the next line only_ with a `/* stylelint-disable-next-line */` comment, after which you do not need to explicitly re-enable them:
40
41<!-- prettier-ignore -->
42```css
43#id {
44 /* stylelint-disable-next-line declaration-no-important */
45 color: pink !important;
46}
47```
48
49Stylelint supports complex, overlapping disabling & enabling patterns:
50
51<!-- prettier-ignore -->
52```css
53/* stylelint-disable */
54/* stylelint-enable foo */
55/* stylelint-disable foo */
56/* stylelint-enable */
57/* stylelint-disable foo, bar */
58/* stylelint-disable baz */
59/* stylelint-enable baz, bar */
60/* stylelint-enable foo */
61```
62
63**Caveat:** Comments within _selector and value lists_ are currently ignored.
64
65You may also include a description at the end of the comment, after two hyphens:
66
67```css
68/* stylelint-disable -- Reason for disabling Stylelint. */
69/* stylelint-disable foo -- Reason for disabling the foo rule. */
70/* stylelint-disable foo, bar -- Reason for disabling the foo and bar rules. */
71```
72
73**Important:** There must be a space on both sides of the hyphens.
74
75## Files entirely
76
77You can use a `.stylelintignore` file to ignore specific files. For example:
78
79```
80vendor/**/*.css
81```
82
83The patterns in your `.stylelintignore` file must match [`.gitignore` syntax](https://git-scm.com/docs/gitignore). (Behind the scenes, [`node-ignore`](https://github.com/kaelzhang/node-ignore) parses your patterns.) _Your patterns in `.stylelintignore` are always analyzed relative to `process.cwd()`._
84
85Stylelint looks for a `.stylelintignore` file in `process.cwd()`. You can also specify a path to your ignore patterns file (absolute or relative to `process.cwd()`) using the `--ignore-path` (in the CLI) and `ignorePath` (in JS) options.
86
87Alternatively, you can add an [`ignoreFiles` property](configure.md#ignorefiles) within your configuration object.