stylelint-config-crisp 1.0.41 → 1.0.42
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
CHANGED
|
@@ -100,8 +100,9 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
|
|
|
100
100
|
| :- | :- |
|
|
101
101
|
| [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`) |
|
|
102
102
|
| [filename-class-match](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/filename-class-match.js) | Ensures that class name is derivated from filename (this rule is only applied to Vue files) |
|
|
103
|
-
| [keyframes-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/keyframes-comment.js) | Requires `// --> KEYFRAMES <--` and an empty line before the first `@keyframes` (including vendor-prefixed variants) in a block, at the same indentation |
|
|
104
|
-
| [media-queries-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/media-queries-comment.js) | Requires `// --> MEDIA-QUERIES <--` and an empty line before the first query (`@media`, `@include mq`, size-based `@container`) in a block, at the same indentation |
|
|
103
|
+
| [keyframes-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/keyframes-comment.js) | Requires `// --> KEYFRAMES <--` and an empty line before the first `@keyframes` (including vendor-prefixed variants) in a block, at the same indentation. Ignored anywhere inside `@mixin` definitions |
|
|
104
|
+
| [media-queries-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/media-queries-comment.js) | Requires `// --> MEDIA-QUERIES <--` and an empty line before the first query (`@media`, `@include mq`, size-based `@container`) in a block, at the same indentation. Ignored anywhere inside `@mixin` definitions |
|
|
105
|
+
| [mixins-comment](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/mixins-comment.js) | Requires `// --> MIXINS <--` and an empty line before the first `@mixin` definition in a block, at the same indentation |
|
|
105
106
|
| [no-inline-colors](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/no-inline-colors.js) | Disallows inline colors (hex, named colors, raw `rgb()` / `hsl()`, Sass color functions and `$color-source--*` variables). Colors must be consumed as CSS variables via `rgb(var(--token))`. Files named `colors.scss`, `codemirror.scss`, `fireworks.scss`, `magic-check.scss` and `reset.scss` are ignored |
|
|
106
107
|
| [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 |
|
|
107
108
|
| [selector-class-interpolation](https://github.com/crisp-oss/stylelint-config-crisp/blob/master/rules/selector-class-interpolation.js) | Enforces class selectors to use Sass interpolation (this rule is only applied to Vue files) |
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ module.exports = {
|
|
|
16
16
|
"./rules/filename-class-match",
|
|
17
17
|
"./rules/keyframes-comment",
|
|
18
18
|
"./rules/media-queries-comment",
|
|
19
|
+
"./rules/mixins-comment",
|
|
19
20
|
"./rules/no-inline-colors",
|
|
20
21
|
"./rules/rule-empty-line-before",
|
|
21
22
|
"./rules/selector-class-interpolation",
|
|
@@ -135,6 +136,7 @@ module.exports = {
|
|
|
135
136
|
"crisp/filename-class-match": true,
|
|
136
137
|
"crisp/keyframes-comment": true,
|
|
137
138
|
"crisp/media-queries-comment": true,
|
|
139
|
+
"crisp/mixins-comment": true,
|
|
138
140
|
"crisp/no-inline-colors": true,
|
|
139
141
|
"crisp/rule-empty-line-before": true,
|
|
140
142
|
"crisp/selector-class-interpolation": true
|
package/package.json
CHANGED
|
@@ -3,5 +3,6 @@ const sectionCommentRule = require("./utils/section-comment-rule");
|
|
|
3
3
|
module.exports = sectionCommentRule(
|
|
4
4
|
"crisp/keyframes-comment",
|
|
5
5
|
"KEYFRAMES",
|
|
6
|
-
(atRule) => /^(?:-[a-z]+-)?keyframes$/i.test(atRule.name)
|
|
6
|
+
(atRule) => /^(?:-[a-z]+-)?keyframes$/i.test(atRule.name),
|
|
7
|
+
["mixin"]
|
|
7
8
|
);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const stylelint = require("stylelint");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const { existsSync } = require("node:fs");
|
|
2
4
|
|
|
3
5
|
// Require one section heading before the first matching at-rule in each block.
|
|
4
|
-
module.exports = (ruleName, heading, isSectionAtRule) => {
|
|
6
|
+
module.exports = (ruleName, heading, isSectionAtRule, ignoredAncestorAtRules = []) => {
|
|
5
7
|
const text = `--> ${heading} <--`;
|
|
6
8
|
const commentLine = `// ${text}`;
|
|
7
9
|
const looseHeading = heading.replace(/-/g, "[-\\s]");
|
|
@@ -12,25 +14,38 @@ module.exports = (ruleName, heading, isSectionAtRule) => {
|
|
|
12
14
|
expectedEmptyLine: `Expected an empty line after "${commentLine}"`
|
|
13
15
|
});
|
|
14
16
|
|
|
15
|
-
const ruleFunction = (primaryOption) => {
|
|
17
|
+
const ruleFunction = (primaryOption, secondaryOptions = {}) => {
|
|
16
18
|
return (root, result) => {
|
|
17
19
|
if (!stylelint.utils.validateOptions(result, ruleName, {
|
|
18
20
|
actual: primaryOption,
|
|
19
21
|
possible: [true]
|
|
22
|
+
}, {
|
|
23
|
+
actual: secondaryOptions,
|
|
24
|
+
possible: {
|
|
25
|
+
ignoreFiles: (value) => Array.isArray(secondaryOptions.ignoreFiles) && typeof value === "string"
|
|
26
|
+
},
|
|
27
|
+
optional: true
|
|
20
28
|
})) {
|
|
21
29
|
return;
|
|
22
30
|
}
|
|
23
31
|
|
|
32
|
+
const filePath = root.source && root.source.input.file;
|
|
33
|
+
|
|
34
|
+
if (filePath && isIgnoredFile(filePath, secondaryOptions.ignoreFiles || [])) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
24
38
|
root.walkAtRules((atRule) => {
|
|
25
39
|
if (!isSectionAtRule(atRule) || hasPreviousSectionAtRule(atRule, isSectionAtRule)) {
|
|
26
40
|
return;
|
|
27
41
|
}
|
|
28
42
|
|
|
29
|
-
// Nested
|
|
43
|
+
// Nested sections inherit their heading; ignored ancestors need none.
|
|
30
44
|
let parent = atRule.parent;
|
|
31
45
|
|
|
32
46
|
while (parent) {
|
|
33
|
-
if (parent.type === "atrule" &&
|
|
47
|
+
if (parent.type === "atrule" &&
|
|
48
|
+
(isSectionAtRule(parent) || ignoredAncestorAtRules.includes(parent.name.toLowerCase()))) {
|
|
34
49
|
return;
|
|
35
50
|
}
|
|
36
51
|
|
|
@@ -94,6 +109,27 @@ module.exports = (ruleName, heading, isSectionAtRule) => {
|
|
|
94
109
|
return stylelint.createPlugin(ruleName, ruleFunction);
|
|
95
110
|
};
|
|
96
111
|
|
|
112
|
+
function isIgnoredFile(filePath, ignoreFiles) {
|
|
113
|
+
if (ignoreFiles.length === 0) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
let directory = path.dirname(filePath);
|
|
118
|
+
|
|
119
|
+
while (!existsSync(path.join(directory, ".git"))) {
|
|
120
|
+
const parent = path.dirname(directory);
|
|
121
|
+
|
|
122
|
+
if (parent === directory) {
|
|
123
|
+
directory = process.cwd();
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
directory = parent;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return ignoreFiles.some((file) => path.resolve(directory, file) === path.resolve(filePath));
|
|
131
|
+
}
|
|
132
|
+
|
|
97
133
|
function hasPreviousSectionAtRule(atRule, isSectionAtRule) {
|
|
98
134
|
let previousNode = atRule.prev();
|
|
99
135
|
|