@master/eslint-plugin-css 2.0.0-rc.28 → 2.0.0-rc.29
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/index.d.ts +4 -2
- package/dist/rules/class-collision.cjs +3 -27
- package/dist/rules/class-collision.mjs +3 -27
- package/dist/rules/class-order.cjs +3 -27
- package/dist/rules/class-order.mjs +3 -27
- package/dist/rules/class-validation.cjs +3 -27
- package/dist/rules/class-validation.mjs +3 -27
- package/dist/settings-schema.cjs +35 -0
- package/dist/settings-schema.d.ts +3 -0
- package/dist/settings-schema.mjs +33 -0
- package/dist/settings.cjs +5 -2
- package/dist/settings.d.ts +6 -4
- package/dist/settings.mjs +5 -2
- package/dist/utils/define-visitors.cjs +23 -6
- package/dist/utils/define-visitors.d.ts +1 -2
- package/dist/utils/define-visitors.mjs +23 -6
- package/dist/utils/resolve-context.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -42,9 +42,11 @@ declare const _default: {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
settings: {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
classAttributes: string[];
|
|
46
|
+
classFunctions: string[];
|
|
47
|
+
classDeclarations: string[];
|
|
47
48
|
ignoredKeys: string[];
|
|
49
|
+
/** @type {import('typescript-eslint').Config} */
|
|
48
50
|
config: string;
|
|
49
51
|
};
|
|
50
52
|
meta: {
|
|
@@ -6,6 +6,7 @@ var findLoc = require('../utils/find-loc.cjs');
|
|
|
6
6
|
var parseNodeRecursive = require('../utils/parse-node-recursive.cjs');
|
|
7
7
|
var filterCollisionClasses = require('../functions/filter-collision-classes.cjs');
|
|
8
8
|
var createRule = require('../create-rule.cjs');
|
|
9
|
+
var settingsSchema = require('../settings-schema.cjs');
|
|
9
10
|
|
|
10
11
|
var classCollision = createRule({
|
|
11
12
|
name: 'class-collision-detection',
|
|
@@ -20,31 +21,7 @@ var classCollision = createRule({
|
|
|
20
21
|
},
|
|
21
22
|
fixable: 'code',
|
|
22
23
|
schema: [
|
|
23
|
-
|
|
24
|
-
type: 'object',
|
|
25
|
-
properties: {
|
|
26
|
-
calleeMatching: {
|
|
27
|
-
type: 'string'
|
|
28
|
-
},
|
|
29
|
-
classMatching: {
|
|
30
|
-
type: 'string'
|
|
31
|
-
},
|
|
32
|
-
ignoredKeys: {
|
|
33
|
-
type: 'array',
|
|
34
|
-
items: {
|
|
35
|
-
type: 'string',
|
|
36
|
-
minLength: 0
|
|
37
|
-
},
|
|
38
|
-
uniqueItems: true
|
|
39
|
-
},
|
|
40
|
-
config: {
|
|
41
|
-
type: [
|
|
42
|
-
'string',
|
|
43
|
-
'object'
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
24
|
+
settingsSchema
|
|
48
25
|
]
|
|
49
26
|
},
|
|
50
27
|
defaultOptions: [],
|
|
@@ -83,8 +60,7 @@ var classCollision = createRule({
|
|
|
83
60
|
};
|
|
84
61
|
return defineVisitors({
|
|
85
62
|
context,
|
|
86
|
-
settings
|
|
87
|
-
options
|
|
63
|
+
settings
|
|
88
64
|
}, visitNode);
|
|
89
65
|
}
|
|
90
66
|
});
|
|
@@ -4,6 +4,7 @@ import findLoc from '../utils/find-loc.mjs';
|
|
|
4
4
|
import { parseNodeRecursive } from '../utils/parse-node-recursive.mjs';
|
|
5
5
|
import filterCollisionClasses from '../functions/filter-collision-classes.mjs';
|
|
6
6
|
import createRule from '../create-rule.mjs';
|
|
7
|
+
import settingsSchema from '../settings-schema.mjs';
|
|
7
8
|
|
|
8
9
|
var classCollision = createRule({
|
|
9
10
|
name: 'class-collision-detection',
|
|
@@ -18,31 +19,7 @@ var classCollision = createRule({
|
|
|
18
19
|
},
|
|
19
20
|
fixable: 'code',
|
|
20
21
|
schema: [
|
|
21
|
-
|
|
22
|
-
type: 'object',
|
|
23
|
-
properties: {
|
|
24
|
-
calleeMatching: {
|
|
25
|
-
type: 'string'
|
|
26
|
-
},
|
|
27
|
-
classMatching: {
|
|
28
|
-
type: 'string'
|
|
29
|
-
},
|
|
30
|
-
ignoredKeys: {
|
|
31
|
-
type: 'array',
|
|
32
|
-
items: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
minLength: 0
|
|
35
|
-
},
|
|
36
|
-
uniqueItems: true
|
|
37
|
-
},
|
|
38
|
-
config: {
|
|
39
|
-
type: [
|
|
40
|
-
'string',
|
|
41
|
-
'object'
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
22
|
+
settingsSchema
|
|
46
23
|
]
|
|
47
24
|
},
|
|
48
25
|
defaultOptions: [],
|
|
@@ -81,8 +58,7 @@ var classCollision = createRule({
|
|
|
81
58
|
};
|
|
82
59
|
return defineVisitors({
|
|
83
60
|
context,
|
|
84
|
-
settings
|
|
85
|
-
options
|
|
61
|
+
settings
|
|
86
62
|
}, visitNode);
|
|
87
63
|
}
|
|
88
64
|
});
|
|
@@ -11,6 +11,7 @@ var extractClassnamesFromValue = require('../utils/extract-classnames-from-value
|
|
|
11
11
|
var findLoc = require('../utils/find-loc.cjs');
|
|
12
12
|
var reorderValidClasses = require('../functions/reorder-valid-classes.cjs');
|
|
13
13
|
var createRule = require('../create-rule.cjs');
|
|
14
|
+
var settingsSchema = require('../settings-schema.cjs');
|
|
14
15
|
|
|
15
16
|
var classOrder = createRule({
|
|
16
17
|
name: 'consistent-class-order',
|
|
@@ -25,31 +26,7 @@ var classOrder = createRule({
|
|
|
25
26
|
invalidClassOrder: 'No consistent class order followed.'
|
|
26
27
|
},
|
|
27
28
|
schema: [
|
|
28
|
-
|
|
29
|
-
type: 'object',
|
|
30
|
-
properties: {
|
|
31
|
-
calleeMatching: {
|
|
32
|
-
type: 'string'
|
|
33
|
-
},
|
|
34
|
-
classMatching: {
|
|
35
|
-
type: 'string'
|
|
36
|
-
},
|
|
37
|
-
ignoredKeys: {
|
|
38
|
-
type: 'array',
|
|
39
|
-
items: {
|
|
40
|
-
type: 'string',
|
|
41
|
-
minLength: 0
|
|
42
|
-
},
|
|
43
|
-
uniqueItems: true
|
|
44
|
-
},
|
|
45
|
-
config: {
|
|
46
|
-
type: [
|
|
47
|
-
'string',
|
|
48
|
-
'object'
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
29
|
+
settingsSchema
|
|
53
30
|
]
|
|
54
31
|
},
|
|
55
32
|
defaultOptions: [],
|
|
@@ -189,8 +166,7 @@ var classOrder = createRule({
|
|
|
189
166
|
};
|
|
190
167
|
return defineVisitors({
|
|
191
168
|
context,
|
|
192
|
-
settings
|
|
193
|
-
options
|
|
169
|
+
settings
|
|
194
170
|
}, visitNode);
|
|
195
171
|
}
|
|
196
172
|
});
|
|
@@ -9,6 +9,7 @@ import extractClassnamesFromValue from '../utils/extract-classnames-from-value.m
|
|
|
9
9
|
import findLoc from '../utils/find-loc.mjs';
|
|
10
10
|
import reorderValidClasses from '../functions/reorder-valid-classes.mjs';
|
|
11
11
|
import createRule from '../create-rule.mjs';
|
|
12
|
+
import settingsSchema from '../settings-schema.mjs';
|
|
12
13
|
|
|
13
14
|
var classOrder = createRule({
|
|
14
15
|
name: 'consistent-class-order',
|
|
@@ -23,31 +24,7 @@ var classOrder = createRule({
|
|
|
23
24
|
invalidClassOrder: 'No consistent class order followed.'
|
|
24
25
|
},
|
|
25
26
|
schema: [
|
|
26
|
-
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
calleeMatching: {
|
|
30
|
-
type: 'string'
|
|
31
|
-
},
|
|
32
|
-
classMatching: {
|
|
33
|
-
type: 'string'
|
|
34
|
-
},
|
|
35
|
-
ignoredKeys: {
|
|
36
|
-
type: 'array',
|
|
37
|
-
items: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
minLength: 0
|
|
40
|
-
},
|
|
41
|
-
uniqueItems: true
|
|
42
|
-
},
|
|
43
|
-
config: {
|
|
44
|
-
type: [
|
|
45
|
-
'string',
|
|
46
|
-
'object'
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
27
|
+
settingsSchema
|
|
51
28
|
]
|
|
52
29
|
},
|
|
53
30
|
defaultOptions: [],
|
|
@@ -187,8 +164,7 @@ var classOrder = createRule({
|
|
|
187
164
|
};
|
|
188
165
|
return defineVisitors({
|
|
189
166
|
context,
|
|
190
|
-
settings
|
|
191
|
-
options
|
|
167
|
+
settings
|
|
192
168
|
}, visitNode);
|
|
193
169
|
}
|
|
194
170
|
});
|
|
@@ -6,6 +6,7 @@ var findLoc = require('../utils/find-loc.cjs');
|
|
|
6
6
|
var parseNodeRecursive = require('../utils/parse-node-recursive.cjs');
|
|
7
7
|
var validate = require('../functions/validate.cjs');
|
|
8
8
|
var createRule = require('../create-rule.cjs');
|
|
9
|
+
var settingsSchema = require('../settings-schema.cjs');
|
|
9
10
|
|
|
10
11
|
var classValidation = createRule({
|
|
11
12
|
name: 'syntax-error-checks',
|
|
@@ -21,31 +22,7 @@ var classValidation = createRule({
|
|
|
21
22
|
},
|
|
22
23
|
fixable: null,
|
|
23
24
|
schema: [
|
|
24
|
-
|
|
25
|
-
type: 'object',
|
|
26
|
-
properties: {
|
|
27
|
-
calleeMatching: {
|
|
28
|
-
type: 'string'
|
|
29
|
-
},
|
|
30
|
-
classMatching: {
|
|
31
|
-
type: 'string'
|
|
32
|
-
},
|
|
33
|
-
ignoredKeys: {
|
|
34
|
-
type: 'array',
|
|
35
|
-
items: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
minLength: 0
|
|
38
|
-
},
|
|
39
|
-
uniqueItems: true
|
|
40
|
-
},
|
|
41
|
-
config: {
|
|
42
|
-
type: [
|
|
43
|
-
'string',
|
|
44
|
-
'object'
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
25
|
+
settingsSchema
|
|
49
26
|
]
|
|
50
27
|
},
|
|
51
28
|
defaultOptions: [],
|
|
@@ -85,8 +62,7 @@ var classValidation = createRule({
|
|
|
85
62
|
};
|
|
86
63
|
return defineVisitors({
|
|
87
64
|
context,
|
|
88
|
-
settings
|
|
89
|
-
options
|
|
65
|
+
settings
|
|
90
66
|
}, visitNode);
|
|
91
67
|
}
|
|
92
68
|
});
|
|
@@ -4,6 +4,7 @@ import findLoc from '../utils/find-loc.mjs';
|
|
|
4
4
|
import { parseNodeRecursive } from '../utils/parse-node-recursive.mjs';
|
|
5
5
|
import validate from '../functions/validate.mjs';
|
|
6
6
|
import createRule from '../create-rule.mjs';
|
|
7
|
+
import settingsSchema from '../settings-schema.mjs';
|
|
7
8
|
|
|
8
9
|
var classValidation = createRule({
|
|
9
10
|
name: 'syntax-error-checks',
|
|
@@ -19,31 +20,7 @@ var classValidation = createRule({
|
|
|
19
20
|
},
|
|
20
21
|
fixable: null,
|
|
21
22
|
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
|
-
}
|
|
23
|
+
settingsSchema
|
|
47
24
|
]
|
|
48
25
|
},
|
|
49
26
|
defaultOptions: [],
|
|
@@ -83,8 +60,7 @@ var classValidation = createRule({
|
|
|
83
60
|
};
|
|
84
61
|
return defineVisitors({
|
|
85
62
|
context,
|
|
86
|
-
settings
|
|
87
|
-
options
|
|
63
|
+
settings
|
|
88
64
|
}, visitNode);
|
|
89
65
|
}
|
|
90
66
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const settingsSchema = {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
classAttributes: {
|
|
7
|
+
type: 'array',
|
|
8
|
+
items: {
|
|
9
|
+
type: 'string'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
classFunctions: {
|
|
13
|
+
type: 'array',
|
|
14
|
+
items: {
|
|
15
|
+
type: 'string'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
ignoredKeys: {
|
|
19
|
+
type: 'array',
|
|
20
|
+
items: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
minLength: 0
|
|
23
|
+
},
|
|
24
|
+
uniqueItems: true
|
|
25
|
+
},
|
|
26
|
+
config: {
|
|
27
|
+
type: [
|
|
28
|
+
'string',
|
|
29
|
+
'object'
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
module.exports = settingsSchema;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const settingsSchema = {
|
|
2
|
+
type: 'object',
|
|
3
|
+
properties: {
|
|
4
|
+
classAttributes: {
|
|
5
|
+
type: 'array',
|
|
6
|
+
items: {
|
|
7
|
+
type: 'string'
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
classFunctions: {
|
|
11
|
+
type: 'array',
|
|
12
|
+
items: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
ignoredKeys: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
minLength: 0
|
|
21
|
+
},
|
|
22
|
+
uniqueItems: true
|
|
23
|
+
},
|
|
24
|
+
config: {
|
|
25
|
+
type: [
|
|
26
|
+
'string',
|
|
27
|
+
'object'
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { settingsSchema as default };
|
package/dist/settings.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var css = require('@master/css');
|
|
4
|
+
|
|
3
5
|
const settings = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
classAttributes: css.CLASS_ATTRIBUTES,
|
|
7
|
+
classFunctions: css.CLASS_FUNCTIONS,
|
|
8
|
+
classDeclarations: css.CLASS_DECLARATIONS,
|
|
6
9
|
ignoredKeys: [
|
|
7
10
|
'compoundVariants',
|
|
8
11
|
'defaultVariants'
|
package/dist/settings.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
declare const settings: {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
classAttributes: string[];
|
|
3
|
+
classFunctions: string[];
|
|
4
|
+
classDeclarations: string[];
|
|
4
5
|
ignoredKeys: string[];
|
|
5
6
|
config: string;
|
|
6
7
|
};
|
|
7
8
|
export default settings;
|
|
8
9
|
export interface Settings {
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
classAttributes?: string[];
|
|
11
|
+
classFunctions?: string[];
|
|
12
|
+
classDeclarations?: string[];
|
|
11
13
|
ignoredKeys: string[];
|
|
12
14
|
config: string | object;
|
|
13
15
|
}
|
package/dist/settings.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { CLASS_ATTRIBUTES, CLASS_FUNCTIONS, CLASS_DECLARATIONS } from '@master/css';
|
|
2
|
+
|
|
1
3
|
const settings = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
classAttributes: CLASS_ATTRIBUTES,
|
|
5
|
+
classFunctions: CLASS_FUNCTIONS,
|
|
6
|
+
classDeclarations: CLASS_DECLARATIONS,
|
|
4
7
|
ignoredKeys: [
|
|
5
8
|
'compoundVariants',
|
|
6
9
|
'defaultVariants'
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function defineVisitors({ context, settings
|
|
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('|')})$`);
|
|
4
7
|
const isFnNode = (node)=>{
|
|
5
8
|
let calleeName = '';
|
|
6
9
|
const calleeNode = node.callee || node.tag;
|
|
@@ -10,7 +13,7 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
10
13
|
if (calleeNode.type === 'MemberExpression') {
|
|
11
14
|
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
12
15
|
}
|
|
13
|
-
return
|
|
16
|
+
return classFunctionsRegex.test(calleeName);
|
|
14
17
|
};
|
|
15
18
|
const CallExpression = function(node) {
|
|
16
19
|
if (!isFnNode(node)) {
|
|
@@ -20,11 +23,10 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
20
23
|
visitNode(node, arg);
|
|
21
24
|
});
|
|
22
25
|
};
|
|
23
|
-
const classMatchingRegex = new RegExp(settings.classMatching);
|
|
24
26
|
const scriptVisitor = {
|
|
25
27
|
CallExpression,
|
|
26
28
|
JSXAttribute: function(node) {
|
|
27
|
-
if (!node.name || !
|
|
29
|
+
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
28
30
|
if (node.value && node.value.type === 'Literal') {
|
|
29
31
|
visitNode(node);
|
|
30
32
|
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
@@ -32,13 +34,13 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
36
|
SvelteAttribute: function(node) {
|
|
35
|
-
if (!node.key?.name || !
|
|
37
|
+
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
36
38
|
for (const eachValue of node.value){
|
|
37
39
|
visitNode(node, eachValue);
|
|
38
40
|
}
|
|
39
41
|
},
|
|
40
42
|
TextAttribute: function(node) {
|
|
41
|
-
if (!node.name || !
|
|
43
|
+
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
42
44
|
visitNode(node);
|
|
43
45
|
},
|
|
44
46
|
TaggedTemplateExpression: function(node) {
|
|
@@ -46,6 +48,21 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
46
48
|
visitNode(node, node.quasi);
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
51
|
+
},
|
|
52
|
+
VariableDeclaration: function(node) {
|
|
53
|
+
node.declarations.forEach((decl)=>{
|
|
54
|
+
console.log(decl);
|
|
55
|
+
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
56
|
+
visitNode(node, decl.init);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
ObjectExpression: function(node) {
|
|
61
|
+
node.properties.forEach((prop)=>{
|
|
62
|
+
if (prop.type === 'Property' && prop.key.type === 'Identifier' && classDeclarationsRegex.test(prop.key.name)) {
|
|
63
|
+
visitNode(node, prop.value);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
49
66
|
}
|
|
50
67
|
};
|
|
51
68
|
const templateBodyVisitor = {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/utils';
|
|
2
2
|
import type { RuleContext, RuleListener } from '@typescript-eslint/utils/ts-eslint';
|
|
3
3
|
import { Settings } from '../settings';
|
|
4
|
-
export default function defineVisitors({ context, settings
|
|
4
|
+
export default function defineVisitors({ context, settings }: {
|
|
5
5
|
context: RuleContext<any, any[]>;
|
|
6
6
|
settings: Settings;
|
|
7
|
-
options: any;
|
|
8
7
|
}, visitNode: (node: TSESTree.Node, args?: any) => void): RuleListener;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
function defineVisitors({ context, settings
|
|
1
|
+
function defineVisitors({ context, settings }, visitNode) {
|
|
2
|
+
const classAttributeRegex = new RegExp(`^(?:${settings.classAttributes.join('|')})$`);
|
|
3
|
+
const classFunctionsRegex = new RegExp(`^(?:${settings.classFunctions.join('|')})`);
|
|
4
|
+
const classDeclarationsRegex = new RegExp(`^(?:${settings.classDeclarations.join('|')})$`);
|
|
2
5
|
const isFnNode = (node)=>{
|
|
3
6
|
let calleeName = '';
|
|
4
7
|
const calleeNode = node.callee || node.tag;
|
|
@@ -8,7 +11,7 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
8
11
|
if (calleeNode.type === 'MemberExpression') {
|
|
9
12
|
calleeName = `${calleeNode.object.name}.${calleeNode.property.name}`;
|
|
10
13
|
}
|
|
11
|
-
return
|
|
14
|
+
return classFunctionsRegex.test(calleeName);
|
|
12
15
|
};
|
|
13
16
|
const CallExpression = function(node) {
|
|
14
17
|
if (!isFnNode(node)) {
|
|
@@ -18,11 +21,10 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
18
21
|
visitNode(node, arg);
|
|
19
22
|
});
|
|
20
23
|
};
|
|
21
|
-
const classMatchingRegex = new RegExp(settings.classMatching);
|
|
22
24
|
const scriptVisitor = {
|
|
23
25
|
CallExpression,
|
|
24
26
|
JSXAttribute: function(node) {
|
|
25
|
-
if (!node.name || !
|
|
27
|
+
if (!node.name || !classAttributeRegex.test(node.name.name)) return;
|
|
26
28
|
if (node.value && node.value.type === 'Literal') {
|
|
27
29
|
visitNode(node);
|
|
28
30
|
} else if (node.value && node.value.type === 'JSXExpressionContainer') {
|
|
@@ -30,13 +32,13 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
30
32
|
}
|
|
31
33
|
},
|
|
32
34
|
SvelteAttribute: function(node) {
|
|
33
|
-
if (!node.key?.name || !
|
|
35
|
+
if (!node.key?.name || !classAttributeRegex.test(node.key.name)) return;
|
|
34
36
|
for (const eachValue of node.value){
|
|
35
37
|
visitNode(node, eachValue);
|
|
36
38
|
}
|
|
37
39
|
},
|
|
38
40
|
TextAttribute: function(node) {
|
|
39
|
-
if (!node.name || !
|
|
41
|
+
if (!node.name || !classAttributeRegex.test(node.name)) return;
|
|
40
42
|
visitNode(node);
|
|
41
43
|
},
|
|
42
44
|
TaggedTemplateExpression: function(node) {
|
|
@@ -44,6 +46,21 @@ function defineVisitors({ context, settings, options }, visitNode) {
|
|
|
44
46
|
visitNode(node, node.quasi);
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
49
|
+
},
|
|
50
|
+
VariableDeclaration: function(node) {
|
|
51
|
+
node.declarations.forEach((decl)=>{
|
|
52
|
+
console.log(decl);
|
|
53
|
+
if (decl.id.type === 'Identifier' && classDeclarationsRegex.test(decl.id.name)) {
|
|
54
|
+
visitNode(node, decl.init);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
ObjectExpression: function(node) {
|
|
59
|
+
node.properties.forEach((prop)=>{
|
|
60
|
+
if (prop.type === 'Property' && prop.key.type === 'Identifier' && classDeclarationsRegex.test(prop.key.name)) {
|
|
61
|
+
visitNode(node, prop.value);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
47
64
|
}
|
|
48
65
|
};
|
|
49
66
|
const templateBodyVisitor = {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
|
|
2
2
|
export default function resolveContext(context: RuleContext<any, any[]>): {
|
|
3
3
|
settings: {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
classAttributes: string[];
|
|
5
|
+
classFunctions: string[];
|
|
6
|
+
classDeclarations: string[];
|
|
6
7
|
ignoredKeys: string[];
|
|
7
8
|
config: string;
|
|
8
9
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@master/eslint-plugin-css","type":"module","scripts":{"build":"techor build \"src/**/*.{js,ts}\"","dev":"pnpm build --watch","test":"jest","type-check":"tsc --noEmit","lint":"eslint src"},"keywords":["mastercss","eslint","eslintplugin"],"license":"MIT","description":"Master CSS ESLint Plugin","author":"Aoyue Design LLC.","funding":"https://css.master.co/docs/donate","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/eslint-plugin"},"sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","types":"./dist/index.d.ts"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/css":"^2.0.0-rc.
|
|
1
|
+
{"name":"@master/eslint-plugin-css","type":"module","scripts":{"build":"techor build \"src/**/*.{js,ts}\"","dev":"pnpm build --watch","test":"jest","type-check":"tsc --noEmit","lint":"eslint src"},"keywords":["mastercss","eslint","eslintplugin"],"license":"MIT","description":"Master CSS ESLint Plugin","author":"Aoyue Design LLC.","funding":"https://css.master.co/docs/donate","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/eslint-plugin"},"sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","types":"./dist/index.d.ts"}},"files":["dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/css":"^2.0.0-rc.29","@master/css-explore-config":"^2.0.0-rc.29","@master/css-validator":"^2.0.0-rc.29","@typescript-eslint/utils":"^7.7.0","synckit":"^0.9.0","typescript-eslint":"^7.7.0"},"devDependencies":{"@angular-eslint/template-parser":"^17.3.0","@master/css-explore-config":"^2.0.0-rc.29","@master/css-shared":"^2.0.0-rc.29","@types/node":"^20.12.7","@typescript-eslint/rule-tester":"^7.7.0","eslint":"^8.57.0","eslint-plugin-markdown":"^4.0.1","eslint-plugin-mdx":"^3.1.5","svelte-eslint-parser":"^0.34.1","ts-node":"^10.9.2","vue-eslint-parser":"^9.4.2"},"version":"2.0.0-rc.29"}
|