@master/eslint-plugin-css 2.0.0-rc.61 → 2.0.0-rc.63

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.
Files changed (52) hide show
  1. package/dist/common.cjs +7 -0
  2. package/dist/common.d.ts +2 -0
  3. package/dist/common.mjs +4 -0
  4. package/dist/create-rule.cjs +1 -1
  5. package/dist/create-rule.mjs +1 -1
  6. package/dist/functions/filter-collision-classes.cjs +1 -1
  7. package/dist/functions/filter-collision-classes.mjs +2 -2
  8. package/dist/rules/class-collision.cjs +44 -38
  9. package/dist/rules/class-collision.mjs +44 -38
  10. package/dist/rules/class-order.cjs +23 -134
  11. package/dist/rules/class-order.mjs +24 -135
  12. package/dist/rules/class-validation.cjs +26 -37
  13. package/dist/rules/class-validation.mjs +26 -37
  14. package/dist/utils/define-visitors.cjs +24 -25
  15. package/dist/utils/define-visitors.d.ts +2 -1
  16. package/dist/utils/define-visitors.mjs +24 -25
  17. package/dist/utils/resolve-class-node.cjs +144 -0
  18. package/dist/utils/resolve-class-node.d.ts +12 -0
  19. package/dist/utils/resolve-class-node.mjs +142 -0
  20. package/dist/utils/resolve-context.cjs +6 -2
  21. package/dist/utils/resolve-context.mjs +6 -2
  22. package/dist/utils/with-visit-class-node.cjs +56 -0
  23. package/dist/utils/with-visit-class-node.d.ts +4 -0
  24. package/dist/utils/with-visit-class-node.mjs +54 -0
  25. package/package.json +1 -1
  26. package/dist/utils/extract-classnames-from-value.cjs +0 -34
  27. package/dist/utils/extract-classnames-from-value.d.ts +0 -6
  28. package/dist/utils/extract-classnames-from-value.mjs +0 -32
  29. package/dist/utils/extract-range-from-node.cjs +0 -18
  30. package/dist/utils/extract-range-from-node.d.ts +0 -1
  31. package/dist/utils/extract-range-from-node.mjs +0 -16
  32. package/dist/utils/extract-value-from-node.cjs +0 -23
  33. package/dist/utils/extract-value-from-node.d.ts +0 -1
  34. package/dist/utils/extract-value-from-node.mjs +0 -21
  35. package/dist/utils/find-loc.cjs +0 -51
  36. package/dist/utils/find-loc.d.ts +0 -7
  37. package/dist/utils/find-loc.mjs +0 -49
  38. package/dist/utils/get-template-element-body.cjs +0 -12
  39. package/dist/utils/get-template-element-body.d.ts +0 -1
  40. package/dist/utils/get-template-element-body.mjs +0 -10
  41. package/dist/utils/get-template-element-prefix.cjs +0 -11
  42. package/dist/utils/get-template-element-prefix.d.ts +0 -1
  43. package/dist/utils/get-template-element-prefix.mjs +0 -9
  44. package/dist/utils/get-template-element-suffix.cjs +0 -10
  45. package/dist/utils/get-template-element-suffix.d.ts +0 -1
  46. package/dist/utils/get-template-element-suffix.mjs +0 -8
  47. package/dist/utils/index-of-all.cjs +0 -12
  48. package/dist/utils/index-of-all.d.ts +0 -1
  49. package/dist/utils/index-of-all.mjs +0 -10
  50. package/dist/utils/parse-node-recursive.cjs +0 -129
  51. package/dist/utils/parse-node-recursive.d.ts +0 -13
  52. package/dist/utils/parse-node-recursive.mjs +0 -127
