1 | # color-named
|
2 |
|
3 | Require (where possible) or disallow named colors.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { color: black }
|
8 | /** ↑
|
9 | * This named color */
|
10 | ```
|
11 |
|
12 | This rule ignores `$sass` and `@less` variable syntaxes.
|
13 |
|
14 | ## Options
|
15 |
|
16 | `string`: `"always-where-possible"|"never"`
|
17 |
|
18 | ### `"always-where-possible"`
|
19 |
|
20 | Colors _must always_, where possible, be named.
|
21 |
|
22 | This will complain if a hex (3, 4, 6 and 8 digit), `rgb()`, `rgba()`, `hsl()`, `hsla()`, `hwb()` or `gray()` color can be represented as a named color.
|
23 |
|
24 | The following patterns are considered violations:
|
25 |
|
26 |
|
27 | ```css
|
28 | a { color: #000; }
|
29 | ```
|
30 |
|
31 |
|
32 | ```css
|
33 | a { color: #f000; }
|
34 | ```
|
35 |
|
36 |
|
37 | ```css
|
38 | a { color: #ff000000; }
|
39 | ```
|
40 |
|
41 |
|
42 | ```css
|
43 | a { color: rgb(0, 0, 0); }
|
44 | ```
|
45 |
|
46 |
|
47 | ```css
|
48 | a { color: rgb(0%, 0%, 0%); }
|
49 | ```
|
50 |
|
51 |
|
52 | ```css
|
53 | a { color: rgba(0, 0, 0, 0); }
|
54 | ```
|
55 |
|
56 |
|
57 | ```css
|
58 | a { color: hsl(0, 0%, 0%); }
|
59 | ```
|
60 |
|
61 |
|
62 | ```css
|
63 | a { color: hwb(0, 0%, 100%); }
|
64 | ```
|
65 |
|
66 |
|
67 | ```css
|
68 | a { color: gray(0); }
|
69 | ```
|
70 |
|
71 | The following patterns are _not_ considered violations:
|
72 |
|
73 |
|
74 | ```css
|
75 | a { color: black; }
|
76 | ```
|
77 |
|
78 |
|
79 | ```css
|
80 | a { color: rgb(10, 0, 0); }
|
81 | ```
|
82 |
|
83 |
|
84 | ```css
|
85 | a { color: rgb(0, 0, 0, 0.5); }
|
86 | ```
|
87 |
|
88 | ### `"never"`
|
89 |
|
90 | Colors _must never_ be named.
|
91 |
|
92 | The following patterns are considered violations:
|
93 |
|
94 |
|
95 | ```css
|
96 | a { color: black; }
|
97 | ```
|
98 |
|
99 |
|
100 | ```css
|
101 | a { color: white; }
|
102 | ```
|
103 |
|
104 | The following patterns are _not_ considered violations:
|
105 |
|
106 |
|
107 | ```css
|
108 | a { color: #000; }
|
109 | ```
|
110 |
|
111 |
|
112 | ```css
|
113 | a { color: rgb(0, 0, 0); }
|
114 | ```
|
115 |
|
116 |
|
117 | ```css
|
118 | a { color: var(--white); }
|
119 | ```
|
120 |
|
121 | ## Optional secondary options
|
122 |
|
123 | ### `ignore: ["inside-function"]`
|
124 |
|
125 | Ignore colors that are inside a function.
|
126 |
|
127 | For example, with `"never"`.
|
128 |
|
129 | The following patterns are _not_ considered violations:
|
130 |
|
131 |
|
132 | ```css
|
133 | a {
|
134 | color: map-get($colour, blue);
|
135 | }
|
136 | ```
|
137 |
|
138 |
|
139 | ```css
|
140 | a {
|
141 | background-image: url(red);
|
142 | }
|
143 | ```
|
144 |
|
145 | ### `ignoreProperties: ["/regex/", /regex/, "string"]`
|
146 |
|
147 | For example with `"never"`.
|
148 |
|
149 | Given:
|
150 |
|
151 | ```
|
152 | ["/^my-/", "composes"]
|
153 | ```
|
154 |
|
155 | The following patterns are _not_ considered violations:
|
156 |
|
157 |
|
158 | ```css
|
159 | a {
|
160 | my-property: red;
|
161 | }
|
162 | ```
|
163 |
|
164 |
|
165 | ```css
|
166 | a {
|
167 | my-other-property: red;
|
168 | }
|
169 | ```
|
170 |
|
171 |
|
172 | ```css
|
173 | a {
|
174 | composes: red from './index.css';
|
175 | }
|
176 | ```
|