-
Notifications
You must be signed in to change notification settings - Fork 92
/
index.js
49 lines (42 loc) · 1.24 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
import { namespace } from "../../utils";
import { utils } from "stylelint";
export const ruleName = namespace("at-if-no-null");
export const messages = utils.ruleMessages(ruleName, {
equals_null: "Expected @if not statement rather than @if statement == null",
not_equals_null: "Expected @if statement rather than @if statement != null"
});
export default function(expectation) {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, {
actual: expectation
});
if (!validOptions) {
return;
}
root.walkAtRules(atrule => {
// Do nothing if it's not an @if
if (atrule.name !== "if") {
return;
}
// If rule != null and (expr), skip
if (atrule.params.match(/\(?[ \t]*.* != null and .*\)?/)) {
return;
}
if (atrule.params.match(/\(?[ \t]*.* == null[ \t]*\)?/)) {
utils.report({
message: messages.equals_null,
node: atrule,
result,
ruleName
});
} else if (atrule.params.match(/\(?[ \t]*.* != null[ \t]*\)?/)) {
utils.report({
message: messages.not_equals_null,
node: atrule,
result,
ruleName
});
}
});
};
}