@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.
@@ -34,6 +34,9 @@ export default createRule({
34
34
  }
35
35
  root.walkDecls((decl) => {
36
36
  const nodes = getValueType(decl);
37
+ if (nodes === null) {
38
+ return;
39
+ }
37
40
  for (const node of nodes) {
38
41
  if (!node.valueType) {
39
42
  continue;
@@ -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
- throw cssTreeDecl.error;
20
+ return null;
18
21
  }
19
- 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);
20
25
  return values.map((value, i) => {
21
26
  const valueType = valueTypes[i] ?? null;
22
- if (valueType === null) {
23
- if (value.type === 'word' && value.value.startsWith('$')) {
24
- return {
25
- value: value,
26
- valueType: '$SASS_VARIABLE',
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
- const firstChild = node.match.at(0);
40
- 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));
41
48
  }
42
- return node;
49
+ return [node];
43
50
  }
44
51
  function isProperty(node) {
45
- return node.syntax.type === 'Property';
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.map((node) => node.valueType);
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.13",
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.13",
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": "a68c1dad34f200e966c4003f53b7b072bbea7900"
28
+ "gitHead": "0a6a1f910f3ca2802a5e7cfee9bc00a67889d24e"
29
29
  }