stylelint-config-crisp 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/index.js +11 -1
- package/package.json +1 -1
- package/rules/at-rule-conditional-parentheses.js +17 -4
- package/rules/rule-empty-line-before.js +50 -0
package/README.md
CHANGED
|
@@ -48,6 +48,9 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
|
|
|
48
48
|
* `outline: none` is disallowed (prefer `0`, for consistency)
|
|
49
49
|
- [keyframe-block-no-duplicate-selectors](https://stylelint.io/user-guide/rules/keyframe-block-no-duplicate-selectors/): Rule is **disabled**, in order to allow cascade selectors within keyframe blocks (seems they are not supported by this rule, yet)
|
|
50
50
|
- [number-max-precision](https://stylelint.io/user-guide/rules/number-max-precision/): Allows a maximum of 5 decimal places in numbers
|
|
51
|
+
- [rule-empty-line-before](https://stylelint.io/user-guide/rules/rule-empty-line-before/): Requires an empty line before multi-line rules
|
|
52
|
+
* `"first-nested"` is reversed (for rules that are nested and the first child of their parent node, we don't want any empty line)
|
|
53
|
+
* `"after-comment"` is ignored (for rules that follow a comment)
|
|
51
54
|
- [selector-class-pattern](https://stylelint.io/user-guide/rules/selector-class-pattern/): Rule is **disabled** as it conflicts with our BEM notation in class selectors
|
|
52
55
|
- [selector-pseudo-class-no-unknown](https://stylelint.io/user-guide/rules/selector-pseudo-class-no-unknown/): Disallows unknown pseudo-class selectors
|
|
53
56
|
- [selector-pseudo-element-colon-notation](https://stylelint.io/user-guide/rules/selector-pseudo-element-colon-notation/): Pseudo-elements must use the single colon notation
|
|
@@ -79,6 +82,7 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
|
|
|
79
82
|
|
|
80
83
|
#### Crisp rules
|
|
81
84
|
- [at-rule-conditional-parentheses](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/at-rule-conditional-parentheses.js): Enforces parentheses in conditions of at-rules (`@if`, `@elseif`, `@while`)
|
|
85
|
+
- [rule-empty-line-before](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/rule-empty-line-before.js): Requires an empty line before multi-line rules the same way [rule-empty-line-before](https://stylelint.io/user-guide/rules/rule-empty-line-before/) does, but properly handles Sass interpolation `#{}` in selectors
|
|
82
86
|
|
|
83
87
|
## License
|
|
84
88
|
|
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ module.exports = {
|
|
|
13
13
|
|
|
14
14
|
plugins: [
|
|
15
15
|
"./rules/at-rule-conditional-parentheses",
|
|
16
|
+
"./rules/rule-empty-line-before",
|
|
16
17
|
|
|
17
18
|
"stylelint-order"
|
|
18
19
|
],
|
|
@@ -54,6 +55,14 @@ module.exports = {
|
|
|
54
55
|
},
|
|
55
56
|
"keyframe-block-no-duplicate-selectors": null,
|
|
56
57
|
"number-max-precision": 5,
|
|
58
|
+
"rule-empty-line-before": [
|
|
59
|
+
"always-multi-line",
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
"except": ["first-nested"],
|
|
63
|
+
"ignore": ["after-comment"]
|
|
64
|
+
}
|
|
65
|
+
],
|
|
57
66
|
"selector-class-pattern": null,
|
|
58
67
|
"selector-pseudo-class-no-unknown": [
|
|
59
68
|
true,
|
|
@@ -107,6 +116,7 @@ module.exports = {
|
|
|
107
116
|
],
|
|
108
117
|
|
|
109
118
|
// Crisp rules
|
|
110
|
-
"crisp/at-rule-conditional-parentheses": true
|
|
119
|
+
"crisp/at-rule-conditional-parentheses": true,
|
|
120
|
+
"crisp/rule-empty-line-before": true
|
|
111
121
|
}
|
|
112
122
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ const ruleFunction = (primaryOption, secondaryOptions, context) => {
|
|
|
9
9
|
return (root, result) => {
|
|
10
10
|
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
|
|
11
11
|
actual: primaryOption,
|
|
12
|
-
possible: [true
|
|
12
|
+
possible: [true]
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
if (!validOptions) {
|
|
@@ -17,13 +17,26 @@ const ruleFunction = (primaryOption, secondaryOptions, context) => {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
root.walkAtRules((rule) => {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
let elseIf = false;
|
|
21
|
+
|
|
22
|
+
// An `@else if` is a regular `@else` with `if` in its params
|
|
23
|
+
if (rule.name === "else" && rule.params.startsWith("if ")) {
|
|
24
|
+
elseIf = true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (["if", "while"].includes(rule.name) || elseIf === true) {
|
|
28
|
+
let params = rule.params;
|
|
29
|
+
|
|
30
|
+
if (elseIf === true) {
|
|
31
|
+
params = params.slice(3);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!params.startsWith("(") || !params.endsWith(")")) {
|
|
22
35
|
stylelint.utils.report({
|
|
23
36
|
ruleName,
|
|
24
37
|
result,
|
|
25
38
|
node: rule,
|
|
26
|
-
message: messages.expected
|
|
39
|
+
message: messages.expected
|
|
27
40
|
});
|
|
28
41
|
}
|
|
29
42
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const stylelint = require("stylelint");
|
|
2
|
+
|
|
3
|
+
const ruleName = "crisp/rule-empty-line-before";
|
|
4
|
+
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
5
|
+
expected: "Expected an empty line before the rule",
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const ruleFunction = (primaryOption, secondaryOptions, context) => {
|
|
9
|
+
return (root, result) => {
|
|
10
|
+
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
|
|
11
|
+
actual: primaryOption,
|
|
12
|
+
possible: [true]
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!validOptions) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
root.walkRules((rule) => {
|
|
20
|
+
// Skip root-level rules and the first child of any rule
|
|
21
|
+
if (rule.parent.type === "root" || !rule.prev()) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let previousNode = rule.prev();
|
|
26
|
+
|
|
27
|
+
// Find the first relevant node (declaration, rule, or comment)
|
|
28
|
+
while (previousNode && previousNode.type !== "comment") {
|
|
29
|
+
if (previousNode.type === "decl" || previousNode.type === "rule") {
|
|
30
|
+
const hasEmptyLineBefore = /(\r?\n\s*\r?\n\s*)/.test(rule.raws.before);
|
|
31
|
+
|
|
32
|
+
if (!hasEmptyLineBefore) {
|
|
33
|
+
stylelint.utils.report({
|
|
34
|
+
ruleName,
|
|
35
|
+
result,
|
|
36
|
+
node: rule,
|
|
37
|
+
message: messages.expected
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
previousNode = previousNode.prev();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
module.exports = stylelint.createPlugin(ruleName, ruleFunction);
|