@d-zero/stylelint-rules 5.0.0-alpha.44 → 5.0.0-alpha.46

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,7 +1,5 @@
1
1
  import stylelint from 'stylelint';
2
2
  // @ts-ignore
3
- import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.mjs';
4
- // @ts-ignore
5
3
  import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp.mjs';
6
4
  // @ts-ignore
7
5
  import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps.mjs';
@@ -58,18 +56,20 @@ export default createRule({
58
56
  if (checkList.length === 0) {
59
57
  continue;
60
58
  }
61
- const index = declarationValueIndex(decl) + node.value.sourceIndex;
62
- const endIndex = index + node.value.sourceEndIndex;
63
59
  const raw = decl.value.slice(node.value.sourceIndex, node.value.sourceIndex + node.value.sourceEndIndex);
64
- if (matchesStringOrRegExp(raw, checkList)) {
60
+ const matched = matchesStringOrRegExp(raw, checkList);
61
+ if (matched) {
62
+ const word = matched.substring;
63
+ const index = raw.indexOf(word);
64
+ const endIndex = index + word.length;
65
65
  stylelint.utils.report({
66
66
  result,
67
67
  ruleName,
68
- message: messages.rejected(raw, node.valueType),
68
+ message: messages.rejected(word, node.valueType),
69
69
  node: decl,
70
70
  index,
71
71
  endIndex,
72
- word: raw,
72
+ word,
73
73
  });
74
74
  }
75
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-zero/stylelint-rules",
3
- "version": "5.0.0-alpha.44",
3
+ "version": "5.0.0-alpha.46",
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.",
@@ -23,14 +23,14 @@
23
23
  "build": "tsc"
24
24
  },
25
25
  "dependencies": {
26
- "@d-zero/csstree-scss-syntax": "5.0.0-alpha.44",
26
+ "@d-zero/csstree-scss-syntax": "5.0.0-alpha.46",
27
27
  "css-tree": "3.0.0",
28
28
  "postcss-selector-parser": "6.1.2",
29
29
  "postcss-value-parser": "4.2.0",
30
- "stylelint": "16.9.0"
30
+ "stylelint": "16.10.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "postcss": "8.4.47"
34
34
  },
35
- "gitHead": "fcadd685a6165140bb87e436b7efc7f726c0f5cc"
35
+ "gitHead": "28f597b01f64efbb1ebb77f28b67e1d9f48bb779"
36
36
  }
@@ -1,40 +0,0 @@
1
- import stylelint from 'stylelint';
2
- import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.mjs';
3
-
4
- import { getValueType } from '../../utils/get-value-type.js';
5
- const { createPlugin, utils: { report, ruleMessages }, } = stylelint;
6
- const ruleName = 'd-zero/length';
7
- const messages = ruleMessages(ruleName, {
8
- rejected: (value) => `Unexpected length value "${value}"`,
9
- });
10
- const meta = {
11
- url: 'https://github.com/d-zero-dev/linters/tree/main/packages/%40d-zero/stylelint-rules',
12
- };
13
- const ruleFunction = () => {
14
- return (root, result) => {
15
- root.walkDecls((decl) => {
16
- const nodes = getValueType(decl);
17
- for (const node of nodes) {
18
- if (node.valueType === 'length') {
19
- console.log(node.valueType, node);
20
- const index = declarationValueIndex(decl) + node.value.sourceIndex;
21
- const endIndex = index + node.value.sourceEndIndex;
22
- const raw = decl.value.slice(node.value.sourceIndex, node.value.sourceIndex + node.value.sourceEndIndex);
23
- report({
24
- result,
25
- ruleName,
26
- message: messages.rejected(raw),
27
- node: decl,
28
- index,
29
- endIndex,
30
- word: raw,
31
- });
32
- }
33
- }
34
- });
35
- };
36
- };
37
- ruleFunction.ruleName = ruleName;
38
- ruleFunction.messages = messages;
39
- ruleFunction.meta = meta;
40
- export default createPlugin(ruleName, ruleFunction);
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- import stylelint from 'stylelint';
2
- // @ts-ignore
3
- import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.mjs';
4
- // @ts-ignore
5
- import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp.mjs';
6
- // @ts-ignore
7
- import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps.mjs';
8
- // @ts-ignore
9
- import validateOptions from 'stylelint/lib/utils/validateOptions.mjs';
10
- // @ts-ignore
11
- import { isString } from 'stylelint/lib/utils/validateTypes.mjs';
12
-
13
- import { createRule } from '../../utils/create-rule.js';
14
- import { getValueType } from '../../utils/get-value-type.js';
15
- export default createRule({
16
- name: 'length-pattern',
17
- rejected: (value) => `Unexpected value "${value}"`,
18
- rule: (ruleName, messages) => (primary) => {
19
- return (root, result) => {
20
- const validOptions = validateOptions(result, ruleName, {
21
- actual: primary,
22
- possible: [validateObjectWithArrayProps(isString)],
23
- });
24
- if (!validOptions) {
25
- return;
26
- }
27
- const options = Object.entries(primary);
28
- if (options.length === 0) {
29
- return;
30
- }
31
- root.walkDecls((decl) => {
32
- const nodes = getValueType(decl);
33
- for (const node of nodes) {
34
- const checkList = options
35
- .filter(([key]) => matchesStringOrRegExp(node.valueType, key))
36
- .flatMap(([, value]) => value);
37
- if (checkList.length === 0) {
38
- continue;
39
- }
40
- const index = declarationValueIndex(decl) + node.value.sourceIndex;
41
- const endIndex = index + node.value.sourceEndIndex;
42
- const raw = decl.value.slice(node.value.sourceIndex, node.value.sourceIndex + node.value.sourceEndIndex);
43
- if (matchesStringOrRegExp(raw, checkList)) {
44
- continue;
45
- }
46
- stylelint.utils.report({
47
- result,
48
- ruleName,
49
- message: messages.rejected(raw),
50
- node: decl,
51
- index,
52
- endIndex,
53
- word: raw,
54
- });
55
- }
56
- });
57
- };
58
- },
59
- });
@@ -1,36 +0,0 @@
1
- import stylelint from 'stylelint';
2
- import { describe, test, expect } from 'vitest';
3
-
4
- import rule from './index.js';
5
- const { lint } = stylelint;
6
- const config = (settings = true) => ({
7
- plugins: [rule],
8
- rules: {
9
- // @ts-ignore
10
- [rule.ruleName]: settings,
11
- },
12
- });
13
- describe('length-pattern', () => {
14
- test('length in flex', async () => {
15
- const {
16
- // @ts-ignore
17
- results: [{ warnings, parseErrors }], } = await lint({
18
- code: '* { flex: 1 1 10px }',
19
- config: config({
20
- length: ['30px'],
21
- }),
22
- });
23
- expect(parseErrors).toHaveLength(0);
24
- expect(warnings).toStrictEqual([
25
- {
26
- rule: '@d-zero/length-pattern',
27
- severity: 'error',
28
- line: 1,
29
- endLine: 1,
30
- column: 15,
31
- endColumn: 19,
32
- text: 'Unexpected value "10px" (@d-zero/length-pattern)',
33
- },
34
- ]);
35
- });
36
- });
@@ -1,59 +0,0 @@
1
- import stylelint from 'stylelint';
2
- // @ts-ignore
3
- import declarationValueIndex from 'stylelint/lib/utils/declarationValueIndex.mjs';
4
- // @ts-ignore
5
- import matchesStringOrRegExp from 'stylelint/lib/utils/matchesStringOrRegExp.mjs';
6
- // @ts-ignore
7
- import validateObjectWithArrayProps from 'stylelint/lib/utils/validateObjectWithArrayProps.mjs';
8
- // @ts-ignore
9
- import validateOptions from 'stylelint/lib/utils/validateOptions.mjs';
10
- // @ts-ignore
11
- import { isString } from 'stylelint/lib/utils/validateTypes.mjs';
12
-
13
- import { createRule } from '../../utils/create-rule.js';
14
- import { getValueType } from '../../utils/get-value-type.js';
15
- export default createRule({
16
- name: 'value-pattern-on-type',
17
- rejected: (value) => `Unexpected value "${value}"`,
18
- rule: (ruleName, messages) => (primary) => {
19
- return (root, result) => {
20
- const validOptions = validateOptions(result, ruleName, {
21
- actual: primary,
22
- possible: [validateObjectWithArrayProps(isString)],
23
- });
24
- if (!validOptions) {
25
- return;
26
- }
27
- const options = Object.entries(primary);
28
- if (options.length === 0) {
29
- return;
30
- }
31
- root.walkDecls((decl) => {
32
- const nodes = getValueType(decl);
33
- for (const node of nodes) {
34
- const checkList = options
35
- .filter(([key]) => matchesStringOrRegExp(node.valueType, key))
36
- .flatMap(([, value]) => value);
37
- if (checkList.length === 0) {
38
- continue;
39
- }
40
- const index = declarationValueIndex(decl) + node.value.sourceIndex;
41
- const endIndex = index + node.value.sourceEndIndex;
42
- const raw = decl.value.slice(node.value.sourceIndex, node.value.sourceIndex + node.value.sourceEndIndex);
43
- if (matchesStringOrRegExp(raw, checkList)) {
44
- continue;
45
- }
46
- stylelint.utils.report({
47
- result,
48
- ruleName,
49
- message: messages.rejected(raw),
50
- node: decl,
51
- index,
52
- endIndex,
53
- word: raw,
54
- });
55
- }
56
- });
57
- };
58
- },
59
- });
@@ -1,36 +0,0 @@
1
- import stylelint from 'stylelint';
2
- import { describe, test, expect } from 'vitest';
3
-
4
- import rule from './index.js';
5
- const { lint } = stylelint;
6
- const config = (settings = true) => ({
7
- plugins: [rule],
8
- rules: {
9
- // @ts-ignore
10
- [rule.ruleName]: settings,
11
- },
12
- });
13
- describe('length-pattern', () => {
14
- test('length in flex', async () => {
15
- const {
16
- // @ts-ignore
17
- results: [{ warnings, parseErrors }], } = await lint({
18
- code: '* { flex: 1 1 10px }',
19
- config: config({
20
- length: ['30px'],
21
- }),
22
- });
23
- expect(parseErrors).toHaveLength(0);
24
- expect(warnings).toStrictEqual([
25
- {
26
- rule: '@d-zero/value-pattern-on-type',
27
- severity: 'error',
28
- line: 1,
29
- endLine: 1,
30
- column: 15,
31
- endColumn: 19,
32
- text: 'Unexpected value "10px" (@d-zero/value-pattern-on-type)',
33
- },
34
- ]);
35
- });
36
- });