@d-zero/stylelint-rules 5.0.0-alpha.14 → 5.0.0-alpha.16

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.
@@ -19,31 +19,38 @@ function _getValueType(prop, value) {
19
19
  if (props === null) {
20
20
  return null;
21
21
  }
22
- const valueTypes = props.match.map((node) => getValueNode(node).syntax.name);
22
+ const valueTypes = props.match
23
+ .flatMap((node) => getValueNode(node))
24
+ .map((node) => node.syntax.name);
23
25
  return values.map((value, i) => {
24
26
  const valueType = valueTypes[i] ?? null;
25
- if (valueType === null) {
26
- if (value.type === 'word' && value.value.startsWith('$')) {
27
- return {
28
- value: value,
29
- valueType: '$SASS_VARIABLE',
30
- };
31
- }
32
- 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
+ };
33
32
  }
34
33
  return {
35
34
  value,
36
- valueType,
35
+ valueType: valueType ?? 'unknown',
37
36
  };
38
37
  });
39
38
  }
40
39
  function getValueNode(node) {
41
- if (isProperty(node)) {
42
- const firstChild = node.match.at(0);
43
- return getValueNode(firstChild);
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));
44
48
  }
45
- return node;
49
+ return [node];
46
50
  }
47
51
  function isProperty(node) {
48
- return node.syntax.type === 'Property';
52
+ return node.syntax?.type === 'Property';
53
+ }
54
+ function isType(node) {
55
+ return node.syntax?.type === 'Type';
49
56
  }
@@ -22,6 +22,15 @@ 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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/stylelint-rules",
3
- "version": "5.0.0-alpha.14",
3
+ "version": "5.0.0-alpha.16",
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.14",
23
+ "@d-zero/csstree-scss-syntax": "5.0.0-alpha.16",
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": "9ba13d8a3153a50f989d9a32fdddec4c43fbb8fa"
28
+ "gitHead": "baddf6a71360a679cb0e418d791daab1605e710f"
29
29
  }