@master/eslint-plugin-css 2.0.0-rc.5 → 2.0.0-rc.50

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 (112) hide show
  1. package/README.md +2 -2
  2. package/dist/configs/base.cjs +11 -0
  3. package/dist/configs/base.d.ts +3 -0
  4. package/dist/configs/base.mjs +9 -0
  5. package/dist/configs/legacy.cjs +17 -0
  6. package/dist/configs/legacy.d.ts +3 -0
  7. package/dist/configs/legacy.mjs +15 -0
  8. package/dist/configs/recommended.cjs +14 -0
  9. package/dist/configs/recommended.d.ts +2 -13
  10. package/dist/configs/recommended.mjs +12 -1
  11. package/dist/create-rule.cjs +8 -0
  12. package/dist/create-rule.d.ts +3 -0
  13. package/dist/create-rule.mjs +6 -0
  14. package/dist/functions/filter-collision-classes.cjs +29 -0
  15. package/dist/functions/filter-collision-classes.d.ts +2 -0
  16. package/dist/functions/filter-collision-classes.mjs +27 -0
  17. package/dist/index.cjs +19 -0
  18. package/dist/index.d.ts +19 -1
  19. package/dist/index.mjs +17 -1
  20. package/dist/plugin.cjs +26 -0
  21. package/dist/plugin.d.ts +2 -2
  22. package/dist/plugin.mjs +23 -1
  23. package/dist/rules/class-collision.cjs +70 -0
  24. package/dist/rules/class-collision.d.ts +1 -2
  25. package/dist/rules/class-collision.mjs +68 -1
  26. package/dist/rules/class-order.cjs +175 -0
  27. package/dist/rules/class-order.d.ts +1 -2
  28. package/dist/rules/class-order.mjs +173 -1
  29. package/dist/rules/class-validation.cjs +71 -0
  30. package/dist/rules/class-validation.d.ts +1 -2
  31. package/dist/rules/class-validation.mjs +69 -1
  32. package/dist/settings-schema.cjs +35 -0
  33. package/dist/settings-schema.d.ts +3 -0
  34. package/dist/settings-schema.mjs +33 -0
  35. package/dist/settings.cjs +16 -0
  36. package/dist/settings.d.ts +10 -2
  37. package/dist/settings.mjs +14 -1
  38. package/dist/utils/define-visitors.cjs +92 -0
  39. package/dist/utils/define-visitors.d.ts +6 -4
  40. package/dist/utils/define-visitors.mjs +90 -1
  41. package/dist/utils/extract-classnames-from-value.cjs +34 -0
  42. package/dist/utils/extract-classnames-from-value.mjs +32 -1
  43. package/dist/utils/extract-range-from-node.cjs +18 -0
  44. package/dist/utils/extract-range-from-node.mjs +16 -1
  45. package/dist/utils/extract-value-from-node.cjs +23 -0
  46. package/dist/utils/extract-value-from-node.mjs +21 -1
  47. package/dist/utils/find-loc.cjs +51 -0
  48. package/dist/utils/find-loc.d.ts +1 -1
  49. package/dist/utils/find-loc.mjs +49 -1
  50. package/dist/utils/get-template-element-body.cjs +12 -0
  51. package/dist/utils/get-template-element-body.mjs +10 -1
  52. package/dist/utils/get-template-element-prefix.cjs +11 -0
  53. package/dist/utils/get-template-element-prefix.mjs +9 -1
  54. package/dist/utils/get-template-element-suffix.cjs +10 -0
  55. package/dist/utils/get-template-element-suffix.mjs +8 -1
  56. package/dist/utils/index-of-all.cjs +12 -0
  57. package/dist/utils/index-of-all.d.ts +1 -0
  58. package/dist/utils/index-of-all.mjs +10 -0
  59. package/dist/utils/parse-node-recursive.cjs +129 -0
  60. package/dist/utils/parse-node-recursive.d.ts +2 -2
  61. package/dist/utils/parse-node-recursive.mjs +127 -1
  62. package/dist/utils/resolve-context.cjs +36 -0
  63. package/dist/utils/resolve-context.d.ts +11 -2
  64. package/dist/utils/resolve-context.mjs +34 -1
  65. package/package.json +1 -1
  66. package/dist/configs/config.d.ts +0 -13
  67. package/dist/configs/config.js +0 -1
  68. package/dist/configs/config.mjs +0 -1
  69. package/dist/configs/flat.d.ts +0 -16
  70. package/dist/configs/flat.js +0 -1
  71. package/dist/configs/flat.mjs +0 -1
  72. package/dist/configs/recommended.js +0 -1
  73. package/dist/index.js +0 -1
  74. package/dist/plugin.js +0 -1
  75. package/dist/rules/class-collision.js +0 -1
  76. package/dist/rules/class-order.js +0 -1
  77. package/dist/rules/class-validation.js +0 -1
  78. package/dist/settings.js +0 -1
  79. package/dist/utils/are-declarations-equal.d.ts +0 -1
  80. package/dist/utils/are-declarations-equal.js +0 -1
  81. package/dist/utils/are-declarations-equal.mjs +0 -1
  82. package/dist/utils/define-visitors.js +0 -1
  83. package/dist/utils/extract-classnames-from-value.js +0 -1
  84. package/dist/utils/extract-range-from-node.js +0 -1
  85. package/dist/utils/extract-value-from-node.js +0 -1
  86. package/dist/utils/find-loc.js +0 -1
  87. package/dist/utils/get-mastercss.d.ts +0 -2
  88. package/dist/utils/get-mastercss.js +0 -1
  89. package/dist/utils/get-mastercss.mjs +0 -1
  90. package/dist/utils/get-template-element-body.js +0 -1
  91. package/dist/utils/get-template-element-prefix.js +0 -1
  92. package/dist/utils/get-template-element-suffix.js +0 -1
  93. package/dist/utils/parse-node-recursive.js +0 -1
  94. package/dist/utils/reorder-valid-classes-action.d.ts +0 -3
  95. package/dist/utils/reorder-valid-classes-action.js +0 -1
  96. package/dist/utils/reorder-valid-classes-action.mjs +0 -1
  97. package/dist/utils/resolve-context.js +0 -1
  98. package/dist/utils/valid-rules-action.d.ts +0 -3
  99. package/dist/utils/valid-rules-action.js +0 -1
  100. package/dist/utils/valid-rules-action.mjs +0 -1
  101. package/dist/utils/validate-action.d.ts +0 -3
  102. package/dist/utils/validate-action.js +0 -1
  103. package/dist/utils/validate-action.mjs +0 -1
  104. package/dist/utils/workers/reorder-valid-classes.d.ts +0 -2
  105. package/dist/utils/workers/reorder-valid-classes.js +0 -1
  106. package/dist/utils/workers/reorder-valid-classes.mjs +0 -1
  107. package/dist/utils/workers/valid-rules.d.ts +0 -2
  108. package/dist/utils/workers/valid-rules.js +0 -1
  109. package/dist/utils/workers/valid-rules.mjs +0 -1
  110. package/dist/utils/workers/validate.d.ts +0 -5
  111. package/dist/utils/workers/validate.js +0 -1
  112. package/dist/utils/workers/validate.mjs +0 -1
