stylelint-config-crisp 1.0.38 → 1.0.39
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 +2 -0
- package/index.js +10 -1
- package/package.json +1 -1
- package/rules/no-inline-colors.js +456 -0
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
|
|
|
48
48
|
| [color-function-notation](https://stylelint.io/user-guide/rules/color-function-notation/) | Color functions must use legacy notation (`rgba(12, 122, 231, 0.2)` instead of `rgb(12 122 231 / 0.2)`) |
|
|
49
49
|
| [color-hex-length](https://stylelint.io/user-guide/rules/color-hex-length/) | Hex colors must use long notation |
|
|
50
50
|
| [color-no-invalid-hex](https://stylelint.io/user-guide/rules/color-no-invalid-hex/) | Disallows invalid hex colors |
|
|
51
|
+
| [custom-property-pattern](https://stylelint.io/user-guide/rules/custom-property-pattern/) | CSS variables must use kebab-case (`--blue-crisp`, `--grey-90`, `--background-level-0`) |
|
|
51
52
|
| [declaration-block-no-redundant-longhand-properties](https://stylelint.io/user-guide/rules/declaration-block-no-redundant-longhand-properties/) | Disallows redundant longhand properties <br /> - `inset` shorthand is ignored (prefer using the longhand properties `top`, `right`, `bottom` and `left` altogether) <br /> - `overflow` shorthand is ignored (prefer using the longhand properties `overflow-x` and `overflow-y` altogether)|
|
|
52
53
|
| [declaration-block-single-line-max-declarations](https://stylelint.io/user-guide/rules/declaration-block-single-line-max-declarations/) | Allows only 1 declaration per line |
|
|
53
54
|
| [declaration-property-value-disallowed-list](https://stylelint.io/user-guide/rules/declaration-property-value-disallowed-list/) | A list of disallowed property and value pairs within declaration <br /> - `^border: none` is disallowed (prefer `0`, for consistency) <br /> - `outline: none` is disallowed (prefer `0`, for consistency) |
|
|
@@ -99,6 +100,7 @@ This is the list of configured syntaxes, plugins and rules used by Stylelint Con
|
|
|
99
100
|
| :- | :- |
|
|
100
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`) |
|
|
101
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
|
+
| [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 |
|
|
102
104
|
| [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 |
|
|
103
105
|
| [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) |
|
|
104
106
|
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = {
|
|
|
14
14
|
plugins: [
|
|
15
15
|
"./rules/at-rule-conditional-parentheses",
|
|
16
16
|
"./rules/filename-class-match",
|
|
17
|
+
"./rules/no-inline-colors",
|
|
17
18
|
"./rules/rule-empty-line-before",
|
|
18
19
|
"./rules/selector-class-interpolation",
|
|
19
20
|
|
|
@@ -35,6 +36,13 @@ module.exports = {
|
|
|
35
36
|
"color-function-notation": "legacy",
|
|
36
37
|
"color-hex-length": "long",
|
|
37
38
|
"color-no-invalid-hex": true,
|
|
39
|
+
"custom-property-pattern": [
|
|
40
|
+
"^([a-z][a-z0-9]*)(-[a-z0-9]+)*$",
|
|
41
|
+
|
|
42
|
+
{
|
|
43
|
+
"message": "Expected CSS variable name to be kebab-case"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
38
46
|
"declaration-block-no-redundant-longhand-properties": [
|
|
39
47
|
true,
|
|
40
48
|
|
|
@@ -123,7 +131,8 @@ module.exports = {
|
|
|
123
131
|
// Crisp rules
|
|
124
132
|
"crisp/at-rule-conditional-parentheses": true,
|
|
125
133
|
"crisp/filename-class-match": true,
|
|
134
|
+
"crisp/no-inline-colors": true,
|
|
126
135
|
"crisp/rule-empty-line-before": true,
|
|
127
136
|
"crisp/selector-class-interpolation": true
|
|
128
137
|
}
|
|
129
|
-
}
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
const stylelint = require("stylelint");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const ruleName = "crisp/no-inline-colors";
|
|
5
|
+
const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
6
|
+
rejected: (color) => {
|
|
7
|
+
return `Unexpected inline color "${color}", use a CSS variable (rgb(var(--token)))`;
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
rejectedSource: (variable) => {
|
|
11
|
+
return `Unexpected color source variable "${variable}", use the CSS variable equivalent`;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const DEFAULT_IGNORE_FILES = [
|
|
16
|
+
"colors.scss",
|
|
17
|
+
"reset.scss"
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const HEX_COLOR_PATTERN = /#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
|
|
21
|
+
|
|
22
|
+
const SOURCE_VARIABLE_PATTERN = /\$color-source--[\w-]+/g;
|
|
23
|
+
|
|
24
|
+
const RGB_CHANNELS_PATTERN = /^\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*$/;
|
|
25
|
+
|
|
26
|
+
const SKIP_VALUE_PATTERN = /url\((?:[^)]*)\)|(["'])(?:\\.|(?!\1).)*\1/gi;
|
|
27
|
+
|
|
28
|
+
const FUNCTION_NAME_CHAR_PATTERN = /[\w.-]/;
|
|
29
|
+
|
|
30
|
+
const FUNCTION_NAME_PATTERN = /^[a-z_]/;
|
|
31
|
+
|
|
32
|
+
const VAR_FUNCTION_PATTERN = /\bvar\s*\(/;
|
|
33
|
+
|
|
34
|
+
const SASS_VARIABLE_PATTERN = /\$[\w-]+/;
|
|
35
|
+
|
|
36
|
+
const NUMERIC_ARGS_PATTERN = /^[\d.]+%?$/;
|
|
37
|
+
|
|
38
|
+
const COLOR_FUNCTIONS = new Set([
|
|
39
|
+
"rgb",
|
|
40
|
+
"rgba",
|
|
41
|
+
"hsl",
|
|
42
|
+
"hsla",
|
|
43
|
+
"hwb",
|
|
44
|
+
"lab",
|
|
45
|
+
"lch",
|
|
46
|
+
"oklab",
|
|
47
|
+
"oklch",
|
|
48
|
+
"color"
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
const SASS_COLOR_FUNCTIONS = new Set([
|
|
52
|
+
"lighten",
|
|
53
|
+
"darken",
|
|
54
|
+
"mix",
|
|
55
|
+
"adjust-color",
|
|
56
|
+
"scale-color",
|
|
57
|
+
"change-color",
|
|
58
|
+
"saturate",
|
|
59
|
+
"desaturate",
|
|
60
|
+
"grayscale",
|
|
61
|
+
"complement",
|
|
62
|
+
"invert",
|
|
63
|
+
"opacify",
|
|
64
|
+
"transparentize",
|
|
65
|
+
"fade-in",
|
|
66
|
+
"fade-out",
|
|
67
|
+
"color.adjust",
|
|
68
|
+
"color.mix",
|
|
69
|
+
"color.scale",
|
|
70
|
+
"color.change",
|
|
71
|
+
"color.complement",
|
|
72
|
+
"color.grayscale",
|
|
73
|
+
"color.invert",
|
|
74
|
+
"color.saturate",
|
|
75
|
+
"color.desaturate"
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
const CSS_FILTER_FUNCTIONS = new Set([
|
|
79
|
+
"invert",
|
|
80
|
+
"grayscale",
|
|
81
|
+
"saturate"
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
const NAMED_COLORS = new Set([
|
|
85
|
+
"aliceblue",
|
|
86
|
+
"antiquewhite",
|
|
87
|
+
"aqua",
|
|
88
|
+
"aquamarine",
|
|
89
|
+
"azure",
|
|
90
|
+
"beige",
|
|
91
|
+
"bisque",
|
|
92
|
+
"black",
|
|
93
|
+
"blanchedalmond",
|
|
94
|
+
"blue",
|
|
95
|
+
"blueviolet",
|
|
96
|
+
"brown",
|
|
97
|
+
"burlywood",
|
|
98
|
+
"cadetblue",
|
|
99
|
+
"chartreuse",
|
|
100
|
+
"chocolate",
|
|
101
|
+
"coral",
|
|
102
|
+
"cornflowerblue",
|
|
103
|
+
"cornsilk",
|
|
104
|
+
"crimson",
|
|
105
|
+
"cyan",
|
|
106
|
+
"darkblue",
|
|
107
|
+
"darkcyan",
|
|
108
|
+
"darkgoldenrod",
|
|
109
|
+
"darkgray",
|
|
110
|
+
"darkgreen",
|
|
111
|
+
"darkgrey",
|
|
112
|
+
"darkkhaki",
|
|
113
|
+
"darkmagenta",
|
|
114
|
+
"darkolivegreen",
|
|
115
|
+
"darkorange",
|
|
116
|
+
"darkorchid",
|
|
117
|
+
"darkred",
|
|
118
|
+
"darksalmon",
|
|
119
|
+
"darkseagreen",
|
|
120
|
+
"darkslateblue",
|
|
121
|
+
"darkslategray",
|
|
122
|
+
"darkslategrey",
|
|
123
|
+
"darkturquoise",
|
|
124
|
+
"darkviolet",
|
|
125
|
+
"deeppink",
|
|
126
|
+
"deepskyblue",
|
|
127
|
+
"dimgray",
|
|
128
|
+
"dimgrey",
|
|
129
|
+
"dodgerblue",
|
|
130
|
+
"firebrick",
|
|
131
|
+
"floralwhite",
|
|
132
|
+
"forestgreen",
|
|
133
|
+
"fuchsia",
|
|
134
|
+
"gainsboro",
|
|
135
|
+
"ghostwhite",
|
|
136
|
+
"gold",
|
|
137
|
+
"goldenrod",
|
|
138
|
+
"gray",
|
|
139
|
+
"green",
|
|
140
|
+
"greenyellow",
|
|
141
|
+
"grey",
|
|
142
|
+
"honeydew",
|
|
143
|
+
"hotpink",
|
|
144
|
+
"indianred",
|
|
145
|
+
"indigo",
|
|
146
|
+
"ivory",
|
|
147
|
+
"khaki",
|
|
148
|
+
"lavender",
|
|
149
|
+
"lavenderblush",
|
|
150
|
+
"lawngreen",
|
|
151
|
+
"lemonchiffon",
|
|
152
|
+
"lightblue",
|
|
153
|
+
"lightcoral",
|
|
154
|
+
"lightcyan",
|
|
155
|
+
"lightgoldenrodyellow",
|
|
156
|
+
"lightgray",
|
|
157
|
+
"lightgreen",
|
|
158
|
+
"lightgrey",
|
|
159
|
+
"lightpink",
|
|
160
|
+
"lightsalmon",
|
|
161
|
+
"lightseagreen",
|
|
162
|
+
"lightskyblue",
|
|
163
|
+
"lightslategray",
|
|
164
|
+
"lightslategrey",
|
|
165
|
+
"lightsteelblue",
|
|
166
|
+
"lightyellow",
|
|
167
|
+
"lime",
|
|
168
|
+
"limegreen",
|
|
169
|
+
"linen",
|
|
170
|
+
"magenta",
|
|
171
|
+
"maroon",
|
|
172
|
+
"mediumaquamarine",
|
|
173
|
+
"mediumblue",
|
|
174
|
+
"mediumorchid",
|
|
175
|
+
"mediumpurple",
|
|
176
|
+
"mediumseagreen",
|
|
177
|
+
"mediumslateblue",
|
|
178
|
+
"mediumspringgreen",
|
|
179
|
+
"mediumturquoise",
|
|
180
|
+
"mediumvioletred",
|
|
181
|
+
"midnightblue",
|
|
182
|
+
"mintcream",
|
|
183
|
+
"mistyrose",
|
|
184
|
+
"moccasin",
|
|
185
|
+
"navajowhite",
|
|
186
|
+
"navy",
|
|
187
|
+
"oldlace",
|
|
188
|
+
"olive",
|
|
189
|
+
"olivedrab",
|
|
190
|
+
"orange",
|
|
191
|
+
"orangered",
|
|
192
|
+
"orchid",
|
|
193
|
+
"palegoldenrod",
|
|
194
|
+
"palegreen",
|
|
195
|
+
"paleturquoise",
|
|
196
|
+
"palevioletred",
|
|
197
|
+
"papayawhip",
|
|
198
|
+
"peachpuff",
|
|
199
|
+
"peru",
|
|
200
|
+
"pink",
|
|
201
|
+
"plum",
|
|
202
|
+
"powderblue",
|
|
203
|
+
"purple",
|
|
204
|
+
"rebeccapurple",
|
|
205
|
+
"red",
|
|
206
|
+
"rosybrown",
|
|
207
|
+
"royalblue",
|
|
208
|
+
"saddlebrown",
|
|
209
|
+
"salmon",
|
|
210
|
+
"sandybrown",
|
|
211
|
+
"seagreen",
|
|
212
|
+
"seashell",
|
|
213
|
+
"sienna",
|
|
214
|
+
"silver",
|
|
215
|
+
"skyblue",
|
|
216
|
+
"slateblue",
|
|
217
|
+
"slategray",
|
|
218
|
+
"slategrey",
|
|
219
|
+
"snow",
|
|
220
|
+
"springgreen",
|
|
221
|
+
"steelblue",
|
|
222
|
+
"tan",
|
|
223
|
+
"teal",
|
|
224
|
+
"thistle",
|
|
225
|
+
"tomato",
|
|
226
|
+
"turquoise",
|
|
227
|
+
"violet",
|
|
228
|
+
"wheat",
|
|
229
|
+
"white",
|
|
230
|
+
"whitesmoke",
|
|
231
|
+
"yellow",
|
|
232
|
+
"yellowgreen"
|
|
233
|
+
]);
|
|
234
|
+
|
|
235
|
+
const NAMED_COLOR_PATTERN = new RegExp(
|
|
236
|
+
`(?<![-$@#.\\w])(${Array.from(NAMED_COLORS).join("|")})(?![-$\\w])`,
|
|
237
|
+
"gi"
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
const ruleFunction = (primaryOption, secondaryOptions = {}) => {
|
|
241
|
+
return (root, result) => {
|
|
242
|
+
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
|
|
243
|
+
actual: primaryOption,
|
|
244
|
+
possible: [true]
|
|
245
|
+
}, {
|
|
246
|
+
actual: secondaryOptions,
|
|
247
|
+
possible: {
|
|
248
|
+
ignoreFiles: [isString]
|
|
249
|
+
},
|
|
250
|
+
optional: true
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
if (!validOptions) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const ignoreFiles = secondaryOptions.ignoreFiles || DEFAULT_IGNORE_FILES;
|
|
258
|
+
|
|
259
|
+
if (isIgnoredFile(root.source && root.source.input.file, ignoreFiles)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
root.walkDecls((decl) => {
|
|
264
|
+
if (decl.prop.startsWith("--") && RGB_CHANNELS_PATTERN.test(decl.value)) {
|
|
265
|
+
report(decl, result, messages.rejected(decl.value.trim()), decl.value.trim());
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
checkValue(decl.value, decl, result);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
root.walkAtRules((atRule) => {
|
|
272
|
+
if (!atRule.params) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
checkValue(atRule.params, atRule, result);
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Scan a CSS/SCSS value for inline colors
|
|
282
|
+
function checkValue(value, node, result) {
|
|
283
|
+
const skipRanges = getSkipRanges(value);
|
|
284
|
+
|
|
285
|
+
findMatches(value, SOURCE_VARIABLE_PATTERN, skipRanges).forEach((color) => {
|
|
286
|
+
report(node, result, messages.rejectedSource(color), color);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
findMatches(value, HEX_COLOR_PATTERN, skipRanges).forEach((color) => {
|
|
290
|
+
report(node, result, messages.rejected(color), color);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
findMatches(value, NAMED_COLOR_PATTERN, skipRanges).forEach((color) => {
|
|
294
|
+
report(node, result, messages.rejected(color), color);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
forEachFunction(value, (name, args) => {
|
|
298
|
+
if (isSkippedIndex(skipRanges, args.index)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (SASS_COLOR_FUNCTIONS.has(name)) {
|
|
303
|
+
// `invert()`, `grayscale()` and `saturate()` are also CSS filters
|
|
304
|
+
if (CSS_FILTER_FUNCTIONS.has(name) && isNumericFunctionArgs(args.value)) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
report(node, result, messages.rejected(`${name}()`), name);
|
|
309
|
+
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// `rgb(var(--token))` and `rgb($color)` wrap a variable, they are not inline colors
|
|
314
|
+
if (!COLOR_FUNCTIONS.has(name) || hasVarFunction(args.value) || hasSassVariable(args.value)) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Hex and named colors inside the function are reported separately
|
|
319
|
+
if (hasPattern(HEX_COLOR_PATTERN, args.value) || hasPattern(NAMED_COLOR_PATTERN, args.value)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
report(node, result, messages.rejected(`${name}(${args.value.trim()})`), name);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Report a violation
|
|
328
|
+
function report(node, result, message, word) {
|
|
329
|
+
stylelint.utils.report({
|
|
330
|
+
ruleName,
|
|
331
|
+
result,
|
|
332
|
+
node,
|
|
333
|
+
message,
|
|
334
|
+
word
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Ranges that should not be scanned (url() and quoted strings)
|
|
339
|
+
function getSkipRanges(value) {
|
|
340
|
+
const ranges = [];
|
|
341
|
+
let match;
|
|
342
|
+
|
|
343
|
+
while ((match = SKIP_VALUE_PATTERN.exec(value)) !== null) {
|
|
344
|
+
ranges.push([match.index, match.index + match[0].length]);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
SKIP_VALUE_PATTERN.lastIndex = 0;
|
|
348
|
+
|
|
349
|
+
return ranges;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Collect regex matches outside skipped ranges
|
|
353
|
+
function findMatches(value, pattern, skipRanges) {
|
|
354
|
+
const matches = [];
|
|
355
|
+
let match;
|
|
356
|
+
|
|
357
|
+
pattern.lastIndex = 0;
|
|
358
|
+
|
|
359
|
+
while ((match = pattern.exec(value)) !== null) {
|
|
360
|
+
if (!isSkippedIndex(skipRanges, match.index)) {
|
|
361
|
+
matches.push(match[0]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
pattern.lastIndex = 0;
|
|
366
|
+
|
|
367
|
+
return matches;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Walk function calls in a value (including nested ones)
|
|
371
|
+
function forEachFunction(value, callback) {
|
|
372
|
+
for (let index = 0; index < value.length; index++) {
|
|
373
|
+
if (value[index] !== "(") {
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let nameStart = index - 1;
|
|
378
|
+
|
|
379
|
+
while (nameStart >= 0 && FUNCTION_NAME_CHAR_PATTERN.test(value[nameStart])) {
|
|
380
|
+
nameStart--;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
nameStart++;
|
|
384
|
+
|
|
385
|
+
const name = value.slice(nameStart, index).toLowerCase();
|
|
386
|
+
|
|
387
|
+
if (!name || !FUNCTION_NAME_PATTERN.test(name)) {
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
let depth = 1;
|
|
392
|
+
let end = index + 1;
|
|
393
|
+
|
|
394
|
+
while (end < value.length && depth > 0) {
|
|
395
|
+
if (value[end] === "(") {
|
|
396
|
+
depth++;
|
|
397
|
+
} else if (value[end] === ")") {
|
|
398
|
+
depth--;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
end++;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
callback(name, {
|
|
405
|
+
value: value.slice(index + 1, end - 1),
|
|
406
|
+
index: index + 1
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Check if a file name is ignored
|
|
412
|
+
function isIgnoredFile(filePath, ignoreFiles) {
|
|
413
|
+
if (!filePath) {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const fileName = path.basename(filePath);
|
|
418
|
+
|
|
419
|
+
return ignoreFiles.includes(fileName);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function hasVarFunction(value) {
|
|
423
|
+
return VAR_FUNCTION_PATTERN.test(value);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function hasSassVariable(value) {
|
|
427
|
+
return SASS_VARIABLE_PATTERN.test(value);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function isNumericFunctionArgs(value) {
|
|
431
|
+
const first = value.trim().split(",")[0].trim();
|
|
432
|
+
|
|
433
|
+
return NUMERIC_ARGS_PATTERN.test(first);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function hasPattern(pattern, value) {
|
|
437
|
+
pattern.lastIndex = 0;
|
|
438
|
+
|
|
439
|
+
const matches = pattern.test(value);
|
|
440
|
+
|
|
441
|
+
pattern.lastIndex = 0;
|
|
442
|
+
|
|
443
|
+
return matches;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function isSkippedIndex(ranges, index) {
|
|
447
|
+
return ranges.some(([start, end]) => {
|
|
448
|
+
return index >= start && index < end;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function isString(value) {
|
|
453
|
+
return typeof value === "string";
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
module.exports = stylelint.createPlugin(ruleName, ruleFunction);
|