UNPKG

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