@@ -0,0 +1,175 @@
1
+ 'use strict';
2
+
3
+ var defineVisitors = require('../utils/define-visitors.cjs');
4
+ var resolveContext = require('../utils/resolve-context.cjs');
5
+ var getTemplateElementBody = require('../utils/get-template-element-body.cjs');
6
+ var getTemplateElementSuffix = require('../utils/get-template-element-suffix.cjs');
7
+ var getTemplateElementPrefix = require('../utils/get-template-element-prefix.cjs');
8
+ var extractValueFromNode = require('../utils/extract-value-from-node.cjs');
9
+ var extractRangeFromNode = require('../utils/extract-range-from-node.cjs');
10
+ var extractClassnamesFromValue = require('../utils/extract-classnames-from-value.cjs');
11
+ var findLoc = require('../utils/find-loc.cjs');
12
+ var createRule = require('../create-rule.cjs');
13
+ var settingsSchema = require('../settings-schema.cjs');
14
+ var css = require('@master/css');
15
+
16
+ var classOrder = createRule({
17
+ name: 'consistent-class-order',
18
+ meta: {
19
+ type: 'layout',
20
+ fixable: 'code',
21
+ docs: {
22
+ description: 'Enforce a consistent and logical order of classes'
23
+ },
24
+ messages: {
25
+ invalidClassOrder: 'No consistent class order followed.'
26
+ },
27
+ schema: [
28
+ settingsSchema
29
+ ]
30
+ },
31
+ defaultOptions: [],
32
+ create: function(context) {
33
+ const { settings, css: css$1 } = resolveContext(context);
34
+ const sourceCode = context.sourceCode;
35
+ const visitNode = (node, arg = null)=>{
36
+ let originalClassNamesValue = null;
37
+ let start = null;
38
+ let end = null;
39
+ let prefix = '';
40
+ let suffix = '';
41
+ let expStrings = [];
42
+ if (arg === null) {
43
+ originalClassNamesValue = extractValueFromNode(node);
44
+ const range = extractRangeFromNode(node);
45
+ if (node.type === 'TextAttribute') {
46
+ start = range[0];
47
+ end = range[1];
48
+ } else {
49
+ start = range[0] + 1;
50
+ end = range[1] - 1;
51
+ }
52
+ } else {
53
+ switch(arg.type){
54
+ case 'Identifier':
55
+ return;
56
+ case 'TemplateLiteral':
57
+ arg.expressions.forEach((exp)=>{
58
+ visitNode(node, exp);
59
+ });
60
+ originalClassNamesValue = sourceCode.getText(arg);
61
+ originalClassNamesValue = originalClassNamesValue.substring(1, originalClassNamesValue.length - 1);
62
+ expStrings = originalClassNamesValue.match(/\$\{(?:(?<!\\\\)(['"`]).*?(?<!\\\\)\1|[^}])*?\}/g) ?? [];
63
+ for(let i = 0; i < expStrings.length; i++){
64
+ originalClassNamesValue = originalClassNamesValue.replace(expStrings[i], `EXPRESSION_STRING_NUM_${i}`);
65
+ }
66
+ start = arg.range[0] + 1;
67
+ end = arg.range[1] - 1;
68
+ break;
69
+ case 'ConditionalExpression':
70
+ visitNode(node, arg.consequent);
71
+ visitNode(node, arg.alternate);
72
+ return;
73
+ case 'LogicalExpression':
74
+ visitNode(node, arg.right);
75
+ return;
76
+ case 'ArrayExpression':
77
+ arg.elements.forEach((el)=>{
78
+ visitNode(node, el);
79
+ });
80
+ return;
81
+ case 'ObjectExpression':
82
+ const isUsedByClassNamesPlugin = node.callee && node.callee.name === 'classnames';
83
+ const isVue = node.key && node.key.type === 'VDirectiveKey';
84
+ arg.properties.forEach((prop)=>{
85
+ const propVal = isUsedByClassNamesPlugin || isVue ? prop.key : prop.value;
86
+ visitNode(node, propVal);
87
+ });
88
+ return;
89
+ case 'Property':
90
+ visitNode(node, arg.key);
91
+ break;
92
+ case 'Literal':
93
+ originalClassNamesValue = arg.raw.slice(1, arg.raw.length - 1);
94
+ start = arg.range[0] + 1;
95
+ end = arg.range[1] - 1;
96
+ break;
97
+ case 'SvelteLiteral':
98
+ originalClassNamesValue = arg.value;
99
+ if (originalClassNamesValue === '') {
100
+ return;
101
+ }
102
+ start = arg.range[0];
103
+ end = arg.range[1];
104
+ break;
105
+ case 'TemplateElement':
106
+ originalClassNamesValue = arg.value.raw;
107
+ if (originalClassNamesValue === '') {
108
+ return;
109
+ }
110
+ start = arg.range[0];
111
+ end = arg.range[1];
112
+ // https://github.com/eslint/eslint/issues/13360
113
+ // The problem is that range computation includes the backticks (`test`)
114
+ // but value.raw does not include them, so there is a mismatch.
115
+ // start/end does not include the backticks, therefore it matches value.raw.
116
+ const txt = context.sourceCode.getText(arg);
117
+ prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
118
+ suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
119
+ originalClassNamesValue = getTemplateElementBody(txt, prefix, suffix);
120
+ break;
121
+ }
122
+ }
123
+ const { classNames, whitespaces, headSpace, tailSpace } = extractClassnamesFromValue(originalClassNamesValue);
124
+ if (classNames.length <= 1) {
125
+ // Don't run sorting for a single or empty className
126
+ return;
127
+ }
128
+ let orderedClassNames = css.reorderForReadableClasses(classNames, css$1).filter((eachOrderedClassName)=>classNames.includes(eachOrderedClassName));
129
+ orderedClassNames = classNames.filter((x)=>!orderedClassNames.includes(x)).concat(orderedClassNames).filter((x)=>x.trim() !== '');
130
+ // Generates the validated/sorted attribute value
131
+ let validatedClassNamesValue = '';
132
+ for(let i = 0; i < orderedClassNames.length; i++){
133
+ const w = whitespaces[i] ?? '';
134
+ const cls = orderedClassNames[i];
135
+ validatedClassNamesValue += headSpace ? `${w}${cls}` : `${cls}${w}`;
136
+ if (cls) {
137
+ if (!tailSpace && i === orderedClassNames.length - 1) {
138
+ validatedClassNamesValue = validatedClassNamesValue.replace(/\s+$/, '');
139
+ }
140
+ if (headSpace && tailSpace && i === orderedClassNames.length - 1) {
141
+ validatedClassNamesValue += whitespaces[whitespaces.length - 1] ?? '';
142
+ }
143
+ }
144
+ }
145
+ for(let i = 0; i < expStrings.length; i++){
146
+ originalClassNamesValue = originalClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
147
+ validatedClassNamesValue = validatedClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
148
+ }
149
+ if (originalClassNamesValue !== validatedClassNamesValue) {
150
+ validatedClassNamesValue = prefix + validatedClassNamesValue + suffix;
151
+ const sourceCodeLines = sourceCode.lines;
152
+ const nodeStartLine = node.loc.start.line;
153
+ const nodeStartColumn = node.loc.start.column;
154
+ const nodeEndLine = node.loc.end.line;
155
+ const nodeEndColumn = node.loc.end.column;
156
+ context.report({
157
+ loc: findLoc(originalClassNamesValue, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
158
+ messageId: 'invalidClassOrder',
159
+ fix: function(fixer) {
160
+ return fixer.replaceTextRange([
161
+ start,
162
+ end
163
+ ], validatedClassNamesValue);
164
+ }
165
+ });
166
+ }
167
+ };
168
+ return defineVisitors({
169
+ context,
170
+ settings
171
+ }, visitNode);
172
+ }
173
+ });
174
+
175
+ module.exports = classOrder;
@@ -1,3 +1,2 @@
1
- import { Rule } from 'eslint';
2
- declare const _default: Rule.RuleModule;
1
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidClassOrder", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
3
2
  export default _default;
@@ -1 +1,173 @@
1
- import T from"../utils/define-visitors.mjs";import b from"../utils/resolve-context.mjs";import v from"../utils/get-template-element-body.mjs";import R from"../utils/get-template-element-suffix.mjs";import I from"../utils/get-template-element-prefix.mjs";import k from"../utils/extract-value-from-node.mjs";import L from"../utils/extract-range-from-node.mjs";import V from"../utils/extract-classnames-from-value.mjs";import _ from"../utils/find-loc.mjs";import $ from"../utils/reorder-valid-classes-action.mjs";var D={meta:{docs:{description:"Enforce a consistent and logical order of classes",category:"Stylistic Issues",recommended:!1,url:"https://rc.css.master.co/docs/code-linting#consistent-class-order"},messages:{invalidClassOrder:"No consistent class order followed."},fixable:"code",schema:[{type:"object",properties:{calleeMatching:{type:"string"},classMatching:{type:"string"},ignoredKeys:{type:"array",items:{type:"string",minLength:0},uniqueItems:!0},config:{type:["string","object"]}}}]},create:function(u){const{options:M,settings:x}=b(u),N=u.sourceCode,a=(r,t=null)=>{let s=null,o=null,c=null,d="",g="",p=[];if(t===null){s=k(r);const e=L(r);r.type==="TextAttribute"?(o=e[0],c=e[1]):(o=e[0]+1,c=e[1]-1)}else switch(t.type){case"Identifier":return;case"TemplateLiteral":t.expressions.forEach(l=>{a(r,l)}),s=N.getText(t),s=s.substring(1,s.length-1),p=s.match(/\$\{(?:(?<!\\\\)(['"`]).*?(?<!\\\\)\1|[^}])*?\}/g)??[];for(let l=0;l<p.length;l++)s=s.replace(p[l],`EXPRESSION_STRING_NUM_${l}`);o=t.range[0]+1,c=t.range[1]-1;break;case"ConditionalExpression":a(r,t.consequent),a(r,t.alternate);return;case"LogicalExpression":a(r,t.right);return;case"ArrayExpression":t.elements.forEach(l=>{a(r,l)});return;case"ObjectExpression":const e=r.callee&&r.callee.name==="classnames",f=r.key&&r.key.type==="VDirectiveKey";t.properties.forEach(l=>{const E=e||f?l.key:l.value;a(r,E)});return;case"Property":a(r,t.key);break;case"Literal":s=t.value,o=t.range[0]+1,c=t.range[1]-1;break;case"SvelteLiteral":if(s=t.value,s==="")return;o=t.range[0],c=t.range[1];break;case"TemplateElement":if(s=t.value.raw,s==="")return;o=t.range[0],c=t.range[1];const n=u.sourceCode.getText(t);d=I(n,s),g=R(n,s),s=v(n,d,g);break}const{classNames:y,whitespaces:h,headSpace:S,tailSpace:C}=V(s);if(y.length<=1)return;let m=$(y,x.config);m=y.filter(e=>!m.includes(e)).concat(m).filter(e=>e.trim()!=="");let i="";for(let e=0;e<m.length;e++){const f=h[e]??"",n=m[e];i+=S?`${f}${n}`:`${n}${f}`,n&&(!C&&e===m.length-1&&(i=i.replace(/\s+$/,"")),S&&C&&e===m.length-1&&(i+=h[h.length-1]??""))}for(let e=0;e<p.length;e++)s=s.replace(`EXPRESSION_STRING_NUM_${e}`,p[e]),i=i.replace(`EXPRESSION_STRING_NUM_${e}`,p[e]);if(s!==i){i=d+i+g;const e=N.lines,f=r.loc.start.line,n=r.loc.end.line,l={loc:_(s,e,f,n),messageId:"invalidClassOrder",fix:function(E){return E.replaceTextRange([o,c],i)}};u.report(l)}};return T({context:u,settings:x},a)}};export{D as default};
1
+ import defineVisitors from '../utils/define-visitors.mjs';
2
+ import resolveContext from '../utils/resolve-context.mjs';
3
+ import getTemplateElementBody from '../utils/get-template-element-body.mjs';
4
+ import getTemplateElementSuffix from '../utils/get-template-element-suffix.mjs';
5
+ import getTemplateElementPrefix from '../utils/get-template-element-prefix.mjs';
6
+ import extractValueFromNode from '../utils/extract-value-from-node.mjs';
7
+ import extractRangeFromNode from '../utils/extract-range-from-node.mjs';
8
+ import extractClassnamesFromValue from '../utils/extract-classnames-from-value.mjs';
9
+ import findLoc from '../utils/find-loc.mjs';
10
+ import createRule from '../create-rule.mjs';
11
+ import settingsSchema from '../settings-schema.mjs';
12
+ import { reorderForReadableClasses } from '@master/css';
13
+
14
+ var classOrder = createRule({
15
+ name: 'consistent-class-order',
16
+ meta: {
17
+ type: 'layout',
18
+ fixable: 'code',
19
+ docs: {
20
+ description: 'Enforce a consistent and logical order of classes'
21
+ },
22
+ messages: {
23
+ invalidClassOrder: 'No consistent class order followed.'
24
+ },
25
+ schema: [
26
+ settingsSchema
27
+ ]
28
+ },
29
+ defaultOptions: [],
30
+ create: function(context) {
31
+ const { settings, css } = resolveContext(context);
32
+ const sourceCode = context.sourceCode;
33
+ const visitNode = (node, arg = null)=>{
34
+ let originalClassNamesValue = null;
35
+ let start = null;
36
+ let end = null;
37
+ let prefix = '';
38
+ let suffix = '';
39
+ let expStrings = [];
40
+ if (arg === null) {
41
+ originalClassNamesValue = extractValueFromNode(node);
42
+ const range = extractRangeFromNode(node);
43
+ if (node.type === 'TextAttribute') {
44
+ start = range[0];
45
+ end = range[1];
46
+ } else {
47
+ start = range[0] + 1;
48
+ end = range[1] - 1;
49
+ }
50
+ } else {
51
+ switch(arg.type){
52
+ case 'Identifier':
53
+ return;
54
+ case 'TemplateLiteral':
55
+ arg.expressions.forEach((exp)=>{
56
+ visitNode(node, exp);
57
+ });
58
+ originalClassNamesValue = sourceCode.getText(arg);
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
+ start = arg.range[0] + 1;
65
+ end = arg.range[1] - 1;
66
+ break;
67
+ case 'ConditionalExpression':
68
+ visitNode(node, arg.consequent);
69
+ visitNode(node, arg.alternate);
70
+ return;
71
+ case 'LogicalExpression':
72
+ visitNode(node, arg.right);
73
+ return;
74
+ case 'ArrayExpression':
75
+ arg.elements.forEach((el)=>{
76
+ visitNode(node, el);
77
+ });
78
+ return;
79
+ case 'ObjectExpression':
80
+ const isUsedByClassNamesPlugin = node.callee && node.callee.name === 'classnames';
81
+ const isVue = node.key && node.key.type === 'VDirectiveKey';
82
+ arg.properties.forEach((prop)=>{
83
+ const propVal = isUsedByClassNamesPlugin || isVue ? prop.key : prop.value;
84
+ visitNode(node, propVal);
85
+ });
86
+ return;
87
+ case 'Property':
88
+ visitNode(node, arg.key);
89
+ break;
90
+ case 'Literal':
91
+ originalClassNamesValue = arg.raw.slice(1, arg.raw.length - 1);
92
+ start = arg.range[0] + 1;
93
+ end = arg.range[1] - 1;
94
+ break;
95
+ case 'SvelteLiteral':
96
+ originalClassNamesValue = arg.value;
97
+ if (originalClassNamesValue === '') {
98
+ return;
99
+ }
100
+ start = arg.range[0];
101
+ end = arg.range[1];
102
+ break;
103
+ case 'TemplateElement':
104
+ originalClassNamesValue = arg.value.raw;
105
+ if (originalClassNamesValue === '') {
106
+ return;
107
+ }
108
+ start = arg.range[0];
109
+ end = arg.range[1];
110
+ // https://github.com/eslint/eslint/issues/13360
111
+ // The problem is that range computation includes the backticks (`test`)
112
+ // but value.raw does not include them, so there is a mismatch.
113
+ // start/end does not include the backticks, therefore it matches value.raw.
114
+ const txt = context.sourceCode.getText(arg);
115
+ prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
116
+ suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
117
+ originalClassNamesValue = getTemplateElementBody(txt, prefix, suffix);
118
+ break;
119
+ }
120
+ }
121
+ const { classNames, whitespaces, headSpace, tailSpace } = extractClassnamesFromValue(originalClassNamesValue);
122
+ if (classNames.length <= 1) {
123
+ // Don't run sorting for a single or empty className
124
+ return;
125
+ }
126
+ let orderedClassNames = reorderForReadableClasses(classNames, css).filter((eachOrderedClassName)=>classNames.includes(eachOrderedClassName));
127
+ orderedClassNames = classNames.filter((x)=>!orderedClassNames.includes(x)).concat(orderedClassNames).filter((x)=>x.trim() !== '');
128
+ // Generates the validated/sorted attribute value
129
+ let validatedClassNamesValue = '';
130
+ for(let i = 0; i < orderedClassNames.length; i++){
131
+ const w = whitespaces[i] ?? '';
132
+ const cls = orderedClassNames[i];
133
+ validatedClassNamesValue += headSpace ? `${w}${cls}` : `${cls}${w}`;
134
+ if (cls) {
135
+ if (!tailSpace && i === orderedClassNames.length - 1) {
136
+ validatedClassNamesValue = validatedClassNamesValue.replace(/\s+$/, '');
137
+ }
138
+ if (headSpace && tailSpace && i === orderedClassNames.length - 1) {
139
+ validatedClassNamesValue += whitespaces[whitespaces.length - 1] ?? '';
140
+ }
141
+ }
142
+ }
143
+ for(let i = 0; i < expStrings.length; i++){
144
+ originalClassNamesValue = originalClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
145
+ validatedClassNamesValue = validatedClassNamesValue.replace(`EXPRESSION_STRING_NUM_${i}`, expStrings[i]);
146
+ }
147
+ if (originalClassNamesValue !== validatedClassNamesValue) {
148
+ validatedClassNamesValue = prefix + validatedClassNamesValue + suffix;
149
+ const sourceCodeLines = sourceCode.lines;
150
+ const nodeStartLine = node.loc.start.line;
151
+ const nodeStartColumn = node.loc.start.column;
152
+ const nodeEndLine = node.loc.end.line;
153
+ const nodeEndColumn = node.loc.end.column;
154
+ context.report({
155
+ loc: findLoc(originalClassNamesValue, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
156
+ messageId: 'invalidClassOrder',
157
+ fix: function(fixer) {
158
+ return fixer.replaceTextRange([
159
+ start,
160
+ end
161
+ ], validatedClassNamesValue);
162
+ }
163
+ });
164
+ }
165
+ };
166
+ return defineVisitors({
167
+ context,
168
+ settings
169
+ }, visitNode);
170
+ }
171
+ });
172
+
173
+ export { classOrder as default };
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ var defineVisitors = require('../utils/define-visitors.cjs');
4
+ var resolveContext = require('../utils/resolve-context.cjs');
5
+ var findLoc = require('../utils/find-loc.cjs');
6
+ var parseNodeRecursive = require('../utils/parse-node-recursive.cjs');
7
+ var createRule = require('../create-rule.cjs');
8
+ var settingsSchema = require('../settings-schema.cjs');
9
+ var cssValidator = require('@master/css-validator');
10
+
11
+ var classValidation = createRule({
12
+ name: 'syntax-error-checks',
13
+ meta: {
14
+ type: 'problem',
15
+ docs: {
16
+ description: 'Detect syntax errors early when writing classes'
17
+ },
18
+ messages: {
19
+ invalidClass: '{{message}}',
20
+ disallowUnknownClass: '{{message}}'
21
+ },
22
+ fixable: null,
23
+ schema: [
24
+ settingsSchema
25
+ ]
26
+ },
27
+ defaultOptions: [],
28
+ create: function(context) {
29
+ const { options, settings, css } = resolveContext(context);
30
+ const visitNode = (node, arg = null)=>{
31
+ parseNodeRecursive.parseNodeRecursive(node, arg, (classNames, node)=>{
32
+ const sourceCode = context.sourceCode;
33
+ const sourceCodeLines = sourceCode.lines;
34
+ const nodeStartLine = node.loc.start.line;
35
+ const nodeStartColumn = node.loc.start.column;
36
+ const nodeEndLine = node.loc.end.line;
37
+ const nodeEndColumn = node.loc.end.column;
38
+ for (const className of classNames){
39
+ const { matched, errors } = cssValidator.validate(className, css);
40
+ if (errors.length > 0) {
41
+ for (const error of errors){
42
+ if (matched) {
43
+ context.report({
44
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
45
+ messageId: 'invalidClass',
46
+ data: {
47
+ message: error.message + '.'
48
+ }
49
+ });
50
+ } else if (options.disallowUnknownClass) {
51
+ context.report({
52
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
53
+ messageId: 'disallowUnknownClass',
54
+ data: {
55
+ message: `"${className}" is not a valid or known class.`
56
+ }
57
+ });
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }, false, false, settings.ignoredKeys, context);
63
+ };
64
+ return defineVisitors({
65
+ context,
66
+ settings
67
+ }, visitNode);
68
+ }
69
+ });
70
+
71
+ module.exports = classValidation;
@@ -1,3 +1,2 @@
1
- import { Rule } from 'eslint';
2
- declare const _default: Rule.RuleModule;
1
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidClass" | "disallowUnknownClass", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
3
2
  export default _default;
@@ -1 +1,69 @@
1
- import u from"../utils/define-visitors.mjs";import y from"../utils/resolve-context.mjs";import l from"../utils/find-loc.mjs";import{parseNodeRecursive as C}from"../utils/parse-node-recursive.mjs";import w from"../utils/validate-action.mjs";var b={meta:{docs:{description:"Detect syntax errors early when writing classes",category:"Stylistic Issues",recommended:!1,url:"https://rc.css.master.co/docs/code-linting#syntax-error-checks"},messages:{invalidClass:"{{message}}",disallowUnknownClass:"{{message}}"},fixable:null,schema:[{type:"object",properties:{calleeMatching:{type:"string"},classMatching:{type:"string"},ignoredKeys:{type:"array",items:{type:"string",minLength:0},uniqueItems:!0},config:{type:["string","object"]}}}]},create:function(e){const{options:c,settings:o}=y(e);return u({context:e,settings:o},(d,m=null)=>{C(d,m,(g,r)=>{const t=e.sourceCode.lines,i=r.loc.start.line,n=r.loc.end.line;for(const s of g){const{isMasterCSS:f,errors:a}=w(s,o.config);if(a.length>0)for(const p of a)f?e.report({loc:l(s,t,i,n),messageId:"invalidClass",data:{message:p.message+"."}}):c.disallowUnknownClass&&e.report({loc:l(s,t,i,n),messageId:"disallowUnknownClass",data:{message:`"${s}" is not a valid or known class.`}})}},!1,!1,o.ignoredKeys,e)})}};export{b as default};
1
+ import defineVisitors from '../utils/define-visitors.mjs';
2
+ import resolveContext from '../utils/resolve-context.mjs';
3
+ import findLoc from '../utils/find-loc.mjs';
4
+ import { parseNodeRecursive } from '../utils/parse-node-recursive.mjs';
5
+ import createRule from '../create-rule.mjs';
6
+ import settingsSchema from '../settings-schema.mjs';
7
+ import { validate } from '@master/css-validator';
8
+
9
+ var classValidation = createRule({
10
+ name: 'syntax-error-checks',
11
+ meta: {
12
+ type: 'problem',
13
+ docs: {
14
+ description: 'Detect syntax errors early when writing classes'
15
+ },
16
+ messages: {
17
+ invalidClass: '{{message}}',
18
+ disallowUnknownClass: '{{message}}'
19
+ },
20
+ fixable: null,
21
+ schema: [
22
+ settingsSchema
23
+ ]
24
+ },
25
+ defaultOptions: [],
26
+ create: function(context) {
27
+ const { options, settings, css } = resolveContext(context);
28
+ const visitNode = (node, arg = null)=>{
29
+ parseNodeRecursive(node, arg, (classNames, node)=>{
30
+ const sourceCode = context.sourceCode;
31
+ const sourceCodeLines = sourceCode.lines;
32
+ const nodeStartLine = node.loc.start.line;
33
+ const nodeStartColumn = node.loc.start.column;
34
+ const nodeEndLine = node.loc.end.line;
35
+ const nodeEndColumn = node.loc.end.column;
36
+ for (const className of classNames){
37
+ const { matched, errors } = validate(className, css);
38
+ if (errors.length > 0) {
39
+ for (const error of errors){
40
+ if (matched) {
41
+ context.report({
42
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
43
+ messageId: 'invalidClass',
44
+ data: {
45
+ message: error.message + '.'
46
+ }
47
+ });
48
+ } else if (options.disallowUnknownClass) {
49
+ context.report({
50
+ loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeStartColumn, nodeEndLine, nodeEndColumn),
51
+ messageId: 'disallowUnknownClass',
52
+ data: {
53
+ message: `"${className}" is not a valid or known class.`
54
+ }
55
+ });
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }, false, false, settings.ignoredKeys, context);
61
+ };
62
+ return defineVisitors({
63
+ context,
64
+ settings
65
+ }, visitNode);
66
+ }
67
+ });
68
+
69
+ export { classValidation as default };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const settingsSchema = {
4
+ type: 'object',
5
+ properties: {
6
+ classAttributes: {
7
+ type: 'array',
8
+ items: {
9
+ type: 'string'
10
+ }
11
+ },
12
+ classFunctions: {
13
+ type: 'array',
14
+ items: {
15
+ type: 'string'
16
+ }
17
+ },
18
+ ignoredKeys: {
19
+ type: 'array',
20
+ items: {
21
+ type: 'string',
22
+ minLength: 0
23
+ },
24
+ uniqueItems: true
25
+ },
26
+ config: {
27
+ type: [
28
+ 'string',
29
+ 'object'
30
+ ]
31
+ }
32
+ }
33
+ };
34
+
35
+ module.exports = settingsSchema;
@@ -0,0 +1,3 @@
1
+ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema';
2
+ declare const settingsSchema: JSONSchema4;
3
+ export default settingsSchema;
@@ -0,0 +1,33 @@
1
+ const settingsSchema = {
2
+ type: 'object',
3
+ properties: {
4
+ classAttributes: {
5
+ type: 'array',
6
+ items: {
7
+ type: 'string'
8
+ }
9
+ },
10
+ classFunctions: {
11
+ type: 'array',
12
+ items: {
13
+ type: 'string'
14
+ }
15
+ },
16
+ ignoredKeys: {
17
+ type: 'array',
18
+ items: {
19
+ type: 'string',
20
+ minLength: 0
21
+ },
22
+ uniqueItems: true
23
+ },
24
+ config: {
25
+ type: [
26
+ 'string',
27
+ 'object'
28
+ ]
29
+ }
30
+ }
31
+ };
32
+
33
+ export { settingsSchema as default };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var css = require('@master/css');
4
+
5
+ const settings = {
6
+ classAttributes: css.CLASS_ATTRIBUTES,
7
+ classFunctions: css.CLASS_FUNCTIONS,
8
+ classDeclarations: css.CLASS_DECLARATIONS,
9
+ ignoredKeys: [
10
+ 'compoundVariants',
11
+ 'defaultVariants'
12
+ ],
13
+ config: 'master.css'
14
+ };
15
+
16
+ module.exports = settings;
@@ -1,7 +1,15 @@
1
1
  declare const settings: {
2
- calleeMatching: string;
3
- classMatching: string;
2
+ classAttributes: string[];
3
+ classFunctions: string[];
4
+ classDeclarations: string[];
4
5
  ignoredKeys: string[];
5
6
  config: string;
6
7
  };
7
8
  export default settings;
9
+ export interface Settings {
10
+ classAttributes?: string[];
11
+ classFunctions?: string[];
12
+ classDeclarations?: string[];
13
+ ignoredKeys: string[];
14
+ config: string | object;
15
+ }
package/dist/settings.mjs CHANGED
@@ -1 +1,14 @@
1
- const s={calleeMatching:"^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)",classMatching:"^class(Name)?$",ignoredKeys:["compoundVariants","defaultVariants"],config:"master.css.*"};var a=s;export{a as default};
1
+ import { CLASS_ATTRIBUTES, CLASS_FUNCTIONS, CLASS_DECLARATIONS } from '@master/css';
2
+
3
+ const settings = {
4
+ classAttributes: CLASS_ATTRIBUTES,
5
+ classFunctions: CLASS_FUNCTIONS,
6
+ classDeclarations: CLASS_DECLARATIONS,
7
+ ignoredKeys: [
8
+ 'compoundVariants',
9
+ 'defaultVariants'
10
+ ],
11
+ config: 'master.css'
12
+ };
13
+
14
+ export { settings as default };