@master/eslint-plugin-css 2.0.0-rc.2 → 2.0.0-rc.20
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/README.md +1 -1
- 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.d.ts +10 -1
- package/dist/configs/flat.mjs +11 -1
- package/dist/configs/recommended.cjs +12 -0
- package/dist/configs/recommended.mjs +10 -1
- package/dist/create-rule.cjs +7 -0
- package/dist/create-rule.d.ts +3 -0
- package/dist/create-rule.mjs +5 -0
- package/dist/functions/get-css.cjs +16 -0
- package/dist/functions/get-css.d.ts +1 -0
- package/dist/functions/get-css.mjs +14 -0
- package/dist/functions/reorder-valid-classes.cjs +9 -0
- package/dist/functions/reorder-valid-classes.d.ts +3 -0
- package/dist/functions/reorder-valid-classes.mjs +11 -0
- package/dist/functions/reorder-valid-classes.worker.cjs +15 -0
- package/dist/functions/reorder-valid-classes.worker.d.ts +1 -0
- package/dist/functions/reorder-valid-classes.worker.mjs +13 -0
- package/dist/functions/valid-rules.cjs +9 -0
- package/dist/functions/valid-rules.d.ts +3 -0
- package/dist/functions/valid-rules.mjs +11 -0
- package/dist/functions/valid-rules.worker.cjs +24 -0
- package/dist/functions/valid-rules.worker.d.ts +6 -0
- package/dist/functions/valid-rules.worker.mjs +22 -0
- package/dist/functions/validate.cjs +9 -0
- package/dist/functions/validate.d.ts +3 -0
- package/dist/functions/validate.mjs +11 -0
- package/dist/functions/validate.worker.cjs +15 -0
- package/dist/functions/validate.worker.d.ts +5 -0
- package/dist/functions/validate.worker.mjs +13 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.ts +57 -1
- package/dist/index.mjs +15 -1
- package/dist/plugin.cjs +18 -0
- package/dist/plugin.d.ts +10 -2
- package/dist/plugin.mjs +16 -1
- package/dist/rules/class-collision.cjs +107 -0
- package/dist/rules/class-collision.d.ts +1 -2
- package/dist/rules/class-collision.mjs +105 -1
- package/dist/rules/class-order.cjs +198 -0
- package/dist/rules/class-order.d.ts +1 -2
- package/dist/rules/class-order.mjs +196 -1
- package/dist/rules/class-validation.cjs +94 -0
- package/dist/rules/class-validation.d.ts +1 -2
- package/dist/rules/class-validation.mjs +92 -1
- package/dist/settings.cjs +13 -0
- package/dist/settings.d.ts +6 -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/are-vendor-prefix-selectors-equal.cjs +14 -0
- package/dist/utils/are-vendor-prefix-selectors-equal.d.ts +1 -0
- package/dist/utils/are-vendor-prefix-selectors-equal.mjs +12 -0
- package/dist/utils/define-visitors.cjs +76 -0
- package/dist/utils/define-visitors.d.ts +8 -5
- package/dist/utils/define-visitors.mjs +74 -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-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.d.ts +2 -2
- package/dist/utils/parse-node-recursive.mjs +120 -1
- package/dist/utils/resolve-context.cjs +13 -0
- package/dist/utils/resolve-context.d.ts +8 -2
- package/dist/utils/resolve-context.mjs +11 -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.d.ts +0 -2
- package/dist/utils/get-mastercss.js +0 -1
- package/dist/utils/get-mastercss.mjs +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.d.ts +0 -3
- package/dist/utils/reorder-valid-classes-action.js +0 -1
- package/dist/utils/reorder-valid-classes-action.mjs +0 -1
- package/dist/utils/resolve-context.js +0 -1
- package/dist/utils/valid-rules-action.d.ts +0 -3
- package/dist/utils/valid-rules-action.js +0 -1
- package/dist/utils/valid-rules-action.mjs +0 -1
- package/dist/utils/validate-action.d.ts +0 -3
- package/dist/utils/validate-action.js +0 -1
- package/dist/utils/validate-action.mjs +0 -1
- package/dist/utils/workers/reorder-valid-classes.d.ts +0 -2
- package/dist/utils/workers/reorder-valid-classes.js +0 -1
- package/dist/utils/workers/reorder-valid-classes.mjs +0 -1
- package/dist/utils/workers/valid-rules.d.ts +0 -2
- package/dist/utils/workers/valid-rules.js +0 -1
- package/dist/utils/workers/valid-rules.mjs +0 -1
- package/dist/utils/workers/validate.d.ts +0 -5
- package/dist/utils/workers/validate.js +0 -1
- package/dist/utils/workers/validate.mjs +0 -1
|
@@ -1 +1,92 @@
|
|
|
1
|
-
import
|
|
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 validate from '../functions/validate.mjs';
|
|
6
|
+
import createRule from '../create-rule.mjs';
|
|
7
|
+
|
|
8
|
+
var classValidation = createRule({
|
|
9
|
+
name: 'syntax-error-checks',
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'problem',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Detect syntax errors early when writing classes',
|
|
14
|
+
recommended: 'recommended'
|
|
15
|
+
},
|
|
16
|
+
messages: {
|
|
17
|
+
invalidClass: '{{message}}',
|
|
18
|
+
disallowUnknownClass: '{{message}}'
|
|
19
|
+
},
|
|
20
|
+
fixable: null,
|
|
21
|
+
schema: [
|
|
22
|
+
{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
calleeMatching: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
classMatching: {
|
|
29
|
+
type: 'string'
|
|
30
|
+
},
|
|
31
|
+
ignoredKeys: {
|
|
32
|
+
type: 'array',
|
|
33
|
+
items: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
minLength: 0
|
|
36
|
+
},
|
|
37
|
+
uniqueItems: true
|
|
38
|
+
},
|
|
39
|
+
config: {
|
|
40
|
+
type: [
|
|
41
|
+
'string',
|
|
42
|
+
'object'
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
defaultOptions: [],
|
|
50
|
+
create: function(context) {
|
|
51
|
+
const { options, settings } = resolveContext(context);
|
|
52
|
+
const visitNode = (node, arg = null)=>{
|
|
53
|
+
parseNodeRecursive(node, arg, (classNames, node)=>{
|
|
54
|
+
const sourceCode = context.sourceCode;
|
|
55
|
+
const sourceCodeLines = sourceCode.lines;
|
|
56
|
+
const nodeStartLine = node.loc.start.line;
|
|
57
|
+
const nodeEndLine = node.loc.end.line;
|
|
58
|
+
for (const className of classNames){
|
|
59
|
+
const { isMasterCSS, errors } = validate(className, settings.config);
|
|
60
|
+
if (errors.length > 0) {
|
|
61
|
+
for (const error of errors){
|
|
62
|
+
if (isMasterCSS) {
|
|
63
|
+
context.report({
|
|
64
|
+
loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeEndLine),
|
|
65
|
+
messageId: 'invalidClass',
|
|
66
|
+
data: {
|
|
67
|
+
message: error.message + '.'
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
} else if (options.disallowUnknownClass) {
|
|
71
|
+
context.report({
|
|
72
|
+
loc: findLoc(className, sourceCodeLines, nodeStartLine, nodeEndLine),
|
|
73
|
+
messageId: 'disallowUnknownClass',
|
|
74
|
+
data: {
|
|
75
|
+
message: `"${className}" is not a valid or known class.`
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, false, false, settings.ignoredKeys, context);
|
|
83
|
+
};
|
|
84
|
+
return defineVisitors({
|
|
85
|
+
context,
|
|
86
|
+
settings,
|
|
87
|
+
options
|
|
88
|
+
}, visitNode);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
export { classValidation as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const settings = {
|
|
4
|
+
calleeMatching: '^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)',
|
|
5
|
+
classMatching: '^class(Name)?$',
|
|
6
|
+
ignoredKeys: [
|
|
7
|
+
'compoundVariants',
|
|
8
|
+
'defaultVariants'
|
|
9
|
+
],
|
|
10
|
+
config: 'master.css'
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = settings;
|
package/dist/settings.d.ts
CHANGED
package/dist/settings.mjs
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const settings = {
|
|
2
|
+
calleeMatching: '^(classnames|clsx|ctl|cva|cv|classVariant|styled(?:\\.\\w+)?)',
|
|
3
|
+
classMatching: '^class(Name)?$',
|
|
4
|
+
ignoredKeys: [
|
|
5
|
+
'compoundVariants',
|
|
6
|
+
'defaultVariants'
|
|
7
|
+
],
|
|
8
|
+
config: 'master.css'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { settings as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function areDeclarationsEqual(aDeclarations, bDeclarations) {
|
|
4
|
+
// 获取对象A和B的所有属性名
|
|
5
|
+
const aKeys = Object.keys(aDeclarations);
|
|
6
|
+
const bKeys = Object.keys(bDeclarations);
|
|
7
|
+
// 如果属性数量不相等,返回false
|
|
8
|
+
if (aKeys.length !== bKeys.length) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
// 检查对象A的属性是否都存在于对象B中
|
|
12
|
+
for (const key of aKeys){
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(bDeclarations, key)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// 如果所有属性都匹配,返回true
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = areDeclarationsEqual;
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
function
|
|
1
|
+
function areDeclarationsEqual(aDeclarations, bDeclarations) {
|
|
2
|
+
// 获取对象A和B的所有属性名
|
|
3
|
+
const aKeys = Object.keys(aDeclarations);
|
|
4
|
+
const bKeys = Object.keys(bDeclarations);
|
|
5
|
+
// 如果属性数量不相等,返回false
|
|
6
|
+
if (aKeys.length !== bKeys.length) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
// 检查对象A的属性是否都存在于对象B中
|
|
10
|
+
for (const key of aKeys){
|
|
11
|
+
if (!Object.prototype.hasOwnProperty.call(bDeclarations, key)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// 如果所有属性都匹配,返回true
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { areDeclarationsEqual as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors, bVendorPrefixSelectors) {
|
|
4
|
+
const aKeys = Object.keys(aVendorPrefixSelectors);
|
|
5
|
+
if (aKeys.length !== Object.keys(bVendorPrefixSelectors).length) return false;
|
|
6
|
+
return aKeys.every((eachAKey)=>{
|
|
7
|
+
if (!Object.prototype.hasOwnProperty.call(bVendorPrefixSelectors, eachAKey)) return false;
|
|
8
|
+
const aValues = aVendorPrefixSelectors[eachAKey];
|
|
9
|
+
const bValues = bVendorPrefixSelectors[eachAKey];
|
|
10
|
+
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = areVendorPrefixSelectorsEqual;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors: any, bVendorPrefixSelectors: any): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function areVendorPrefixSelectorsEqual(aVendorPrefixSelectors, bVendorPrefixSelectors) {
|
|
2
|
+
const aKeys = Object.keys(aVendorPrefixSelectors);
|
|
3
|
+
if (aKeys.length !== Object.keys(bVendorPrefixSelectors).length) return false;
|
|
4
|
+
return aKeys.every((eachAKey)=>{
|
|
5
|
+
if (!Object.prototype.hasOwnProperty.call(bVendorPrefixSelectors, eachAKey)) return false;
|
|
6
|
+
const aValues = aVendorPrefixSelectors[eachAKey];
|
|
7
|
+
const bValues = bVendorPrefixSelectors[eachAKey];
|
|
8
|
+
return aValues.length === bValues.length && aValues.every((eachAValue)=>bValues.includes(eachAValue));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { areVendorPrefixSelectorsEqual as default };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function defineVisitors({ context, settings, options }, visitNode) {
|
|
4
|
+
const isFnNode = (node)=>{
|
|
5
|
+
let calleeName = '';
|
|
6
|
+
const calleeNode = node.callee || node.tag;
|
|
7
|
+
if (calleeNode.type === 'Identifier') {
|
|
8
|
+
calleeName = calleeNode.name;
|
|
9
|
+
}
|
|
10
|
+
if (calleeNode.type === 'MemberExpression') {
|
|
11
|
+
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
12
|
+
}
|
|
13
|
+
return new RegExp(settings.calleeMatching).test(calleeName);
|
|
14
|
+
};
|
|
15
|
+
const CallExpression = function(node) {
|
|
16
|
+
if (!isFnNode(node)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
node.arguments.forEach((arg)=>{
|
|
20
|
+
visitNode(node, arg);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const classMatchingRegex = new RegExp(settings.classMatching);
|
|
24
|
+
const scriptVisitor = {
|
|
25
|
+
CallExpression,
|
|
26
|
+
JSXAttribute: function(node) {
|
|
27
|
+
if (!node.name || !classMatchingRegex.test(node.name.name)) return;
|
|
28
|
+
if (node.value && node.value.type === 'Literal') {
|
|
29
|
+
visitNode(node);
|
|
30
|
+
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
31
|
+
visitNode(node, node.value.expression);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
SvelteAttribute: function(node) {
|
|
35
|
+
if (!node.key?.name || !classMatchingRegex.test(node.key.name)) return;
|
|
36
|
+
for (const eachValue of node.value){
|
|
37
|
+
visitNode(node, eachValue);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
TextAttribute: function(node) {
|
|
41
|
+
if (!node.name || !classMatchingRegex.test(node.name)) return;
|
|
42
|
+
visitNode(node);
|
|
43
|
+
},
|
|
44
|
+
TaggedTemplateExpression: function(node) {
|
|
45
|
+
if (isFnNode(node)) {
|
|
46
|
+
visitNode(node, node.quasi);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const templateBodyVisitor = {
|
|
52
|
+
CallExpression,
|
|
53
|
+
VAttribute: function(node) {
|
|
54
|
+
if (node.value && node.value.type === 'VLiteral') {
|
|
55
|
+
visitNode(node);
|
|
56
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression') {
|
|
57
|
+
node.value.expression.elements.forEach((arg)=>{
|
|
58
|
+
visitNode(node, arg);
|
|
59
|
+
});
|
|
60
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression') {
|
|
61
|
+
node.value.expression.properties.forEach((prop)=>{
|
|
62
|
+
visitNode(node, prop);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
68
|
+
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
69
|
+
return scriptVisitor;
|
|
70
|
+
} else {
|
|
71
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
72
|
+
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = defineVisitors;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint';
|
|
3
|
+
import { Settings } from '../settings';
|
|
4
|
+
export default function defineVisitors({ context, settings, options }: {
|
|
5
|
+
context: RuleContext<any, any[]>;
|
|
6
|
+
settings: Settings;
|
|
7
|
+
options: any;
|
|
8
|
+
}, visitNode: (node: TSESTree.Node, args?: any) => void): RuleListener;
|
|
@@ -1 +1,74 @@
|
|
|
1
|
-
function
|
|
1
|
+
function defineVisitors({ context, settings, options }, visitNode) {
|
|
2
|
+
const isFnNode = (node)=>{
|
|
3
|
+
let calleeName = '';
|
|
4
|
+
const calleeNode = node.callee || node.tag;
|
|
5
|
+
if (calleeNode.type === 'Identifier') {
|
|
6
|
+
calleeName = calleeNode.name;
|
|
7
|
+
}
|
|
8
|
+
if (calleeNode.type === 'MemberExpression') {
|
|
9
|
+
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
10
|
+
}
|
|
11
|
+
return new RegExp(settings.calleeMatching).test(calleeName);
|
|
12
|
+
};
|
|
13
|
+
const CallExpression = function(node) {
|
|
14
|
+
if (!isFnNode(node)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
node.arguments.forEach((arg)=>{
|
|
18
|
+
visitNode(node, arg);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const classMatchingRegex = new RegExp(settings.classMatching);
|
|
22
|
+
const scriptVisitor = {
|
|
23
|
+
CallExpression,
|
|
24
|
+
JSXAttribute: function(node) {
|
|
25
|
+
if (!node.name || !classMatchingRegex.test(node.name.name)) return;
|
|
26
|
+
if (node.value && node.value.type === 'Literal') {
|
|
27
|
+
visitNode(node);
|
|
28
|
+
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
29
|
+
visitNode(node, node.value.expression);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
SvelteAttribute: function(node) {
|
|
33
|
+
if (!node.key?.name || !classMatchingRegex.test(node.key.name)) return;
|
|
34
|
+
for (const eachValue of node.value){
|
|
35
|
+
visitNode(node, eachValue);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
TextAttribute: function(node) {
|
|
39
|
+
if (!node.name || !classMatchingRegex.test(node.name)) return;
|
|
40
|
+
visitNode(node);
|
|
41
|
+
},
|
|
42
|
+
TaggedTemplateExpression: function(node) {
|
|
43
|
+
if (isFnNode(node)) {
|
|
44
|
+
visitNode(node, node.quasi);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const templateBodyVisitor = {
|
|
50
|
+
CallExpression,
|
|
51
|
+
VAttribute: function(node) {
|
|
52
|
+
if (node.value && node.value.type === 'VLiteral') {
|
|
53
|
+
visitNode(node);
|
|
54
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ArrayExpression') {
|
|
55
|
+
node.value.expression.elements.forEach((arg)=>{
|
|
56
|
+
visitNode(node, arg);
|
|
57
|
+
});
|
|
58
|
+
} else if (node.value && node.value.type === 'VExpressionContainer' && node.value.expression.type === 'ObjectExpression') {
|
|
59
|
+
node.value.expression.properties.forEach((prop)=>{
|
|
60
|
+
visitNode(node, prop);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
66
|
+
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
67
|
+
return scriptVisitor;
|
|
68
|
+
} else {
|
|
69
|
+
// @ts-expect-error defineTemplateBodyVisitor
|
|
70
|
+
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { defineVisitors as default };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const separatorRegEx = /([\t\n\f\r ]+)/;
|
|
4
|
+
function extractClassnamesFromValue(classStr) {
|
|
5
|
+
if (typeof classStr !== 'string') {
|
|
6
|
+
return {
|
|
7
|
+
classNames: [],
|
|
8
|
+
whitespaces: [],
|
|
9
|
+
headSpace: false,
|
|
10
|
+
tailSpace: false
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const parts = classStr.split(separatorRegEx);
|
|
14
|
+
if (parts[0] === '') {
|
|
15
|
+
parts.shift();
|
|
16
|
+
}
|
|
17
|
+
if (parts[parts.length - 1] === '') {
|
|
18
|
+
parts.pop();
|
|
19
|
+
}
|
|
20
|
+
const headSpace = separatorRegEx.test(parts[0]);
|
|
21
|
+
const tailSpace = separatorRegEx.test(parts[parts.length - 1]);
|
|
22
|
+
const isClass = (_, i)=>headSpace ? i % 2 !== 0 : i % 2 === 0;
|
|
23
|
+
const isNotClass = (_, i)=>headSpace ? i % 2 === 0 : i % 2 !== 0;
|
|
24
|
+
const classNames = parts.filter(isClass);
|
|
25
|
+
const whitespaces = parts.filter(isNotClass);
|
|
26
|
+
return {
|
|
27
|
+
classNames: classNames,
|
|
28
|
+
whitespaces: whitespaces,
|
|
29
|
+
headSpace: headSpace,
|
|
30
|
+
tailSpace: tailSpace
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = extractClassnamesFromValue;
|
|
@@ -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,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 };
|