@master/eslint-plugin-css 2.0.0-rc.7 → 2.0.0-rc.70
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 +136 -7
- package/dist/common.cjs +7 -0
- package/dist/common.d.ts +2 -0
- package/dist/common.mjs +4 -0
- package/dist/configs/base.cjs +11 -0
- package/dist/configs/base.d.ts +3 -0
- package/dist/configs/base.mjs +9 -0
- package/dist/configs/legacy.cjs +17 -0
- package/dist/configs/legacy.d.ts +3 -0
- package/dist/configs/legacy.mjs +15 -0
- package/dist/configs/recommended.cjs +14 -0
- package/dist/configs/recommended.d.ts +2 -13
- package/dist/configs/recommended.mjs +12 -1
- package/dist/create-rule.cjs +7 -0
- package/dist/create-rule.d.ts +5 -0
- package/dist/create-rule.mjs +5 -0
- package/dist/functions/filter-collision-classes.cjs +29 -0
- package/dist/functions/filter-collision-classes.d.ts +2 -0
- package/dist/functions/filter-collision-classes.mjs +27 -0
- package/dist/index.cjs +19 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +17 -1
- package/dist/plugin.cjs +26 -0
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.mjs +23 -1
- package/dist/rules/class-collision.cjs +76 -0
- package/dist/rules/class-collision.d.ts +3 -2
- package/dist/rules/class-collision.mjs +74 -1
- package/dist/rules/class-order.cjs +64 -0
- package/dist/rules/class-order.d.ts +3 -2
- package/dist/rules/class-order.mjs +62 -1
- package/dist/rules/class-validation.cjs +60 -0
- package/dist/rules/class-validation.d.ts +3 -2
- package/dist/rules/class-validation.mjs +58 -1
- package/dist/settings-schema.cjs +32 -0
- package/dist/settings-schema.d.ts +3 -0
- package/dist/settings-schema.mjs +30 -0
- package/dist/settings.cjs +16 -0
- package/dist/settings.d.ts +12 -3
- package/dist/settings.mjs +14 -1
- package/dist/utils/define-visitors.cjs +125 -0
- package/dist/utils/define-visitors.d.ts +7 -4
- package/dist/utils/define-visitors.mjs +123 -1
- package/dist/utils/is-same-or-child-path.cjs +10 -0
- package/dist/utils/is-same-or-child-path.d.ts +1 -0
- package/dist/utils/is-same-or-child-path.mjs +8 -0
- package/dist/utils/master-css.cjs +94 -0
- package/dist/utils/master-css.d.ts +21 -0
- package/dist/utils/master-css.mjs +81 -0
- package/dist/utils/resolve-class-node.cjs +147 -0
- package/dist/utils/resolve-class-node.d.ts +12 -0
- package/dist/utils/resolve-class-node.mjs +145 -0
- package/dist/utils/resolve-context.cjs +78 -0
- package/dist/utils/resolve-context.d.ts +11 -2
- package/dist/utils/resolve-context.mjs +76 -1
- package/dist/utils/with-visit-class-node.cjs +57 -0
- package/dist/utils/with-visit-class-node.d.ts +4 -0
- package/dist/utils/with-visit-class-node.mjs +55 -0
- package/package.json +1 -1
- package/dist/configs/config.d.ts +0 -13
- package/dist/configs/config.js +0 -1
- package/dist/configs/config.mjs +0 -1
- package/dist/configs/flat.d.ts +0 -16
- package/dist/configs/flat.js +0 -1
- package/dist/configs/flat.mjs +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.d.ts +0 -1
- package/dist/utils/are-declarations-equal.js +0 -1
- package/dist/utils/are-declarations-equal.mjs +0 -1
- package/dist/utils/define-visitors.js +0 -1
- package/dist/utils/extract-classnames-from-value.d.ts +0 -6
- package/dist/utils/extract-classnames-from-value.js +0 -1
- package/dist/utils/extract-classnames-from-value.mjs +0 -1
- package/dist/utils/extract-range-from-node.d.ts +0 -1
- package/dist/utils/extract-range-from-node.js +0 -1
- package/dist/utils/extract-range-from-node.mjs +0 -1
- package/dist/utils/extract-value-from-node.d.ts +0 -1
- package/dist/utils/extract-value-from-node.js +0 -1
- package/dist/utils/extract-value-from-node.mjs +0 -1
- package/dist/utils/find-loc.d.ts +0 -7
- package/dist/utils/find-loc.js +0 -1
- package/dist/utils/find-loc.mjs +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.d.ts +0 -1
- package/dist/utils/get-template-element-body.js +0 -1
- package/dist/utils/get-template-element-body.mjs +0 -1
- package/dist/utils/get-template-element-prefix.d.ts +0 -1
- package/dist/utils/get-template-element-prefix.js +0 -1
- package/dist/utils/get-template-element-prefix.mjs +0 -1
- package/dist/utils/get-template-element-suffix.d.ts +0 -1
- package/dist/utils/get-template-element-suffix.js +0 -1
- package/dist/utils/get-template-element-suffix.mjs +0 -1
- package/dist/utils/parse-node-recursive.d.ts +0 -13
- package/dist/utils/parse-node-recursive.js +0 -1
- package/dist/utils/parse-node-recursive.mjs +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
|
@@ -0,0 +1,64 @@
|
|
|
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 settingsSchema = require('../settings-schema.cjs');
|
|
7
|
+
var masterCss = require('../utils/master-css.cjs');
|
|
8
|
+
|
|
9
|
+
var classOrder = createRule({
|
|
10
|
+
name: 'consistent-class-order',
|
|
11
|
+
meta: {
|
|
12
|
+
type: 'layout',
|
|
13
|
+
fixable: 'code',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Enforce a consistent and logical order of classes'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
invalidClassOrder: 'No consistent class order followed.'
|
|
19
|
+
},
|
|
20
|
+
schema: [
|
|
21
|
+
settingsSchema
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [],
|
|
25
|
+
create: function(context) {
|
|
26
|
+
const { settings, css } = resolveContext(context);
|
|
27
|
+
const { sourceCode } = context;
|
|
28
|
+
return defineVisitors({
|
|
29
|
+
context,
|
|
30
|
+
settings
|
|
31
|
+
}, (node, { raw, start, end, nodes, classValueRawMap, classValues })=>{
|
|
32
|
+
if (nodes.length <= 1) return;
|
|
33
|
+
let orderedClasses = masterCss.sortReadableClasses(classValues, css);
|
|
34
|
+
let orderedRaw = nodes.map((eachNode, i)=>{
|
|
35
|
+
if (eachNode.type === 'class') {
|
|
36
|
+
const value = orderedClasses.shift();
|
|
37
|
+
return classValueRawMap.get(value);
|
|
38
|
+
}
|
|
39
|
+
if (eachNode.type === 'space' && (orderedClasses.length !== 0 || i === nodes.length - 1)) {
|
|
40
|
+
return eachNode.raw;
|
|
41
|
+
}
|
|
42
|
+
return '';
|
|
43
|
+
}).join('');
|
|
44
|
+
if (raw !== orderedRaw) {
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
loc: {
|
|
48
|
+
start: sourceCode.getLocFromIndex(start),
|
|
49
|
+
end: sourceCode.getLocFromIndex(end)
|
|
50
|
+
},
|
|
51
|
+
messageId: 'invalidClassOrder',
|
|
52
|
+
fix: function(fixer) {
|
|
53
|
+
return fixer.replaceTextRange([
|
|
54
|
+
start,
|
|
55
|
+
end
|
|
56
|
+
], orderedRaw);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
module.exports = classOrder;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidClassOrder", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
3
4
|
export default _default;
|
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import
|
|
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 settingsSchema from '../settings-schema.mjs';
|
|
5
|
+
import { sortReadableClasses } from '../utils/master-css.mjs';
|
|
6
|
+
|
|
7
|
+
var classOrder = createRule({
|
|
8
|
+
name: 'consistent-class-order',
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'layout',
|
|
11
|
+
fixable: 'code',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Enforce a consistent and logical order of classes'
|
|
14
|
+
},
|
|
15
|
+
messages: {
|
|
16
|
+
invalidClassOrder: 'No consistent class order followed.'
|
|
17
|
+
},
|
|
18
|
+
schema: [
|
|
19
|
+
settingsSchema
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create: function(context) {
|
|
24
|
+
const { settings, css } = resolveContext(context);
|
|
25
|
+
const { sourceCode } = context;
|
|
26
|
+
return defineVisitors({
|
|
27
|
+
context,
|
|
28
|
+
settings
|
|
29
|
+
}, (node, { raw, start, end, nodes, classValueRawMap, classValues })=>{
|
|
30
|
+
if (nodes.length <= 1) return;
|
|
31
|
+
let orderedClasses = sortReadableClasses(classValues, css);
|
|
32
|
+
let orderedRaw = nodes.map((eachNode, i)=>{
|
|
33
|
+
if (eachNode.type === 'class') {
|
|
34
|
+
const value = orderedClasses.shift();
|
|
35
|
+
return classValueRawMap.get(value);
|
|
36
|
+
}
|
|
37
|
+
if (eachNode.type === 'space' && (orderedClasses.length !== 0 || i === nodes.length - 1)) {
|
|
38
|
+
return eachNode.raw;
|
|
39
|
+
}
|
|
40
|
+
return '';
|
|
41
|
+
}).join('');
|
|
42
|
+
if (raw !== orderedRaw) {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
loc: {
|
|
46
|
+
start: sourceCode.getLocFromIndex(start),
|
|
47
|
+
end: sourceCode.getLocFromIndex(end)
|
|
48
|
+
},
|
|
49
|
+
messageId: 'invalidClassOrder',
|
|
50
|
+
fix: function(fixer) {
|
|
51
|
+
return fixer.replaceTextRange([
|
|
52
|
+
start,
|
|
53
|
+
end
|
|
54
|
+
], orderedRaw);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export { classOrder as default };
|
|
@@ -0,0 +1,60 @@
|
|
|
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 settingsSchema = require('../settings-schema.cjs');
|
|
7
|
+
var cssValidator = require('@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
|
+
return defineVisitors({
|
|
29
|
+
context,
|
|
30
|
+
settings
|
|
31
|
+
}, (_, { classNodes })=>{
|
|
32
|
+
for (const node of classNodes){
|
|
33
|
+
const { matched, errors } = cssValidator.validate(node.value, css);
|
|
34
|
+
if (errors.length > 0) {
|
|
35
|
+
for (const error of errors){
|
|
36
|
+
if (matched) {
|
|
37
|
+
context.report({
|
|
38
|
+
node,
|
|
39
|
+
messageId: 'invalidClass',
|
|
40
|
+
data: {
|
|
41
|
+
message: error.message + '.'
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
} else if (options.disallowUnknownClass) {
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: 'disallowUnknownClass',
|
|
48
|
+
data: {
|
|
49
|
+
message: `"${node.raw}" is not a valid or known class.`
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
module.exports = classValidation;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"invalidClass" | "disallowUnknownClass", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
2
|
+
name: string;
|
|
3
|
+
};
|
|
3
4
|
export default _default;
|
|
@@ -1 +1,58 @@
|
|
|
1
|
-
import
|
|
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 settingsSchema from '../settings-schema.mjs';
|
|
5
|
+
import { validate } from '@master/css-validator';
|
|
6
|
+
|
|
7
|
+
var classValidation = createRule({
|
|
8
|
+
name: 'syntax-error-checks',
|
|
9
|
+
meta: {
|
|
10
|
+
type: 'problem',
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Detect syntax errors early when writing classes'
|
|
13
|
+
},
|
|
14
|
+
messages: {
|
|
15
|
+
invalidClass: '{{message}}',
|
|
16
|
+
disallowUnknownClass: '{{message}}'
|
|
17
|
+
},
|
|
18
|
+
fixable: null,
|
|
19
|
+
schema: [
|
|
20
|
+
settingsSchema
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
defaultOptions: [],
|
|
24
|
+
create: function(context) {
|
|
25
|
+
const { options, settings, css } = resolveContext(context);
|
|
26
|
+
return defineVisitors({
|
|
27
|
+
context,
|
|
28
|
+
settings
|
|
29
|
+
}, (_, { classNodes })=>{
|
|
30
|
+
for (const node of classNodes){
|
|
31
|
+
const { matched, errors } = validate(node.value, css);
|
|
32
|
+
if (errors.length > 0) {
|
|
33
|
+
for (const error of errors){
|
|
34
|
+
if (matched) {
|
|
35
|
+
context.report({
|
|
36
|
+
node,
|
|
37
|
+
messageId: 'invalidClass',
|
|
38
|
+
data: {
|
|
39
|
+
message: error.message + '.'
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} else if (options.disallowUnknownClass) {
|
|
43
|
+
context.report({
|
|
44
|
+
node,
|
|
45
|
+
messageId: 'disallowUnknownClass',
|
|
46
|
+
data: {
|
|
47
|
+
message: `"${node.raw}" is not a valid or known class.`
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { classValidation as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
manifest: {
|
|
27
|
+
type: 'object'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = settingsSchema;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
manifest: {
|
|
25
|
+
type: 'object'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export { settingsSchema as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var masterCss = require('./utils/master-css.cjs');
|
|
4
|
+
|
|
5
|
+
const settings = {
|
|
6
|
+
classAttributes: masterCss.CLASS_ATTRIBUTES,
|
|
7
|
+
classFunctions: masterCss.CLASS_FUNCTIONS,
|
|
8
|
+
classDeclarations: masterCss.CLASS_DECLARATIONS,
|
|
9
|
+
ignoredKeys: [
|
|
10
|
+
'compoundVariants',
|
|
11
|
+
'defaultVariants'
|
|
12
|
+
],
|
|
13
|
+
manifest: undefined
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = settings;
|
package/dist/settings.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { type MasterCSSManifest } from './utils/master-css';
|
|
1
2
|
declare const settings: {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
classAttributes: string[];
|
|
4
|
+
classFunctions: string[];
|
|
5
|
+
classDeclarations: string[];
|
|
4
6
|
ignoredKeys: string[];
|
|
5
|
-
|
|
7
|
+
manifest: any;
|
|
6
8
|
};
|
|
7
9
|
export default settings;
|
|
10
|
+
export interface Settings {
|
|
11
|
+
classAttributes?: string[];
|
|
12
|
+
classFunctions?: string[];
|
|
13
|
+
classDeclarations?: string[];
|
|
14
|
+
ignoredKeys: string[];
|
|
15
|
+
manifest?: MasterCSSManifest;
|
|
16
|
+
}
|
package/dist/settings.mjs
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { CLASS_DECLARATIONS, CLASS_FUNCTIONS, CLASS_ATTRIBUTES } from './utils/master-css.mjs';
|
|
2
|
+
|
|
3
|
+
const settings = {
|
|
4
|
+
classAttributes: CLASS_ATTRIBUTES,
|
|
5
|
+
classFunctions: CLASS_FUNCTIONS,
|
|
6
|
+
classDeclarations: CLASS_DECLARATIONS,
|
|
7
|
+
ignoredKeys: [
|
|
8
|
+
'compoundVariants',
|
|
9
|
+
'defaultVariants'
|
|
10
|
+
],
|
|
11
|
+
manifest: undefined
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { settings as default };
|
|
@@ -0,0 +1,125 @@
|
|
|
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,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint';
|
|
3
|
+
import { Settings } from '../settings';
|
|
4
|
+
import resolveClassNode from './resolve-class-node';
|
|
2
5
|
export default function defineVisitors({ context, settings }: {
|
|
3
|
-
context:
|
|
4
|
-
settings:
|
|
5
|
-
}, visitNode:
|
|
6
|
+
context: RuleContext<any, any[]>;
|
|
7
|
+
settings: Settings;
|
|
8
|
+
}, visitNode: (node: TSESTree.Node, resolved: ReturnType<typeof resolveClassNode>) => void): RuleListener;
|
|
@@ -1 +1,123 @@
|
|
|
1
|
-
|
|
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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
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;
|