@master/eslint-plugin-css 2.0.0-rc.73 → 2.0.0-rc.74
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/LICENSE +21 -0
- package/dist/configs/base.d.ts +5 -2
- package/dist/configs/base.js +5 -0
- package/dist/configs/legacy.d.ts +5 -2
- package/dist/configs/legacy.js +9 -0
- package/dist/configs/recommended.d.ts +5 -2
- package/dist/configs/recommended.js +13 -0
- package/dist/create-rule.d.ts +11 -4
- package/dist/create-rule.js +5 -0
- package/dist/index.d.ts +13 -10
- package/dist/index.js +17 -0
- package/dist/plugin.d.ts +5 -2
- package/dist/plugin.js +26 -0
- package/dist/rules/no-conflicting-classes.d.ts +4 -2
- package/dist/rules/no-conflicting-classes.js +76 -0
- package/dist/rules/no-invalid-classes.d.ts +5 -3
- package/dist/rules/no-invalid-classes.js +41 -0
- package/dist/rules/no-unapproved-raw-values.d.ts +7 -5
- package/dist/rules/no-unapproved-raw-values.js +61 -0
- package/dist/rules/prefer-canonical-classes.d.ts +6 -3
- package/dist/rules/prefer-canonical-classes.js +79 -0
- package/dist/rules/sort-classes.d.ts +4 -2
- package/dist/rules/sort-classes.js +40 -0
- package/dist/settings-schema.d.ts +7 -4
- package/dist/settings-schema.js +27 -0
- package/dist/settings.d.ts +16 -13
- package/dist/settings.js +8 -0
- package/dist/utils/define-visitors.d.ts +14 -7
- package/dist/utils/define-visitors.js +107 -0
- package/dist/utils/is-same-or-child-path.d.ts +4 -1
- package/dist/utils/is-same-or-child-path.js +8 -0
- package/dist/utils/master-css.d.ts +6 -4
- package/dist/utils/master-css.js +6 -0
- package/dist/utils/resolve-class-node.d.ts +22 -18
- package/dist/utils/resolve-class-node.js +85 -0
- package/dist/utils/resolve-context.d.ts +16 -12
- package/dist/utils/resolve-context.js +69 -0
- package/dist/utils/with-visit-class-node.d.ts +8 -4
- package/dist/utils/with-visit-class-node.js +51 -0
- package/package.json +78 -1
- package/dist/configs/base.cjs +0 -11
- package/dist/configs/base.mjs +0 -9
- package/dist/configs/legacy.cjs +0 -17
- package/dist/configs/legacy.mjs +0 -15
- package/dist/configs/recommended.cjs +0 -15
- package/dist/configs/recommended.mjs +0 -13
- package/dist/create-rule.cjs +0 -7
- package/dist/create-rule.mjs +0 -5
- package/dist/index.cjs +0 -19
- package/dist/index.mjs +0 -17
- package/dist/plugin.cjs +0 -30
- package/dist/plugin.mjs +0 -27
- package/dist/rules/no-conflicting-classes.cjs +0 -101
- package/dist/rules/no-conflicting-classes.mjs +0 -99
- package/dist/rules/no-invalid-classes.cjs +0 -51
- package/dist/rules/no-invalid-classes.mjs +0 -49
- package/dist/rules/no-unapproved-raw-values.cjs +0 -77
- package/dist/rules/no-unapproved-raw-values.mjs +0 -75
- package/dist/rules/prefer-canonical-classes.cjs +0 -112
- package/dist/rules/prefer-canonical-classes.mjs +0 -110
- package/dist/rules/sort-classes.cjs +0 -53
- package/dist/rules/sort-classes.mjs +0 -51
- package/dist/settings-schema.cjs +0 -38
- package/dist/settings-schema.mjs +0 -32
- package/dist/settings.cjs +0 -10
- package/dist/settings.mjs +0 -8
- package/dist/utils/define-visitors.cjs +0 -125
- package/dist/utils/define-visitors.mjs +0 -123
- package/dist/utils/is-same-or-child-path.cjs +0 -10
- package/dist/utils/is-same-or-child-path.mjs +0 -8
- package/dist/utils/master-css.cjs +0 -14
- package/dist/utils/master-css.mjs +0 -7
- package/dist/utils/resolve-class-node.cjs +0 -98
- package/dist/utils/resolve-class-node.mjs +0 -96
- package/dist/utils/resolve-context.cjs +0 -78
- package/dist/utils/resolve-context.mjs +0 -76
- package/dist/utils/with-visit-class-node.cjs +0 -57
- package/dist/utils/with-visit-class-node.mjs +0 -55
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import defineVisitors from '../utils/define-visitors.mjs';
|
|
2
|
-
import resolveContext from '../utils/resolve-context.mjs';
|
|
3
|
-
import createRule from '../create-rule.mjs';
|
|
4
|
-
import { defaultCanonicalClassNameOptions, suggestCanonicalClassGroups, replaceClassGroupInClassList, suggestCanonicalClassName, replaceClassNameInClassList } from '@master/css-lint';
|
|
5
|
-
|
|
6
|
-
var preferCanonicalClasses = createRule({
|
|
7
|
-
name: 'prefer-canonical-classes',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'suggestion',
|
|
10
|
-
docs: {
|
|
11
|
-
description: 'Prefer canonical Master CSS classes'
|
|
12
|
-
},
|
|
13
|
-
messages: {
|
|
14
|
-
preferClass: 'Prefer "{{recommended}}" over "{{actual}}".'
|
|
15
|
-
},
|
|
16
|
-
fixable: 'code',
|
|
17
|
-
schema: [
|
|
18
|
-
{
|
|
19
|
-
type: 'object',
|
|
20
|
-
properties: {
|
|
21
|
-
preferStaticUtilities: {
|
|
22
|
-
type: 'boolean'
|
|
23
|
-
},
|
|
24
|
-
preferThemeTokens: {
|
|
25
|
-
type: 'boolean'
|
|
26
|
-
},
|
|
27
|
-
preferPropertyAliases: {
|
|
28
|
-
type: 'boolean'
|
|
29
|
-
},
|
|
30
|
-
preferVariableReferences: {
|
|
31
|
-
type: 'boolean'
|
|
32
|
-
},
|
|
33
|
-
preferMultiValueTokens: {
|
|
34
|
-
type: 'boolean'
|
|
35
|
-
},
|
|
36
|
-
preferCompositionUtilities: {
|
|
37
|
-
type: 'boolean'
|
|
38
|
-
},
|
|
39
|
-
preferConditionOrder: {
|
|
40
|
-
type: 'boolean'
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
additionalProperties: false
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
},
|
|
47
|
-
defaultOptions: [
|
|
48
|
-
defaultCanonicalClassNameOptions
|
|
49
|
-
],
|
|
50
|
-
create (context) {
|
|
51
|
-
const { settings, css } = resolveContext(context);
|
|
52
|
-
const options = {
|
|
53
|
-
...defaultCanonicalClassNameOptions,
|
|
54
|
-
...context.options[0] || {}
|
|
55
|
-
};
|
|
56
|
-
return defineVisitors({
|
|
57
|
-
context,
|
|
58
|
-
settings
|
|
59
|
-
}, (node, { raw, start, end, unescape, classNodes, classValues })=>{
|
|
60
|
-
const groupSuggestions = suggestCanonicalClassGroups(classValues, css, options);
|
|
61
|
-
const coveredClassNames = new Set(groupSuggestions.flatMap((suggestion)=>suggestion.classNames));
|
|
62
|
-
const reports = [];
|
|
63
|
-
let fixedRaw = raw;
|
|
64
|
-
for (const suggestion of groupSuggestions){
|
|
65
|
-
const firstClassNode = classNodes.find((node)=>node.value === suggestion.classNames[0]);
|
|
66
|
-
if (!firstClassNode) continue;
|
|
67
|
-
fixedRaw = replaceClassGroupInClassList(fixedRaw, suggestion.classNames, suggestion.recommended, {
|
|
68
|
-
unescape
|
|
69
|
-
});
|
|
70
|
-
reports.push({
|
|
71
|
-
loc: firstClassNode.loc,
|
|
72
|
-
actual: suggestion.classNames.join(' '),
|
|
73
|
-
recommended: suggestion.recommended
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
for (const classNode of classNodes){
|
|
77
|
-
if (coveredClassNames.has(classNode.value)) continue;
|
|
78
|
-
const recommended = suggestCanonicalClassName(classNode.value, css, options);
|
|
79
|
-
if (!recommended) continue;
|
|
80
|
-
fixedRaw = replaceClassNameInClassList(fixedRaw, classNode.value, recommended, {
|
|
81
|
-
unescape
|
|
82
|
-
});
|
|
83
|
-
reports.push({
|
|
84
|
-
loc: classNode.loc,
|
|
85
|
-
actual: classNode.value,
|
|
86
|
-
recommended
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
for (const report of reports){
|
|
90
|
-
context.report({
|
|
91
|
-
node,
|
|
92
|
-
loc: report.loc,
|
|
93
|
-
messageId: 'preferClass',
|
|
94
|
-
data: {
|
|
95
|
-
actual: report.actual,
|
|
96
|
-
recommended: report.recommended
|
|
97
|
-
},
|
|
98
|
-
fix (fixer) {
|
|
99
|
-
return fixer.replaceTextRange([
|
|
100
|
-
start,
|
|
101
|
-
end
|
|
102
|
-
], fixedRaw);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
export { preferCanonicalClasses as default };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var defineVisitors = require('../utils/define-visitors.cjs');
|
|
4
|
-
var resolveContext = require('../utils/resolve-context.cjs');
|
|
5
|
-
var createRule = require('../create-rule.cjs');
|
|
6
|
-
var cssLint = require('@master/css-lint');
|
|
7
|
-
|
|
8
|
-
var sortClasses = createRule({
|
|
9
|
-
name: 'sort-classes',
|
|
10
|
-
meta: {
|
|
11
|
-
type: 'layout',
|
|
12
|
-
fixable: 'code',
|
|
13
|
-
docs: {
|
|
14
|
-
description: 'Sort Master CSS classes'
|
|
15
|
-
},
|
|
16
|
-
messages: {
|
|
17
|
-
invalidClassOrder: 'No consistent class order followed.'
|
|
18
|
-
},
|
|
19
|
-
schema: []
|
|
20
|
-
},
|
|
21
|
-
defaultOptions: [],
|
|
22
|
-
create: function(context) {
|
|
23
|
-
const { settings, css } = resolveContext(context);
|
|
24
|
-
const { sourceCode } = context;
|
|
25
|
-
return defineVisitors({
|
|
26
|
-
context,
|
|
27
|
-
settings
|
|
28
|
-
}, (node, { raw, start, end, nodes, unescape })=>{
|
|
29
|
-
if (nodes.length <= 1) return;
|
|
30
|
-
const orderedRaw = cssLint.sortClassList(raw, css, {
|
|
31
|
-
unescape
|
|
32
|
-
});
|
|
33
|
-
if (raw !== orderedRaw) {
|
|
34
|
-
context.report({
|
|
35
|
-
node,
|
|
36
|
-
loc: {
|
|
37
|
-
start: sourceCode.getLocFromIndex(start),
|
|
38
|
-
end: sourceCode.getLocFromIndex(end)
|
|
39
|
-
},
|
|
40
|
-
messageId: 'invalidClassOrder',
|
|
41
|
-
fix: function(fixer) {
|
|
42
|
-
return fixer.replaceTextRange([
|
|
43
|
-
start,
|
|
44
|
-
end
|
|
45
|
-
], orderedRaw);
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
module.exports = sortClasses;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import defineVisitors from '../utils/define-visitors.mjs';
|
|
2
|
-
import resolveContext from '../utils/resolve-context.mjs';
|
|
3
|
-
import createRule from '../create-rule.mjs';
|
|
4
|
-
import { sortClassList } from '@master/css-lint';
|
|
5
|
-
|
|
6
|
-
var sortClasses = createRule({
|
|
7
|
-
name: 'sort-classes',
|
|
8
|
-
meta: {
|
|
9
|
-
type: 'layout',
|
|
10
|
-
fixable: 'code',
|
|
11
|
-
docs: {
|
|
12
|
-
description: 'Sort Master CSS classes'
|
|
13
|
-
},
|
|
14
|
-
messages: {
|
|
15
|
-
invalidClassOrder: 'No consistent class order followed.'
|
|
16
|
-
},
|
|
17
|
-
schema: []
|
|
18
|
-
},
|
|
19
|
-
defaultOptions: [],
|
|
20
|
-
create: function(context) {
|
|
21
|
-
const { settings, css } = resolveContext(context);
|
|
22
|
-
const { sourceCode } = context;
|
|
23
|
-
return defineVisitors({
|
|
24
|
-
context,
|
|
25
|
-
settings
|
|
26
|
-
}, (node, { raw, start, end, nodes, unescape })=>{
|
|
27
|
-
if (nodes.length <= 1) return;
|
|
28
|
-
const orderedRaw = sortClassList(raw, css, {
|
|
29
|
-
unescape
|
|
30
|
-
});
|
|
31
|
-
if (raw !== orderedRaw) {
|
|
32
|
-
context.report({
|
|
33
|
-
node,
|
|
34
|
-
loc: {
|
|
35
|
-
start: sourceCode.getLocFromIndex(start),
|
|
36
|
-
end: sourceCode.getLocFromIndex(end)
|
|
37
|
-
},
|
|
38
|
-
messageId: 'invalidClassOrder',
|
|
39
|
-
fix: function(fixer) {
|
|
40
|
-
return fixer.replaceTextRange([
|
|
41
|
-
start,
|
|
42
|
-
end
|
|
43
|
-
], orderedRaw);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
export { sortClasses as default };
|
package/dist/settings-schema.cjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const sourceMatcherSchema = {
|
|
6
|
-
type: 'array',
|
|
7
|
-
items: {
|
|
8
|
-
type: 'string',
|
|
9
|
-
minLength: 1
|
|
10
|
-
},
|
|
11
|
-
uniqueItems: true
|
|
12
|
-
};
|
|
13
|
-
const masterCSSSettingsSchema = {
|
|
14
|
-
type: 'object',
|
|
15
|
-
properties: {
|
|
16
|
-
classAttributes: sourceMatcherSchema,
|
|
17
|
-
classFunctions: sourceMatcherSchema,
|
|
18
|
-
classDeclarations: sourceMatcherSchema,
|
|
19
|
-
ignoredKeys: sourceMatcherSchema,
|
|
20
|
-
manifest: {
|
|
21
|
-
type: 'object'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
additionalProperties: false
|
|
25
|
-
};
|
|
26
|
-
const noInvalidClassesOptionsSchema = {
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
disallowUnknownClass: {
|
|
30
|
-
type: 'boolean'
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
additionalProperties: false
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.default = masterCSSSettingsSchema;
|
|
37
|
-
exports.masterCSSSettingsSchema = masterCSSSettingsSchema;
|
|
38
|
-
exports.noInvalidClassesOptionsSchema = noInvalidClassesOptionsSchema;
|
package/dist/settings-schema.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const sourceMatcherSchema = {
|
|
2
|
-
type: 'array',
|
|
3
|
-
items: {
|
|
4
|
-
type: 'string',
|
|
5
|
-
minLength: 1
|
|
6
|
-
},
|
|
7
|
-
uniqueItems: true
|
|
8
|
-
};
|
|
9
|
-
const masterCSSSettingsSchema = {
|
|
10
|
-
type: 'object',
|
|
11
|
-
properties: {
|
|
12
|
-
classAttributes: sourceMatcherSchema,
|
|
13
|
-
classFunctions: sourceMatcherSchema,
|
|
14
|
-
classDeclarations: sourceMatcherSchema,
|
|
15
|
-
ignoredKeys: sourceMatcherSchema,
|
|
16
|
-
manifest: {
|
|
17
|
-
type: 'object'
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
additionalProperties: false
|
|
21
|
-
};
|
|
22
|
-
const noInvalidClassesOptionsSchema = {
|
|
23
|
-
type: 'object',
|
|
24
|
-
properties: {
|
|
25
|
-
disallowUnknownClass: {
|
|
26
|
-
type: 'boolean'
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
additionalProperties: false
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export { masterCSSSettingsSchema as default, masterCSSSettingsSchema, noInvalidClassesOptionsSchema };
|
package/dist/settings.cjs
DELETED
package/dist/settings.mjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var withVisitClassNode = require('./with-visit-class-node.cjs');
|
|
4
|
-
|
|
5
|
-
function defineVisitors({ context, settings }, visitNode) {
|
|
6
|
-
const classAttributeRegex = new RegExp(`^(?:${settings.classAttributes.join('|')})$`);
|
|
7
|
-
const classFunctionsRegex = new RegExp(`^(?:${settings.classFunctions.join('|')})$`);
|
|
8
|
-
const classDeclarationsRegex = new RegExp(`^(?:${settings.classDeclarations.join('|')})$`);
|
|
9
|
-
const visitClassNode = withVisitClassNode(visitNode, context);
|
|
10
|
-
const getStaticName = (node)=>{
|
|
11
|
-
if (!node) return;
|
|
12
|
-
if (node.type === 'Identifier') return node.name;
|
|
13
|
-
if (node.type === 'Literal' && typeof node.value === 'string') return node.value;
|
|
14
|
-
};
|
|
15
|
-
const getMemberExpressionName = (node)=>{
|
|
16
|
-
if (!node || node.type !== 'MemberExpression') return;
|
|
17
|
-
const objectName = getStaticName(node.object);
|
|
18
|
-
const propertyName = getStaticName(node.property);
|
|
19
|
-
if (!objectName || !propertyName) return;
|
|
20
|
-
return `${objectName}.${propertyName}`;
|
|
21
|
-
};
|
|
22
|
-
const getCalleeName = (node)=>{
|
|
23
|
-
const calleeNode = node.callee || node.tag;
|
|
24
|
-
return getStaticName(calleeNode) || getMemberExpressionName(calleeNode);
|
|
25
|
-
};
|
|
26
|
-
const allowCalleeNode = (node)=>{
|
|
27
|
-
const calleeName = getCalleeName(node);
|
|
28
|
-
return calleeName ? classFunctionsRegex.test(calleeName) : false;
|
|
29
|
-
};
|
|
30
|
-
const getPropertyName = (prop)=>getStaticName(prop.key);
|
|
31
|
-
const visitUtilityDefinitions = (node)=>{
|
|
32
|
-
if (!node) return;
|
|
33
|
-
if (node.type === 'ArrayExpression') {
|
|
34
|
-
node.elements.forEach((element)=>{
|
|
35
|
-
if (!element || element.type === 'ObjectExpression') return;
|
|
36
|
-
visitClassNode(element);
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (node.type !== 'ObjectExpression') {
|
|
41
|
-
visitClassNode(node);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const visitClassDeclarationNode = (name, node)=>{
|
|
46
|
-
if (name !== 'utilities') {
|
|
47
|
-
visitClassNode(node);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
visitUtilityDefinitions(node);
|
|
51
|
-
};
|
|
52
|
-
const CallExpression = function(node) {
|
|
53
|
-
if (!allowCalleeNode(node)) return;
|
|
54
|
-
node.arguments.forEach((node)=>{
|
|
55
|
-
visitClassNode(node);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
const scriptVisitor = {
|
|
59
|
-
CallExpression,
|
|
60
|
-
JSXAttribute: function(node) {
|
|
61
|
-
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
62
|
-
if (node.value) {
|
|
63
|
-
visitClassNode(node.value);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
SvelteAttribute: function(node) {
|
|
67
|
-
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
68
|
-
for (const eachValue of node.value){
|
|
69
|
-
visitClassNode(eachValue);
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
TextAttribute: function(node) {
|
|
73
|
-
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
74
|
-
visitClassNode(node);
|
|
75
|
-
},
|
|
76
|
-
TaggedTemplateExpression: function(node) {
|
|
77
|
-
if (allowCalleeNode(node)) {
|
|
78
|
-
visitClassNode(node.quasi);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
VariableDeclaration: function(node) {
|
|
83
|
-
node.declarations.forEach((decl)=>{
|
|
84
|
-
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
85
|
-
visitClassDeclarationNode(decl.id.name, decl.init);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
ObjectExpression: function(node) {
|
|
90
|
-
node.properties.forEach((prop)=>{
|
|
91
|
-
if (prop.type === 'Property') {
|
|
92
|
-
const propName = getPropertyName(prop);
|
|
93
|
-
if (typeof propName === 'string' && classDeclarationsRegex.test(propName)) {
|
|
94
|
-
visitClassDeclarationNode(propName, prop.value);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
const templateBodyVisitor = {
|
|
101
|
-
CallExpression,
|
|
102
|
-
VAttribute: function(node) {
|
|
103
|
-
const name = node.key?.argument?.name || node.key?.name;
|
|
104
|
-
if (!name || !classAttributeRegex.test(name)) return;
|
|
105
|
-
if (node.value && node.value.type === 'VLiteral') {
|
|
106
|
-
visitClassNode(node.value);
|
|
107
|
-
} else if (node.value) {
|
|
108
|
-
if (node.value.type === 'VExpressionContainer') {
|
|
109
|
-
if (node.value.expression?.type === 'ArrayExpression' || node.value.expression?.type === 'ObjectExpression') {
|
|
110
|
-
visitClassNode(node.value.expression);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
// @ts-expect-error defineTemplateBodyVisitor
|
|
117
|
-
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
118
|
-
return scriptVisitor;
|
|
119
|
-
} else {
|
|
120
|
-
// @ts-expect-error defineTemplateBodyVisitor
|
|
121
|
-
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
module.exports = defineVisitors;
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import withVisitClassNode from './with-visit-class-node.mjs';
|
|
2
|
-
|
|
3
|
-
function defineVisitors({ context, settings }, visitNode) {
|
|
4
|
-
const classAttributeRegex = new RegExp(`^(?:${settings.classAttributes.join('|')})$`);
|
|
5
|
-
const classFunctionsRegex = new RegExp(`^(?:${settings.classFunctions.join('|')})$`);
|
|
6
|
-
const classDeclarationsRegex = new RegExp(`^(?:${settings.classDeclarations.join('|')})$`);
|
|
7
|
-
const visitClassNode = withVisitClassNode(visitNode, context);
|
|
8
|
-
const getStaticName = (node)=>{
|
|
9
|
-
if (!node) return;
|
|
10
|
-
if (node.type === 'Identifier') return node.name;
|
|
11
|
-
if (node.type === 'Literal' && typeof node.value === 'string') return node.value;
|
|
12
|
-
};
|
|
13
|
-
const getMemberExpressionName = (node)=>{
|
|
14
|
-
if (!node || node.type !== 'MemberExpression') return;
|
|
15
|
-
const objectName = getStaticName(node.object);
|
|
16
|
-
const propertyName = getStaticName(node.property);
|
|
17
|
-
if (!objectName || !propertyName) return;
|
|
18
|
-
return `${objectName}.${propertyName}`;
|
|
19
|
-
};
|
|
20
|
-
const getCalleeName = (node)=>{
|
|
21
|
-
const calleeNode = node.callee || node.tag;
|
|
22
|
-
return getStaticName(calleeNode) || getMemberExpressionName(calleeNode);
|
|
23
|
-
};
|
|
24
|
-
const allowCalleeNode = (node)=>{
|
|
25
|
-
const calleeName = getCalleeName(node);
|
|
26
|
-
return calleeName ? classFunctionsRegex.test(calleeName) : false;
|
|
27
|
-
};
|
|
28
|
-
const getPropertyName = (prop)=>getStaticName(prop.key);
|
|
29
|
-
const visitUtilityDefinitions = (node)=>{
|
|
30
|
-
if (!node) return;
|
|
31
|
-
if (node.type === 'ArrayExpression') {
|
|
32
|
-
node.elements.forEach((element)=>{
|
|
33
|
-
if (!element || element.type === 'ObjectExpression') return;
|
|
34
|
-
visitClassNode(element);
|
|
35
|
-
});
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (node.type !== 'ObjectExpression') {
|
|
39
|
-
visitClassNode(node);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const visitClassDeclarationNode = (name, node)=>{
|
|
44
|
-
if (name !== 'utilities') {
|
|
45
|
-
visitClassNode(node);
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
visitUtilityDefinitions(node);
|
|
49
|
-
};
|
|
50
|
-
const CallExpression = function(node) {
|
|
51
|
-
if (!allowCalleeNode(node)) return;
|
|
52
|
-
node.arguments.forEach((node)=>{
|
|
53
|
-
visitClassNode(node);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
const scriptVisitor = {
|
|
57
|
-
CallExpression,
|
|
58
|
-
JSXAttribute: function(node) {
|
|
59
|
-
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
60
|
-
if (node.value) {
|
|
61
|
-
visitClassNode(node.value);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
SvelteAttribute: function(node) {
|
|
65
|
-
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
66
|
-
for (const eachValue of node.value){
|
|
67
|
-
visitClassNode(eachValue);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
TextAttribute: function(node) {
|
|
71
|
-
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
72
|
-
visitClassNode(node);
|
|
73
|
-
},
|
|
74
|
-
TaggedTemplateExpression: function(node) {
|
|
75
|
-
if (allowCalleeNode(node)) {
|
|
76
|
-
visitClassNode(node.quasi);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
VariableDeclaration: function(node) {
|
|
81
|
-
node.declarations.forEach((decl)=>{
|
|
82
|
-
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
83
|
-
visitClassDeclarationNode(decl.id.name, decl.init);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
ObjectExpression: function(node) {
|
|
88
|
-
node.properties.forEach((prop)=>{
|
|
89
|
-
if (prop.type === 'Property') {
|
|
90
|
-
const propName = getPropertyName(prop);
|
|
91
|
-
if (typeof propName === 'string' && classDeclarationsRegex.test(propName)) {
|
|
92
|
-
visitClassDeclarationNode(propName, prop.value);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const templateBodyVisitor = {
|
|
99
|
-
CallExpression,
|
|
100
|
-
VAttribute: function(node) {
|
|
101
|
-
const name = node.key?.argument?.name || node.key?.name;
|
|
102
|
-
if (!name || !classAttributeRegex.test(name)) return;
|
|
103
|
-
if (node.value && node.value.type === 'VLiteral') {
|
|
104
|
-
visitClassNode(node.value);
|
|
105
|
-
} else if (node.value) {
|
|
106
|
-
if (node.value.type === 'VExpressionContainer') {
|
|
107
|
-
if (node.value.expression?.type === 'ArrayExpression' || node.value.expression?.type === 'ObjectExpression') {
|
|
108
|
-
visitClassNode(node.value.expression);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
// @ts-expect-error defineTemplateBodyVisitor
|
|
115
|
-
if (context.sourceCode.parserServices == null || context.sourceCode.parserServices.defineTemplateBodyVisitor == null) {
|
|
116
|
-
return scriptVisitor;
|
|
117
|
-
} else {
|
|
118
|
-
// @ts-expect-error defineTemplateBodyVisitor
|
|
119
|
-
return context.sourceCode.parserServices.defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export { defineVisitors as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('node:path');
|
|
4
|
-
|
|
5
|
-
function isSameOrChildPath(parentPath, childPath) {
|
|
6
|
-
const relativePath = path.relative(parentPath, childPath);
|
|
7
|
-
return relativePath === '' || !!relativePath && relativePath !== '..' && !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
module.exports = isSameOrChildPath;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
function isSameOrChildPath(parentPath, childPath) {
|
|
4
|
-
const relativePath = path.relative(parentPath, childPath);
|
|
5
|
-
return relativePath === '' || !!relativePath && relativePath !== '..' && !relativePath.startsWith(`..${path.sep}`) && !path.isAbsolute(relativePath);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { isSameOrChildPath as default };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var cssValidator = require('@master/css-validator');
|
|
4
|
-
var node_module = require('node:module');
|
|
5
|
-
|
|
6
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
|
-
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils/master-css.cjs', document.baseURI).href)));
|
|
8
|
-
const defaultManifest = require$1('@master/css-preset/default-manifest.json');
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "createCSSWithNativeDeclarations", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () { return cssValidator.createCSSWithNativeDeclarations; }
|
|
13
|
-
});
|
|
14
|
-
exports.defaultManifest = defaultManifest;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { createCSSWithNativeDeclarations } from '@master/css-validator';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
|
|
4
|
-
const require$1 = createRequire(import.meta.url);
|
|
5
|
-
const defaultManifest = require$1('@master/css-preset/default-manifest.json');
|
|
6
|
-
|
|
7
|
-
export { defaultManifest };
|