stylelint-plugin-defensive-css 0.2.0 → 0.3.0
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/package.json
CHANGED
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
findShorthandBackgroundRepeat,
|
|
8
8
|
} = require('../../utils/findShorthandBackgroundRepeat');
|
|
9
9
|
const { findVendorPrefixes } = require('../../utils/findVendorPrefixes');
|
|
10
|
+
const { findCustomProperties } = require('../../utils/findCustomProperties');
|
|
10
11
|
|
|
11
12
|
const defaultBackgroundRepeatProps = {
|
|
12
13
|
hasBackgroundImage: false,
|
|
@@ -71,14 +72,20 @@ const ruleFunction = (_, options) => {
|
|
|
71
72
|
|
|
72
73
|
/* CUSTOM PROPERTY FALLBACKS */
|
|
73
74
|
if (options?.['custom-property-fallbacks']) {
|
|
74
|
-
|
|
75
|
+
const propertiesWithoutFallback = findCustomProperties(decl.value);
|
|
76
|
+
|
|
77
|
+
if (propertiesWithoutFallback.length) {
|
|
75
78
|
if (Array.isArray(options?.['custom-property-fallbacks'])) {
|
|
76
79
|
if (options['custom-property-fallbacks'][0]) {
|
|
77
80
|
const patterns = options['custom-property-fallbacks'][1].ignore;
|
|
78
|
-
const patternMatched =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
const patternMatched = propertiesWithoutFallback.some(
|
|
82
|
+
(property) => {
|
|
83
|
+
return patterns.some((pattern) =>
|
|
84
|
+
typeof pattern === 'string'
|
|
85
|
+
? new RegExp(pattern).test(property)
|
|
86
|
+
: pattern.test(property),
|
|
87
|
+
);
|
|
88
|
+
},
|
|
82
89
|
);
|
|
83
90
|
|
|
84
91
|
if (patternMatched) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const expression = /var\(.+?\)/g;
|
|
2
|
+
|
|
3
|
+
function findCustomProperties(value) {
|
|
4
|
+
if (!value) return false;
|
|
5
|
+
|
|
6
|
+
let propertiesFound = [...value.trim().matchAll(expression)];
|
|
7
|
+
return propertiesFound
|
|
8
|
+
.map(([property]) => (property.includes(',') ? undefined : property))
|
|
9
|
+
.filter((value) => value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
findCustomProperties,
|
|
14
|
+
};
|