@d-zero/stylelint-rules 5.0.0-alpha.13 → 5.0.0-alpha.15
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import CSSTree from '@d-zero/csstree-scss-syntax';
|
|
2
2
|
import postcssValueParser from 'postcss-value-parser';
|
|
3
3
|
export function getValueType(decl) {
|
|
4
|
+
if (decl.prop.startsWith('$')) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
4
7
|
return _getValueType(decl.prop, decl.value);
|
|
5
8
|
}
|
|
6
9
|
function _getValueType(prop, value) {
|
|
@@ -14,33 +17,40 @@ function _getValueType(prop, value) {
|
|
|
14
17
|
const values = valueAst.nodes.filter((node) => node.type === 'string' || node.type === 'function' || node.type === 'word');
|
|
15
18
|
const props = cssTreeDecl.matched;
|
|
16
19
|
if (props === null) {
|
|
17
|
-
|
|
20
|
+
return null;
|
|
18
21
|
}
|
|
19
|
-
const valueTypes = props.match
|
|
22
|
+
const valueTypes = props.match
|
|
23
|
+
.flatMap((node) => getValueNode(node))
|
|
24
|
+
.map((node) => node.syntax.name);
|
|
20
25
|
return values.map((value, i) => {
|
|
21
26
|
const valueType = valueTypes[i] ?? null;
|
|
22
|
-
if (valueType === null) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
throw new Error('Value type not found');
|
|
27
|
+
if (valueType === null && value.type === 'word' && value.value.startsWith('$')) {
|
|
28
|
+
return {
|
|
29
|
+
value: value,
|
|
30
|
+
valueType: '$SASS_VARIABLE',
|
|
31
|
+
};
|
|
30
32
|
}
|
|
31
33
|
return {
|
|
32
34
|
value,
|
|
33
|
-
valueType,
|
|
35
|
+
valueType: valueType ?? 'unknown',
|
|
34
36
|
};
|
|
35
37
|
});
|
|
36
38
|
}
|
|
37
39
|
function getValueNode(node) {
|
|
38
|
-
if (isProperty(node)) {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
if (isProperty(node) || isType(node)) {
|
|
41
|
+
if (node.match[0].syntax === null) {
|
|
42
|
+
return isProperty(node) ? [] : [node];
|
|
43
|
+
}
|
|
44
|
+
if (isType(node) && node.match.length === 1) {
|
|
45
|
+
return [node];
|
|
46
|
+
}
|
|
47
|
+
return node.match.flatMap((child) => child.syntax === null ? [] : getValueNode(child));
|
|
41
48
|
}
|
|
42
|
-
return node;
|
|
49
|
+
return [node];
|
|
43
50
|
}
|
|
44
51
|
function isProperty(node) {
|
|
45
|
-
return node.syntax
|
|
52
|
+
return node.syntax?.type === 'Property';
|
|
53
|
+
}
|
|
54
|
+
function isType(node) {
|
|
55
|
+
return node.syntax?.type === 'Type';
|
|
46
56
|
}
|
|
@@ -6,7 +6,7 @@ function p(css) {
|
|
|
6
6
|
const rule = root.first;
|
|
7
7
|
const decl = rule.first;
|
|
8
8
|
const nodeWithType = getValueType(decl);
|
|
9
|
-
return nodeWithType
|
|
9
|
+
return nodeWithType?.map((node) => node.valueType) ?? null;
|
|
10
10
|
}
|
|
11
11
|
describe('getValueType', () => {
|
|
12
12
|
test('flex', () => {
|
|
@@ -22,7 +22,19 @@ describe('getValueType', () => {
|
|
|
22
22
|
test('height vw', () => {
|
|
23
23
|
expect(p('a { height: 100vw }')).toEqual(['length']);
|
|
24
24
|
});
|
|
25
|
+
test('background', () => {
|
|
26
|
+
expect(p('a { background: url(../../img/edit.png) no-repeat scroll 0 0 }')).toEqual([
|
|
27
|
+
'bg-image',
|
|
28
|
+
'repeat-style',
|
|
29
|
+
'attachment',
|
|
30
|
+
'length-percentage',
|
|
31
|
+
'length-percentage',
|
|
32
|
+
]);
|
|
33
|
+
});
|
|
25
34
|
test('SASS Variable', () => {
|
|
26
35
|
expect(p('a { flex: 1 2 $basis }')).toEqual(['number', 'number', '$SASS_VARIABLE']);
|
|
27
36
|
});
|
|
37
|
+
test('SASS Variable Definition', () => {
|
|
38
|
+
expect(p('a { $var: value }')).toEqual(null);
|
|
39
|
+
});
|
|
28
40
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/stylelint-rules",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.15",
|
|
4
4
|
"description": "Rules of Stylelint for D-ZERO",
|
|
5
5
|
"repository": "https://github.com/d-zero-dev/linters.git",
|
|
6
6
|
"author": "D-ZERO Co., Ltd.",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"build": "tsc"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@d-zero/csstree-scss-syntax": "5.0.0-alpha.
|
|
23
|
+
"@d-zero/csstree-scss-syntax": "5.0.0-alpha.15",
|
|
24
24
|
"css-tree": "2.3.1",
|
|
25
25
|
"postcss-value-parser": "4.2.0",
|
|
26
26
|
"stylelint": "16.2.1"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "0a6a1f910f3ca2802a5e7cfee9bc00a67889d24e"
|
|
29
29
|
}
|