1 | # selector-class-pattern
|
2 |
|
3 | Specify a pattern for class selectors.
|
4 |
|
5 |
|
6 | ```css
|
7 | .foo, #bar.baz span, #hoo[disabled] { color: pink; }
|
8 | /** ↑ ↑
|
9 | * These class selectors */
|
10 | ```
|
11 |
|
12 | This rule ignores non-outputting Less mixin definitions and called Less mixins.
|
13 |
|
14 | Escaped selectors (e.g. `.u-size-11\/12\@sm`) are parsed as escaped twice (e.g. `.u-size-11\\/12\\@sm`). Your RegExp should account for that.
|
15 |
|
16 | ## Options
|
17 |
|
18 | `regex|string`
|
19 |
|
20 | A string will be translated into a RegExp like so `new RegExp(yourString)` — so be sure to escape properly.
|
21 |
|
22 | The selector value _after `.`_ will be checked. No need to include `.` in your pattern.
|
23 |
|
24 | Given the string:
|
25 |
|
26 | ```js
|
27 | "foo-[a-z]+";
|
28 |
|
29 | ```
|
30 |
|
31 | The following patterns are considered violations:
|
32 |
|
33 |
|
34 | ```css
|
35 | .foop {}
|
36 | ```
|
37 |
|
38 |
|
39 | ```css
|
40 | .foo-BAR {}
|
41 | ```
|
42 |
|
43 |
|
44 | ```css
|
45 | div > #zing + .foo-BAR {}
|
46 | ```
|
47 |
|
48 | The following patterns are _not_ considered violations:
|
49 |
|
50 |
|
51 | ```css
|
52 | .foo-bar {}
|
53 | ```
|
54 |
|
55 |
|
56 | ```css
|
57 | div > #zing + .foo-bar {}
|
58 | ```
|
59 |
|
60 |
|
61 | ```css
|
62 | #foop {}
|
63 | ```
|
64 |
|
65 |
|
66 | ```css
|
67 | [foo='bar'] {}
|
68 | ```
|
69 |
|
70 | ## Optional secondary options
|
71 |
|
72 | ### `resolveNestedSelectors: true | false` (default: `false`)
|
73 |
|
74 | This option will resolve nested selectors with `&` interpolation.
|
75 |
|
76 | For example, with `true`.
|
77 |
|
78 | Given the string:
|
79 |
|
80 | ```
|
81 | "^[A-Z]+$"
|
82 | ```
|
83 |
|
84 | The following patterns are considered violations:
|
85 |
|
86 |
|
87 | ```css
|
88 | .A {
|
89 | &__B {} /* resolved to ".A__B" */
|
90 | }
|
91 | ```
|
92 |
|
93 | The following patterns are _not_ considered violations:
|
94 |
|
95 |
|
96 | ```css
|
97 | .A {
|
98 | &B {} /* resolved to ".AB" */
|
99 | }
|
100 | ```
|