@master/eslint-plugin-css 2.0.0-rc.15 → 2.0.0-rc.17
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.
- package/dist/configs/config.cjs +16 -0
- package/dist/configs/config.mjs +14 -1
- package/dist/configs/flat.cjs +13 -0
- package/dist/configs/flat.mjs +11 -1
- package/dist/configs/recommended.cjs +12 -0
- package/dist/configs/recommended.mjs +10 -1
- package/dist/index.cjs +15 -0
- package/dist/index.mjs +13 -1
- package/dist/plugin.cjs +18 -0
- package/dist/plugin.mjs +16 -1
- package/dist/rules/class-collision.cjs +103 -0
- package/dist/rules/class-collision.mjs +101 -1
- package/dist/rules/class-order.cjs +196 -0
- package/dist/rules/class-order.mjs +194 -1
- package/dist/rules/class-validation.cjs +91 -0
- package/dist/rules/class-validation.mjs +89 -1
- package/dist/settings.cjs +13 -0
- package/dist/settings.mjs +11 -1
- package/dist/utils/are-declarations-equal.cjs +21 -0
- package/dist/utils/are-declarations-equal.mjs +19 -1
- package/dist/utils/define-visitors.cjs +74 -0
- package/dist/utils/define-visitors.mjs +72 -1
- package/dist/utils/extract-classnames-from-value.cjs +34 -0
- package/dist/utils/extract-classnames-from-value.mjs +32 -1
- package/dist/utils/extract-range-from-node.cjs +18 -0
- package/dist/utils/extract-range-from-node.mjs +16 -1
- package/dist/utils/extract-value-from-node.cjs +23 -0
- package/dist/utils/extract-value-from-node.mjs +21 -1
- package/dist/utils/find-loc.cjs +40 -0
- package/dist/utils/find-loc.mjs +38 -1
- package/dist/utils/get-mastercss.cjs +16 -0
- package/dist/utils/get-mastercss.d.ts +1 -1
- package/dist/utils/get-mastercss.mjs +14 -1
- package/dist/utils/get-template-element-body.cjs +12 -0
- package/dist/utils/get-template-element-body.mjs +10 -1
- package/dist/utils/get-template-element-prefix.cjs +11 -0
- package/dist/utils/get-template-element-prefix.mjs +9 -1
- package/dist/utils/get-template-element-suffix.cjs +10 -0
- package/dist/utils/get-template-element-suffix.mjs +8 -1
- package/dist/utils/parse-node-recursive.cjs +122 -0
- package/dist/utils/parse-node-recursive.mjs +120 -1
- package/dist/utils/reorder-valid-classes-action.cjs +9 -0
- package/dist/utils/reorder-valid-classes-action.mjs +7 -1
- package/dist/utils/resolve-context.cjs +13 -0
- package/dist/utils/resolve-context.mjs +11 -1
- package/dist/utils/valid-rules-action.cjs +9 -0
- package/dist/utils/valid-rules-action.mjs +7 -1
- package/dist/utils/validate-action.cjs +9 -0
- package/dist/utils/validate-action.mjs +7 -1
- package/dist/utils/workers/reorder-valid-classes.cjs +15 -0
- package/dist/utils/workers/reorder-valid-classes.mjs +13 -1
- package/dist/utils/workers/valid-rules.cjs +23 -0
- package/dist/utils/workers/valid-rules.mjs +21 -1
- package/dist/utils/workers/validate.cjs +15 -0
- package/dist/utils/workers/validate.mjs +13 -1
- package/package.json +1 -1
- package/dist/configs/config.js +0 -1
- package/dist/configs/flat.js +0 -1
- package/dist/configs/recommended.js +0 -1
- package/dist/index.js +0 -1
- package/dist/plugin.js +0 -1
- package/dist/rules/class-collision.js +0 -1
- package/dist/rules/class-order.js +0 -1
- package/dist/rules/class-validation.js +0 -1
- package/dist/settings.js +0 -1
- package/dist/utils/are-declarations-equal.js +0 -1
- package/dist/utils/define-visitors.js +0 -1
- package/dist/utils/extract-classnames-from-value.js +0 -1
- package/dist/utils/extract-range-from-node.js +0 -1
- package/dist/utils/extract-value-from-node.js +0 -1
- package/dist/utils/find-loc.js +0 -1
- package/dist/utils/get-mastercss.js +0 -1
- package/dist/utils/get-template-element-body.js +0 -1
- package/dist/utils/get-template-element-prefix.js +0 -1
- package/dist/utils/get-template-element-suffix.js +0 -1
- package/dist/utils/parse-node-recursive.js +0 -1
- package/dist/utils/reorder-valid-classes-action.js +0 -1
- package/dist/utils/resolve-context.js +0 -1
- package/dist/utils/valid-rules-action.js +0 -1
- package/dist/utils/validate-action.js +0 -1
- package/dist/utils/workers/reorder-valid-classes.js +0 -1
- package/dist/utils/workers/valid-rules.js +0 -1
- package/dist/utils/workers/validate.js +0 -1
|
@@ -1 +1,32 @@
|
|
|
1
|
-
const
|
|
1
|
+
const separatorRegEx = /([\t\n\f\r ]+)/;
|
|
2
|
+
function extractClassnamesFromValue(classStr) {
|
|
3
|
+
if (typeof classStr !== 'string') {
|
|
4
|
+
return {
|
|
5
|
+
classNames: [],
|
|
6
|
+
whitespaces: [],
|
|
7
|
+
headSpace: false,
|
|
8
|
+
tailSpace: false
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const parts = classStr.split(separatorRegEx);
|
|
12
|
+
if (parts[0] === '') {
|
|
13
|
+
parts.shift();
|
|
14
|
+
}
|
|
15
|
+
if (parts[parts.length - 1] === '') {
|
|
16
|
+
parts.pop();
|
|
17
|
+
}
|
|
18
|
+
const headSpace = separatorRegEx.test(parts[0]);
|
|
19
|
+
const tailSpace = separatorRegEx.test(parts[parts.length - 1]);
|
|
20
|
+
const isClass = (_, i)=>headSpace ? i % 2 !== 0 : i % 2 === 0;
|
|
21
|
+
const isNotClass = (_, i)=>headSpace ? i % 2 === 0 : i % 2 !== 0;
|
|
22
|
+
const classNames = parts.filter(isClass);
|
|
23
|
+
const whitespaces = parts.filter(isNotClass);
|
|
24
|
+
return {
|
|
25
|
+
classNames: classNames,
|
|
26
|
+
whitespaces: whitespaces,
|
|
27
|
+
headSpace: headSpace,
|
|
28
|
+
tailSpace: tailSpace
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { extractClassnamesFromValue as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function extractRangeFromNode(node) {
|
|
4
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
5
|
+
return [
|
|
6
|
+
node.valueSpan.fullStart.offset,
|
|
7
|
+
node.valueSpan.end.offset
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
switch(node.value.type){
|
|
11
|
+
case 'JSXExpressionContainer':
|
|
12
|
+
return node.value.expression.range;
|
|
13
|
+
default:
|
|
14
|
+
return node.value.range;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = extractRangeFromNode;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
function
|
|
1
|
+
function extractRangeFromNode(node) {
|
|
2
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
3
|
+
return [
|
|
4
|
+
node.valueSpan.fullStart.offset,
|
|
5
|
+
node.valueSpan.end.offset
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
switch(node.value.type){
|
|
9
|
+
case 'JSXExpressionContainer':
|
|
10
|
+
return node.value.expression.range;
|
|
11
|
+
default:
|
|
12
|
+
return node.value.range;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { extractRangeFromNode as default };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function extractValueFromNode(node) {
|
|
4
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
5
|
+
return node.value;
|
|
6
|
+
}
|
|
7
|
+
switch(node.value.type){
|
|
8
|
+
case 'JSXExpressionContainer':
|
|
9
|
+
return node.value.expression.value;
|
|
10
|
+
case 'VExpressionContainer':
|
|
11
|
+
switch(node.value.expression.type){
|
|
12
|
+
case 'ArrayExpression':
|
|
13
|
+
return node.value.expression.elements;
|
|
14
|
+
case 'ObjectExpression':
|
|
15
|
+
return node.value.expression.properties;
|
|
16
|
+
}
|
|
17
|
+
return node.value.expression.value;
|
|
18
|
+
default:
|
|
19
|
+
return node.value.value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = extractValueFromNode;
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
function
|
|
1
|
+
function extractValueFromNode(node) {
|
|
2
|
+
if (node.type === 'TextAttribute' && node.name === 'class') {
|
|
3
|
+
return node.value;
|
|
4
|
+
}
|
|
5
|
+
switch(node.value.type){
|
|
6
|
+
case 'JSXExpressionContainer':
|
|
7
|
+
return node.value.expression.value;
|
|
8
|
+
case 'VExpressionContainer':
|
|
9
|
+
switch(node.value.expression.type){
|
|
10
|
+
case 'ArrayExpression':
|
|
11
|
+
return node.value.expression.elements;
|
|
12
|
+
case 'ObjectExpression':
|
|
13
|
+
return node.value.expression.properties;
|
|
14
|
+
}
|
|
15
|
+
return node.value.expression.value;
|
|
16
|
+
default:
|
|
17
|
+
return node.value.value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { extractValueFromNode as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function findLoc(text, lines, startLine, endLine) {
|
|
4
|
+
const targetLines = text.match(/.+(?:\r\n|\n)?/g);
|
|
5
|
+
let checkingTargetLine = 0;
|
|
6
|
+
let resultStart = null;
|
|
7
|
+
let checking = false;
|
|
8
|
+
for(let i = startLine; i <= endLine; i++){
|
|
9
|
+
const sourceCodeLine = lines[i - 1];
|
|
10
|
+
const index = sourceCodeLine.indexOf(targetLines[checkingTargetLine].replace(/\r\n|\n/, ''));
|
|
11
|
+
if (index !== -1) {
|
|
12
|
+
if (checkingTargetLine === 0) {
|
|
13
|
+
resultStart = {
|
|
14
|
+
line: i,
|
|
15
|
+
column: index
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (checkingTargetLine === targetLines.length - 1) {
|
|
19
|
+
return {
|
|
20
|
+
start: resultStart,
|
|
21
|
+
end: {
|
|
22
|
+
line: i,
|
|
23
|
+
column: index + text.length
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
checking = true;
|
|
28
|
+
checkingTargetLine++;
|
|
29
|
+
} else {
|
|
30
|
+
if (checking) {
|
|
31
|
+
checking = false;
|
|
32
|
+
checkingTargetLine = 0;
|
|
33
|
+
resultStart = null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = findLoc;
|
package/dist/utils/find-loc.mjs
CHANGED
|
@@ -1 +1,38 @@
|
|
|
1
|
-
function
|
|
1
|
+
function findLoc(text, lines, startLine, endLine) {
|
|
2
|
+
const targetLines = text.match(/.+(?:\r\n|\n)?/g);
|
|
3
|
+
let checkingTargetLine = 0;
|
|
4
|
+
let resultStart = null;
|
|
5
|
+
let checking = false;
|
|
6
|
+
for(let i = startLine; i <= endLine; i++){
|
|
7
|
+
const sourceCodeLine = lines[i - 1];
|
|
8
|
+
const index = sourceCodeLine.indexOf(targetLines[checkingTargetLine].replace(/\r\n|\n/, ''));
|
|
9
|
+
if (index !== -1) {
|
|
10
|
+
if (checkingTargetLine === 0) {
|
|
11
|
+
resultStart = {
|
|
12
|
+
line: i,
|
|
13
|
+
column: index
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (checkingTargetLine === targetLines.length - 1) {
|
|
17
|
+
return {
|
|
18
|
+
start: resultStart,
|
|
19
|
+
end: {
|
|
20
|
+
line: i,
|
|
21
|
+
column: index + text.length
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
checking = true;
|
|
26
|
+
checkingTargetLine++;
|
|
27
|
+
} else {
|
|
28
|
+
if (checking) {
|
|
29
|
+
checking = false;
|
|
30
|
+
checkingTargetLine = 0;
|
|
31
|
+
resultStart = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { findLoc as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var css = require('@master/css');
|
|
4
|
+
var exploreConfig = require('explore-config');
|
|
5
|
+
|
|
6
|
+
let currentCSS;
|
|
7
|
+
let currentConfig;
|
|
8
|
+
function getMasterCSS(config) {
|
|
9
|
+
if (!currentCSS || currentConfig !== config) {
|
|
10
|
+
currentCSS = new css.MasterCSS(typeof config === 'object' ? config : exploreConfig(config || ''));
|
|
11
|
+
currentConfig = config;
|
|
12
|
+
}
|
|
13
|
+
return currentCSS;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = getMasterCSS;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import MasterCSS,
|
|
1
|
+
import { MasterCSS, Config } from '@master/css';
|
|
2
2
|
export default function getMasterCSS(config: string | Config): MasterCSS;
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { MasterCSS } from '@master/css';
|
|
2
|
+
import exploreConfig from 'explore-config';
|
|
3
|
+
|
|
4
|
+
let currentCSS;
|
|
5
|
+
let currentConfig;
|
|
6
|
+
function getMasterCSS(config) {
|
|
7
|
+
if (!currentCSS || currentConfig !== config) {
|
|
8
|
+
currentCSS = new MasterCSS(typeof config === 'object' ? config : exploreConfig(config || ''));
|
|
9
|
+
currentConfig = config;
|
|
10
|
+
}
|
|
11
|
+
return currentCSS;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { getMasterCSS as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getTemplateElementBody(text, prefix, suffix) {
|
|
4
|
+
let arr = text.split(prefix);
|
|
5
|
+
arr.shift();
|
|
6
|
+
const body = arr.join(prefix);
|
|
7
|
+
arr = body.split(suffix);
|
|
8
|
+
arr.pop();
|
|
9
|
+
return arr.join(suffix);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = getTemplateElementBody;
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementBody(text, prefix, suffix) {
|
|
2
|
+
let arr = text.split(prefix);
|
|
3
|
+
arr.shift();
|
|
4
|
+
const body = arr.join(prefix);
|
|
5
|
+
arr = body.split(suffix);
|
|
6
|
+
arr.pop();
|
|
7
|
+
return arr.join(suffix);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { getTemplateElementBody as default };
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementPrefix(text, raw) {
|
|
2
|
+
const idx = text.indexOf(raw);
|
|
3
|
+
if (idx === 0) {
|
|
4
|
+
return '';
|
|
5
|
+
}
|
|
6
|
+
return text.split(raw).shift();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { getTemplateElementPrefix as default };
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
function
|
|
1
|
+
function getTemplateElementSuffix(text, raw) {
|
|
2
|
+
if (text.indexOf(raw) === -1) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
return text.split(raw).pop();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { getTemplateElementSuffix as default };
|
|
@@ -0,0 +1,122 @@
|
|
|
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 = null) {
|
|
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
|
+
switch(childNode.type){
|
|
52
|
+
case 'TemplateLiteral':
|
|
53
|
+
childNode.expressions.forEach((exp)=>{
|
|
54
|
+
parseNodeRecursive(rootNode, exp, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
55
|
+
});
|
|
56
|
+
childNode.quasis.forEach((quasis)=>{
|
|
57
|
+
parseNodeRecursive(rootNode, quasis, cb, skipConditional, isolate, ignoredKeys);
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
case 'ConditionalExpression':
|
|
61
|
+
parseNodeRecursive(rootNode, childNode.consequent, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
62
|
+
parseNodeRecursive(rootNode, childNode.alternate, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
63
|
+
return;
|
|
64
|
+
case 'LogicalExpression':
|
|
65
|
+
parseNodeRecursive(rootNode, childNode.right, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
66
|
+
return;
|
|
67
|
+
case 'ArrayExpression':
|
|
68
|
+
childNode.elements.forEach((el)=>{
|
|
69
|
+
parseNodeRecursive(rootNode, el, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
case 'ObjectExpression':
|
|
73
|
+
childNode.properties.forEach((prop)=>{
|
|
74
|
+
const isUsedByClassNamesPlugin = rootNode.callee && rootNode.callee.name === 'classnames';
|
|
75
|
+
if (prop.type === 'SpreadElement') {
|
|
76
|
+
// Ignore spread elements
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (prop.key.type === 'Identifier' && ignoredKeys.includes(prop.key.name)) {
|
|
80
|
+
// Ignore specific keys defined in settings
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
parseNodeRecursive(rootNode, isUsedByClassNamesPlugin ? prop.key : prop.value, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
case 'Property':
|
|
87
|
+
parseNodeRecursive(rootNode, childNode.key, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
88
|
+
return;
|
|
89
|
+
case 'Literal':
|
|
90
|
+
originalClassNamesValue = childNode.value;
|
|
91
|
+
start = childNode.range[0] + 1;
|
|
92
|
+
end = childNode.range[1] - 1;
|
|
93
|
+
break;
|
|
94
|
+
case 'SvelteLiteral':
|
|
95
|
+
originalClassNamesValue = childNode.value;
|
|
96
|
+
start = childNode.range[0];
|
|
97
|
+
end = childNode.range[1];
|
|
98
|
+
break;
|
|
99
|
+
case 'TemplateElement':
|
|
100
|
+
originalClassNamesValue = childNode.value.raw;
|
|
101
|
+
start = childNode.range[0];
|
|
102
|
+
end = childNode.range[1];
|
|
103
|
+
// eslint-disable-next-line no-case-declarations
|
|
104
|
+
const txt = context?.sourceCode.getText(childNode) ?? '';
|
|
105
|
+
prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
|
|
106
|
+
suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
|
|
110
|
+
classNames = [
|
|
111
|
+
...new Set(classNames)
|
|
112
|
+
];
|
|
113
|
+
if (classNames.length === 0) {
|
|
114
|
+
// Don't run for empty className
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const targetNode = isolate ? null : rootNode;
|
|
118
|
+
cb(classNames, targetNode, originalClassNamesValue, start, end, prefix, suffix);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
exports.parseNodeRecursive = parseNodeRecursive;
|
|
@@ -1 +1,120 @@
|
|
|
1
|
-
import
|
|
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 = null) {
|
|
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
|
+
switch(childNode.type){
|
|
50
|
+
case 'TemplateLiteral':
|
|
51
|
+
childNode.expressions.forEach((exp)=>{
|
|
52
|
+
parseNodeRecursive(rootNode, exp, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
53
|
+
});
|
|
54
|
+
childNode.quasis.forEach((quasis)=>{
|
|
55
|
+
parseNodeRecursive(rootNode, quasis, cb, skipConditional, isolate, ignoredKeys);
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
case 'ConditionalExpression':
|
|
59
|
+
parseNodeRecursive(rootNode, childNode.consequent, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
60
|
+
parseNodeRecursive(rootNode, childNode.alternate, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
61
|
+
return;
|
|
62
|
+
case 'LogicalExpression':
|
|
63
|
+
parseNodeRecursive(rootNode, childNode.right, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
64
|
+
return;
|
|
65
|
+
case 'ArrayExpression':
|
|
66
|
+
childNode.elements.forEach((el)=>{
|
|
67
|
+
parseNodeRecursive(rootNode, el, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
68
|
+
});
|
|
69
|
+
return;
|
|
70
|
+
case 'ObjectExpression':
|
|
71
|
+
childNode.properties.forEach((prop)=>{
|
|
72
|
+
const isUsedByClassNamesPlugin = rootNode.callee && rootNode.callee.name === 'classnames';
|
|
73
|
+
if (prop.type === 'SpreadElement') {
|
|
74
|
+
// Ignore spread elements
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (prop.key.type === 'Identifier' && ignoredKeys.includes(prop.key.name)) {
|
|
78
|
+
// Ignore specific keys defined in settings
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
parseNodeRecursive(rootNode, isUsedByClassNamesPlugin ? prop.key : prop.value, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
82
|
+
});
|
|
83
|
+
return;
|
|
84
|
+
case 'Property':
|
|
85
|
+
parseNodeRecursive(rootNode, childNode.key, cb, skipConditional, forceIsolation, ignoredKeys);
|
|
86
|
+
return;
|
|
87
|
+
case 'Literal':
|
|
88
|
+
originalClassNamesValue = childNode.value;
|
|
89
|
+
start = childNode.range[0] + 1;
|
|
90
|
+
end = childNode.range[1] - 1;
|
|
91
|
+
break;
|
|
92
|
+
case 'SvelteLiteral':
|
|
93
|
+
originalClassNamesValue = childNode.value;
|
|
94
|
+
start = childNode.range[0];
|
|
95
|
+
end = childNode.range[1];
|
|
96
|
+
break;
|
|
97
|
+
case 'TemplateElement':
|
|
98
|
+
originalClassNamesValue = childNode.value.raw;
|
|
99
|
+
start = childNode.range[0];
|
|
100
|
+
end = childNode.range[1];
|
|
101
|
+
// eslint-disable-next-line no-case-declarations
|
|
102
|
+
const txt = context?.sourceCode.getText(childNode) ?? '';
|
|
103
|
+
prefix = getTemplateElementPrefix(txt, originalClassNamesValue);
|
|
104
|
+
suffix = getTemplateElementSuffix(txt, originalClassNamesValue);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
({ classNames } = extractClassnamesFromValue(originalClassNamesValue));
|
|
108
|
+
classNames = [
|
|
109
|
+
...new Set(classNames)
|
|
110
|
+
];
|
|
111
|
+
if (classNames.length === 0) {
|
|
112
|
+
// Don't run for empty className
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const targetNode = isolate ? null : rootNode;
|
|
116
|
+
cb(classNames, targetNode, originalClassNamesValue, start, end, prefix, suffix);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export { parseNodeRecursive };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import __mod_for_shim from 'module';
|
|
2
|
+
const require = __mod_for_shim.createRequire(import.meta.url);
|
|
3
|
+
import { createSyncFn } from 'synckit';
|
|
4
|
+
const reorderValidClassesAction = createSyncFn(require.resolve('./workers/reorder-valid-classes'), { tsRunner: 'swc' });
|
|
5
|
+
export {
|
|
6
|
+
reorderValidClassesAction as default
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var settings = require('../settings.cjs');
|
|
4
|
+
|
|
5
|
+
function resolveContext(context) {
|
|
6
|
+
const resolvedSettings = Object.assign(settings, context.settings?.['@master/css']);
|
|
7
|
+
return {
|
|
8
|
+
settings: resolvedSettings,
|
|
9
|
+
options: context.options[0] || {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = resolveContext;
|
|
@@ -1 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import settings from '../settings.mjs';
|
|
2
|
+
|
|
3
|
+
function resolveContext(context) {
|
|
4
|
+
const resolvedSettings = Object.assign(settings, context.settings?.['@master/css']);
|
|
5
|
+
return {
|
|
6
|
+
settings: resolvedSettings,
|
|
7
|
+
options: context.options[0] || {}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { resolveContext as default };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import __mod_for_shim from 'module';
|
|
2
|
+
const require = __mod_for_shim.createRequire(import.meta.url);
|
|
3
|
+
import { createSyncFn } from 'synckit';
|
|
4
|
+
const validRulesAction = createSyncFn(require.resolve('./workers/valid-rules'), { tsRunner: 'swc' });
|
|
5
|
+
export {
|
|
6
|
+
validRulesAction as default
|
|
7
|
+
};
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import __mod_for_shim from 'module';
|
|
2
|
+
const require = __mod_for_shim.createRequire(import.meta.url);
|
|
3
|
+
import { createSyncFn } from 'synckit';
|
|
4
|
+
const validateAction = createSyncFn(require.resolve('./workers/validate'), { tsRunner: 'swc' });
|
|
5
|
+
export {
|
|
6
|
+
validateAction as default
|
|
7
|
+
};
|