/
index.js
331 lines (323 loc) · 6.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import rule, { messages, ruleName } from "..";
testRule(rule, {
ruleName,
config: ["always"],
syntax: "scss",
accept: [
{
code: `
.foo {
.bar {}
}
`,
description: "when child combinators are nested"
},
{
code: `
.foo {
&.bar {}
}
`,
description: "when chained combinators are nested"
},
{
code: `
.foo {
& > .bar {}
}
`,
description: "when direct descendant combinators are nested"
},
{
code: `
.baz {
.foo.bar & {}
}
`,
description:
"when chained combinators can't be nested due to preceding a parent selector"
},
{
code: `
.foo {
&bar {
&baz {}
}
}
`,
description: "when parent selectors are used for concatenation"
},
{
code: `
.foo {
&__bar {
&--baz {}
}
}
`,
description: "when parent selectors are used for BEM style concatenation"
},
{
code: `
.foo {
&:hover {}
}
`,
description: "when pseudo classes are nested"
},
{
code: `
.foo {
&:nth-child(2n - 1) {}
}
`,
description: "when an nth child selector is used which includes spaces"
},
{
code: `
[data-test="foo bar"] {}
`,
description: "when an attribute selector is used with spaces in it"
},
{
code: `
:not([class]:last-child) {}
`,
description: "when selectors are chained within a not selector"
},
{
code: `
.class-name {
#{if(&, "&", "")} {
}
}
`,
description: "should support interpolation"
}
],
reject: [
{
code: `
.foo .bar {}
`,
description: "when a child combinator is used instead of nesting",
messages: messages.expected(" ", "combinator"),
line: 2,
column: 11
},
{
code: `
.foo.bar {}
`,
description: "when a selector is chained with another",
messages: messages.expected(".bar", "class"),
line: 2,
column: 11
},
{
code: `
.foo > .bar {}
`,
description:
"when a direct descendant combinator is used without nesting",
messages: messages.expected(">", "combinator"),
line: 2,
column: 12
},
{
code: `
.foo:hover {}
`,
description: "when pseudo classes are used without nesting",
messages: messages.expected(":hover", "pseudo"),
line: 2,
column: 11
},
{
code: `
* + li {}
`,
description: "when universal selectors are used with a combinator",
messages: messages.expected("+", "combinator"),
line: 2,
column: 9
},
{
code: `
:nth-child(2n - 1):last-child {}
`,
description: "when pseudo selectors only are chained",
messages: messages.expected(":last-child", "pseudo"),
line: 2,
column: 25
},
{
code: `
.class-name #{if(&, "&", "")} {}
`,
description: "when interpolation is used",
messages: messages.expectedInterpolation,
line: 2,
column: 18
}
]
});
testRule(rule, {
ruleName,
config: ["never"],
syntax: "scss",
accept: [
{
code: `
.foo .bar {}
`,
description: "when a child combinator is used instead of nesting"
},
{
code: `
.foo.bar {}
`,
description: "when a selector is chained with another"
},
{
code: `
.foo > .bar {}
`,
description: "when a direct descendant combinator is used without nesting"
},
{
code: `
.foo:hover {}
`,
description: "when pseudo classes are used without nesting"
},
{
code: `
@media screen {
.foo {}
}
`,
description: "when selectors are nested inside @media"
},
{
code: `
@keyframes foo {
0% {}
100% {}
}
`,
description: "when a keyframes rule is used"
},
{
code: `
@include mixin {
.foo {}
}
`,
description:
"when selectors are nested in a mixin, e.g. when making use of @content"
},
{
code: `
.foo:nth-child(2n-1) {}
`,
description: "when using an nth-child selector"
},
{
code: `
#foo:not([class]:last-child) {}
`,
description: "when using a not selector"
},
{
code: `
.class-name #{if(&, "&", "")} {}
`,
description: "should support interpolation"
}
],
reject: [
{
code: `
.foo {
.bar {}
}
`,
description: "when child combinators are nested",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.foo {
&.bar {}
}
`,
description: "when chained combinators are nested",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.foo {
& > bar {}
}
`,
description: "when direct descendant combinators are nested",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.foo {
&bar {
&baz {}
}
}
`,
description: "when parent selectors are used for concatenation",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.foo {
&__bar {
&--baz {}
}
}
`,
description: "when parent selectors are used for BEM style concatenation",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.foo {
&:hover {}
}
`,
description: "when pseudo classes are nested",
messages: messages.rejected,
line: 3,
column: 9
},
{
code: `
.class-name {
#{if(&, "&", "")} {
}
}
`,
description: "when interpolation is used",
messages: messages.rejected,
line: 3,
column: 8
}
]
});