@@ -1,129 +0,0 @@
1
- 'use strict';
2
-
3
- var getTemplateElementPrefix = require('./get-template-element-prefix.cjs');
4
- var getTemplateElementSuffix = require('./get-template-element-suffix.cjs');
5
- var extractValueFromNode = require('./extract-value-from-node.cjs');
6
- var extractClassnamesFromValue = require('./extract-classnames-from-value.cjs');
7
- var extractRangeFromNode = require('./extract-range-from-node.cjs');
8
-
9
- /**
10
- * Inspect and parse an abstract syntax node and run a callback function
11
- *
12
- * @param {ASTNode} rootNode The current root node being parsed by eslint
13
- * @param {ASTNode} childNode The AST node child argument being checked
14
- * @param {Function} cb The callback function
15
- * @param {Boolean} skipConditional Optional, indicate distinct parsing for conditional nodes
16
- * @param {Boolean} isolate Optional, set internally to isolate parsing and validation on conditional children
17
- * @param {Array} ignoredKeys Optional, set object keys which should not be parsed e.g. for `cva`
18
- * @returns {void}
19
- */ function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, isolate = false, ignoredKeys = [], context) {
20
- // TODO allow vue non litteral
21
- let originalClassNamesValue;
22
- let classNames;
23
- let start = null;
24
- let end = null;
25
- let prefix = '';
26
- let suffix = '';
27
- if (childNode === null) {
28
- originalClassNamesValue = extractValueFromNode(rootNode);
29
- ({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
30
- classNames = [
31
- ...new Set(classNames)
32
- ];
33
- if (classNames.length === 0) {
34
- // Don't run for empty className
35
- return;
36
- }
37
- const range = extractRangeFromNode(rootNode);
38
- if (rootNode.type === 'TextAttribute') {
39
- start = range[0];
40
- end = range[1];
41
- } else {
42
- start = range[0] + 1;
43
- end = range[1] - 1;
44
- }
45
- cb(classNames, rootNode, originalClassNamesValue, start, end, prefix, suffix);
46
- } else if (childNode === undefined) {
47
- // Ignore invalid child candidates (probably inside complex TemplateLiteral)
48
- return;
49
- } else {
50
- const forceIsolation = skipConditional ? true : isolate;
51
- let expStrings = [];
52
- switch(childNode.type){
53
- case 'TemplateLiteral':
54
- childNode.expressions.forEach((exp)=>{
55
- parseNodeRecursive(rootNode, exp, cb, skipConditional, forceIsolation, ignoredKeys, context);
56
- });
57
- const sourceCode = context.sourceCode;
58
- originalClassNamesValue = sourceCode.getText(childNode);
59
- originalClassNamesValue = originalClassNamesValue.substring(1, originalClassNamesValue.length - 1);
60
- expStrings = originalClassNamesValue.match(/\$\{(?:(?<!\\\\)(['"`]).*?(?<!\\\\)\1|[^}])*?\}/g) ?? [];
61
- for(let i = 0; i < expStrings.length; i++){
62
- originalClassNamesValue = originalClassNamesValue.replace(expStrings[i], `EXPRESSION_STRING_NUM_${i}`);
63
- }
64
- break;
65
- case 'ConditionalExpression':
66
- parseNodeRecursive(rootNode, childNode.consequent, cb, skipConditional, forceIsolation, ignoredKeys, context);
67
- parseNodeRecursive(rootNode, childNode.alternate, cb, skipConditional, forceIsolation, ignoredKeys, context);
68
- return;
69
- case 'LogicalExpression':
70
- parseNodeRecursive(rootNode, childNode.right, cb, skipConditional, forceIsolation, ignoredKeys, context);
71
- return;
72
- case 'ArrayExpression':
73
- childNode.elements.forEach((el)=>{
74
- parseNodeRecursive(rootNode, el, cb, skipConditional, forceIsolation, ignoredKeys, context);
75
- });
76
- return;
77
- case 'ObjectExpression':
78
- childNode.properties.forEach((prop)=>{
79
- const isUsedByClassNamesPlugin = rootNode.callee && rootNode.callee.name === 'classnames';
80
- if (prop.type === 'SpreadElement') {
81
- // Ignore spread elements
82
- return;
83
- }
84
- if (prop.key.type === 'Identifier' && ignoredKeys.includes(prop.key.name)) {
85
- // Ignore specific keys defined in settings
86
- return;
87
- }
88
- parseNodeRecursive(prop, isUsedByClassNamesPlugin ? prop.key : prop.value, cb, skipConditional, forceIsolation, ignoredKeys, context);
89
- });
90
- return;
91
- case 'Property':
92
- parseNodeRecursive(rootNode, childNode.key, cb, skipConditional, forceIsolation, ignoredKeys, context);
93
- return;
94
- case 'Literal':
95
- originalClassNamesValue = childNode.value;
96
- start = childNode.range[0] + 1;
97
- end = childNode.range[1] - 1;
98
- break;
99
- case 'SvelteLiteral':
100
- originalClassNamesValue = childNode.value;
101
- start = childNode.range[0];
102
- end = childNode.range[1];
103
- break;
104
- case 'TemplateElement':
105
- originalClassNamesValue = childNode.value.raw;
106
- start = childNode.range[0];
107
- end = childNode.range[1];
108
- const txt = context?.sourceCode.getText(childNode) ?? '';
109
- prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
110
- suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
111
- break;
112
- }
113
- for(let i = 0; i < expStrings.length; i++){
114
- originalClassNamesValue = originalClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
115
- }
116
- ({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
117
- classNames = [
118
- ...new Set(classNames)
119
- ];
120
- if (classNames.length === 0) {
121
- // Don't run for empty className
122
- return;
123
- }
124
- const targetNode = isolate ? null : rootNode;
125
- cb(classNames, targetNode, originalClassNamesValue, start, end, prefix, suffix);
126
- }
127
- }
128
-
129
- exports.parseNodeRecursive = parseNodeRecursive;
@@ -1,13 +0,0 @@
1
- import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
2
- /**
3
- * Inspect and parse an abstract syntax node and run a callback function
4
- *
5
- * @param {ASTNode} rootNode The current root node being parsed by eslint
6
- * @param {ASTNode} childNode The AST node child argument being checked
7
- * @param {Function} cb The callback function
8
- * @param {Boolean} skipConditional Optional, indicate distinct parsing for conditional nodes
9
- * @param {Boolean} isolate Optional, set internally to isolate parsing and validation on conditional children
10
- * @param {Array} ignoredKeys Optional, set object keys which should not be parsed e.g. for `cva`
11
- * @returns {void}
12
- */
13
- export declare function parseNodeRecursive(rootNode: any, childNode: any, cb: any, skipConditional: boolean, isolate: boolean, ignoredKeys: any[], context: RuleContext<any, any>): void;
@@ -1,127 +0,0 @@
1
- import getTemplateElementPrefix from './get-template-element-prefix.mjs';
2
- import getTemplateElementSuffix from './get-template-element-suffix.mjs';
3
- import extractValueFromNode from './extract-value-from-node.mjs';
4
- import extractClassnamesFromValue from './extract-classnames-from-value.mjs';
5
- import extractRangeFromNode from './extract-range-from-node.mjs';
6
-
7
- /**
8
- * Inspect and parse an abstract syntax node and run a callback function
9
- *
10
- * @param {ASTNode} rootNode The current root node being parsed by eslint
11
- * @param {ASTNode} childNode The AST node child argument being checked
12
- * @param {Function} cb The callback function
13
- * @param {Boolean} skipConditional Optional, indicate distinct parsing for conditional nodes
14
- * @param {Boolean} isolate Optional, set internally to isolate parsing and validation on conditional children
15
- * @param {Array} ignoredKeys Optional, set object keys which should not be parsed e.g. for `cva`
16
- * @returns {void}
17
- */ function parseNodeRecursive(rootNode, childNode, cb, skipConditional = false, isolate = false, ignoredKeys = [], context) {
18
- // TODO allow vue non litteral
19
- let originalClassNamesValue;
20
- let classNames;
21
- let start = null;
22
- let end = null;
23
- let prefix = '';
24
- let suffix = '';
25
- if (childNode === null) {
26
- originalClassNamesValue = extractValueFromNode(rootNode);
27
- ({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
28
- classNames = [
29
- ...new Set(classNames)
30
- ];
31
- if (classNames.length === 0) {
32
- // Don't run for empty className
33
- return;
34
- }
35
- const range = extractRangeFromNode(rootNode);
36
- if (rootNode.type === 'TextAttribute') {
37
- start = range[0];
38
- end = range[1];
39
- } else {
40
- start = range[0] + 1;
41
- end = range[1] - 1;
42
- }
43
- cb(classNames, rootNode, originalClassNamesValue, start, end, prefix, suffix);
44
- } else if (childNode === undefined) {
45
- // Ignore invalid child candidates (probably inside complex TemplateLiteral)
46
- return;
47
- } else {
48
- const forceIsolation = skipConditional ? true : isolate;
49
- let expStrings = [];
50
- switch(childNode.type){
51
- case 'TemplateLiteral':
52
- childNode.expressions.forEach((exp)=>{
53
- parseNodeRecursive(rootNode, exp, cb, skipConditional, forceIsolation, ignoredKeys, context);
54
- });
55
- const sourceCode = context.sourceCode;
56
- originalClassNamesValue = sourceCode.getText(childNode);
57
- originalClassNamesValue = originalClassNamesValue.substring(1, originalClassNamesValue.length - 1);
58
- expStrings = originalClassNamesValue.match(/\$\{(?:(?<!\\\\)(['"`]).*?(?<!\\\\)\1|[^}])*?\}/g) ?? [];
59
- for(let i = 0; i < expStrings.length; i++){
60
- originalClassNamesValue = originalClassNamesValue.replace(expStrings[i], `EXPRESSION_STRING_NUM_${i}`);
61
- }
62
- break;
63
- case 'ConditionalExpression':
64
- parseNodeRecursive(rootNode, childNode.consequent, cb, skipConditional, forceIsolation, ignoredKeys, context);
65
- parseNodeRecursive(rootNode, childNode.alternate, cb, skipConditional, forceIsolation, ignoredKeys, context);
66
- return;
67
- case 'LogicalExpression':
68
- parseNodeRecursive(rootNode, childNode.right, cb, skipConditional, forceIsolation, ignoredKeys, context);
69
- return;
70
- case 'ArrayExpression':
71
- childNode.elements.forEach((el)=>{
72
- parseNodeRecursive(rootNode, el, cb, skipConditional, forceIsolation, ignoredKeys, context);
73
- });
74
- return;
75
- case 'ObjectExpression':
76
- childNode.properties.forEach((prop)=>{
77
- const isUsedByClassNamesPlugin = rootNode.callee && rootNode.callee.name === 'classnames';
78
- if (prop.type === 'SpreadElement') {
79
- // Ignore spread elements
80
- return;
81
- }
82
- if (prop.key.type === 'Identifier' && ignoredKeys.includes(prop.key.name)) {
83
- // Ignore specific keys defined in settings
84
- return;
85
- }
86
- parseNodeRecursive(prop, isUsedByClassNamesPlugin ? prop.key : prop.value, cb, skipConditional, forceIsolation, ignoredKeys, context);
87
- });
88
- return;
89
- case 'Property':
90
- parseNodeRecursive(rootNode, childNode.key, cb, skipConditional, forceIsolation, ignoredKeys, context);
91
- return;
92
- case 'Literal':
93
- originalClassNamesValue = childNode.value;
94
- start = childNode.range[0] + 1;
95
- end = childNode.range[1] - 1;
96
- break;
97
- case 'SvelteLiteral':
98
- originalClassNamesValue = childNode.value;
99
- start = childNode.range[0];
100
- end = childNode.range[1];
101
- break;
102
- case 'TemplateElement':
103
- originalClassNamesValue = childNode.value.raw;
104
- start = childNode.range[0];
105
- end = childNode.range[1];
106
- const txt = context?.sourceCode.getText(childNode) ?? '';
107
- prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
108
- suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
109
- break;
110
- }
111
- for(let i = 0; i < expStrings.length; i++){
112
- originalClassNamesValue = originalClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
113
- }
114
- ({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
115
- classNames = [
116
- ...new Set(classNames)
117
- ];
118
- if (classNames.length === 0) {
119
- // Don't run for empty className
120
- return;
121
- }
122
- const targetNode = isolate ? null : rootNode;
123
- cb(classNames, targetNode, originalClassNamesValue, start, end, prefix, suffix);
124
- }
125
- }
126
-
127
- export { parseNodeRecursive };