forked from stylelint-scss/stylelint-scss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (55 loc) · 1.38 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
import rule, { ruleName, messages, units } from "..";
testRule(rule, {
ruleName,
config: [true],
syntax: "scss",
accept: loopOverUnits({
code: `
p {
padding: 1 * 1%unit%;
}
`,
description: "Accepts proper value interpolation with %unit%"
}).concat([
{
code: "$pad: 2; $doublePad: px#{$pad}px;",
description: "does not report when a unit is preceded by another string"
},
{
code: "$pad: 2; $doublePad: #{$pad}pxx;",
description: "does not report lint when no understood units are used"
},
{
code: `$pad: "2";
$string: "#{$pad}px";`,
description: "does not report lint when string is quoted"
}
]),
reject: loopOverUnits({
code: `
p {
padding: #{$value}%unit%;
}
`,
messages: messages.rejected,
description: "Rejects interpolation with %unit%"
}).concat([
{
code: "$pad: 2; $padAndMore: #{$pad + 5}px;",
description: "reports lint when expression used in interpolation",
messages: messages.rejected("px")
}
])
});
function loopOverUnits(codeBlock) {
return units.map(unit => {
const block = {
code: codeBlock.code.replace("%unit%", unit),
description: codeBlock.description.replace("%unit%", unit)
};
if (codeBlock.messages) {
block["messages"] = codeBlock.messages.call(unit);
}
return block;
});
}