1 | # string-quotes
|
2 |
|
3 | Specify single or double quotes around strings.
|
4 |
|
5 | ```css
|
6 | a[id="foo"] { content: "x"; }
|
7 | /** ↑ ↑ ↑ ↑
|
8 | * These quotes and these quotes */
|
9 | ```
|
10 |
|
11 | Quotes within comments are ignored.
|
12 |
|
13 |
|
14 | ```css
|
15 | /* "This is fine" */
|
16 | /* 'And this is also fine' */
|
17 | ```
|
18 |
|
19 | Single quotes in a charset @-rule are ignored as using single quotes in this context is incorrect according the [CSS specification](https://www.w3.org/TR/CSS2/syndata.html#x57).
|
20 |
|
21 | ```css
|
22 | @charset "utf-8"
|
23 | /* fine regardless of configuration */
|
24 | ```
|
25 |
|
26 | The `--fix` option on the [command line](../../../docs/user-guide/cli.md#autofixing-errors) can automatically fix most of the problems reported by this rule.
|
27 |
|
28 | ## Options
|
29 |
|
30 | `string`: `"single"|"double"`
|
31 |
|
32 | ### `"single"`
|
33 |
|
34 | Strings *must always* be wrapped with single quotes.
|
35 |
|
36 | The following patterns are considered violations:
|
37 |
|
38 | ```css
|
39 | a { content: "x"; }
|
40 | ```
|
41 |
|
42 | ```css
|
43 | a[id="foo"] {}
|
44 | ```
|
45 |
|
46 | The following patterns are *not* considered violations:
|
47 |
|
48 | ```css
|
49 | a { content: 'x'; }
|
50 | ```
|
51 |
|
52 | ```css
|
53 | a[id='foo'] {}
|
54 | ```
|
55 |
|
56 | ```css
|
57 | a { content: "x'y'z"; }
|
58 | ```
|
59 |
|
60 | ### `"double"`
|
61 |
|
62 | Strings *must always* be wrapped with double quotes.
|
63 |
|
64 | The following patterns are considered violations:
|
65 |
|
66 | ```css
|
67 | a { content: 'x'; }
|
68 | ```
|
69 |
|
70 | ```css
|
71 | a[id='foo'] {}
|
72 | ```
|
73 |
|
74 | The following patterns are *not* considered violations:
|
75 |
|
76 | ```css
|
77 | a { content: "x"; }
|
78 | ```
|
79 |
|
80 | ```css
|
81 | a[id="foo"] {}
|
82 | ```
|
83 |
|
84 | ```css
|
85 | a { content: 'x"y"z'; }
|
86 | ```
|
87 |
|
88 | ## Optional secondary options
|
89 |
|
90 | ### `avoidEscape`: `true|false`, defaults to `true`
|
91 |
|
92 | Allows strings to use single-quotes or double-quotes so long as the string contains a quote that would have to be escaped otherwise.
|
93 |
|
94 | For example, with `"single", { "avoidEscape" : false }`.
|
95 |
|
96 | The following patterns are considered violations:
|
97 |
|
98 | ```css
|
99 | a { content: "x'y'z"; }
|
100 | ```
|
101 |
|
102 | ```css
|
103 | a[id="foo'bar'baz"] {}
|
104 | ```
|
105 |
|
106 | The following patterns are *not* considered violations:
|
107 |
|
108 | ```css
|
109 | a { content: 'x'; }
|
110 | ```
|
111 |
|
112 | ```css
|
113 | a[id='foo'] {}
|
114 | ```
|