@agilebot/eslint-plugin 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +11 -11
- package/lib/index.js +43 -58
- package/lib/rules/import/enforce-icon-alias.js +42 -42
- package/lib/rules/import/monorepo.js +49 -49
- package/lib/rules/intl/id-missing.js +111 -111
- package/lib/rules/intl/id-prefix.js +103 -103
- package/lib/rules/intl/id-unused.js +123 -123
- package/lib/rules/intl/no-default.js +63 -63
- package/lib/rules/others/no-unnecessary-template-literals.js +38 -38
- package/lib/rules/react/better-exhaustive-deps.js +1923 -1923
- package/lib/rules/react/hook-use-ref.js +35 -35
- package/lib/rules/react/no-inline-styles.js +87 -87
- package/lib/rules/react/prefer-named-property-access.js +105 -105
- package/lib/rules/tss/class-naming.js +43 -43
- package/lib/rules/tss/no-color-value.js +58 -58
- package/lib/rules/tss/unused-classes.js +108 -108
- package/lib/util/intl.js +127 -127
- package/lib/util/settings.js +14 -14
- package/lib/util/translations.js +66 -66
- package/lib/util/tss.js +109 -109
- package/package.json +2 -2
package/lib/util/tss.js
CHANGED
@@ -1,109 +1,109 @@
|
|
1
|
-
// Helper function to get the basic identifier from various node types
|
2
|
-
function getBasicIdentifier(node) {
|
3
|
-
if (node.type === 'Identifier') {
|
4
|
-
// Return the identifier name for simple cases like classes.foo
|
5
|
-
return node.name;
|
6
|
-
}
|
7
|
-
|
8
|
-
if (node.type === 'Literal') {
|
9
|
-
// Return the literal value for cases like classes['foo']
|
10
|
-
return node.value;
|
11
|
-
}
|
12
|
-
|
13
|
-
if (node.type === 'TemplateLiteral') {
|
14
|
-
// Handle template literals, e.g., classes[`foo`]
|
15
|
-
if (node.expressions.length > 0) {
|
16
|
-
// Template literals with expressions, e.g., classes[`foo${bar}`]
|
17
|
-
return null;
|
18
|
-
}
|
19
|
-
return node.quasis[0].value.raw;
|
20
|
-
}
|
21
|
-
|
22
|
-
// Handle other cases, e.g., classes['foo' + bar]
|
23
|
-
return null;
|
24
|
-
}
|
25
|
-
|
26
|
-
// Helper function to recursively get the base identifier from a MemberExpression node
|
27
|
-
function getBaseIdentifier(node) {
|
28
|
-
switch (node.type) {
|
29
|
-
case 'Identifier': {
|
30
|
-
return node;
|
31
|
-
}
|
32
|
-
case 'CallExpression': {
|
33
|
-
return getBaseIdentifier(node.callee);
|
34
|
-
}
|
35
|
-
case 'MemberExpression': {
|
36
|
-
return getBaseIdentifier(node.object);
|
37
|
-
}
|
38
|
-
// No default
|
39
|
-
}
|
40
|
-
return null;
|
41
|
-
}
|
42
|
-
|
43
|
-
function getStyesObj(node) {
|
44
|
-
const isMakeStyles = node.callee.name === 'makeStyles';
|
45
|
-
|
46
|
-
const isModernApi =
|
47
|
-
node.callee.type === 'MemberExpression' &&
|
48
|
-
node.callee.property.name === 'create' &&
|
49
|
-
getBaseIdentifier(node.callee.object) &&
|
50
|
-
getBaseIdentifier(node.callee.object).name === 'tss';
|
51
|
-
|
52
|
-
if (!isMakeStyles && !isModernApi) {
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
|
56
|
-
const styles = (() => {
|
57
|
-
if (isMakeStyles) {
|
58
|
-
return node.parent.arguments[0];
|
59
|
-
}
|
60
|
-
|
61
|
-
if (isModernApi) {
|
62
|
-
return node.callee.parent.arguments[0];
|
63
|
-
}
|
64
|
-
})();
|
65
|
-
|
66
|
-
if (!styles) {
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
|
70
|
-
switch (styles.type) {
|
71
|
-
case 'ObjectExpression':
|
72
|
-
return styles;
|
73
|
-
case 'ArrowFunctionExpression':
|
74
|
-
{
|
75
|
-
const { body } = styles;
|
76
|
-
|
77
|
-
switch (body.type) {
|
78
|
-
case 'ObjectExpression':
|
79
|
-
return body;
|
80
|
-
case 'BlockStatement': {
|
81
|
-
let stylesObj;
|
82
|
-
|
83
|
-
body.body.forEach(bodyNode => {
|
84
|
-
if (
|
85
|
-
bodyNode.type === 'ReturnStatement' &&
|
86
|
-
bodyNode.argument.type === 'ObjectExpression'
|
87
|
-
) {
|
88
|
-
stylesObj = bodyNode.argument;
|
89
|
-
}
|
90
|
-
});
|
91
|
-
|
92
|
-
return stylesObj;
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
break;
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
function isCamelCase(value) {
|
101
|
-
return /^[a-z][a-zA-Z0-9]*$/.test(value);
|
102
|
-
}
|
103
|
-
|
104
|
-
module.exports = {
|
105
|
-
getBasicIdentifier: getBasicIdentifier,
|
106
|
-
getBaseIdentifier: getBaseIdentifier,
|
107
|
-
getStyesObj: getStyesObj,
|
108
|
-
isCamelCase: isCamelCase
|
109
|
-
};
|
1
|
+
// Helper function to get the basic identifier from various node types
|
2
|
+
function getBasicIdentifier(node) {
|
3
|
+
if (node.type === 'Identifier') {
|
4
|
+
// Return the identifier name for simple cases like classes.foo
|
5
|
+
return node.name;
|
6
|
+
}
|
7
|
+
|
8
|
+
if (node.type === 'Literal') {
|
9
|
+
// Return the literal value for cases like classes['foo']
|
10
|
+
return node.value;
|
11
|
+
}
|
12
|
+
|
13
|
+
if (node.type === 'TemplateLiteral') {
|
14
|
+
// Handle template literals, e.g., classes[`foo`]
|
15
|
+
if (node.expressions.length > 0) {
|
16
|
+
// Template literals with expressions, e.g., classes[`foo${bar}`]
|
17
|
+
return null;
|
18
|
+
}
|
19
|
+
return node.quasis[0].value.raw;
|
20
|
+
}
|
21
|
+
|
22
|
+
// Handle other cases, e.g., classes['foo' + bar]
|
23
|
+
return null;
|
24
|
+
}
|
25
|
+
|
26
|
+
// Helper function to recursively get the base identifier from a MemberExpression node
|
27
|
+
function getBaseIdentifier(node) {
|
28
|
+
switch (node.type) {
|
29
|
+
case 'Identifier': {
|
30
|
+
return node;
|
31
|
+
}
|
32
|
+
case 'CallExpression': {
|
33
|
+
return getBaseIdentifier(node.callee);
|
34
|
+
}
|
35
|
+
case 'MemberExpression': {
|
36
|
+
return getBaseIdentifier(node.object);
|
37
|
+
}
|
38
|
+
// No default
|
39
|
+
}
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
|
43
|
+
function getStyesObj(node) {
|
44
|
+
const isMakeStyles = node.callee.name === 'makeStyles';
|
45
|
+
|
46
|
+
const isModernApi =
|
47
|
+
node.callee.type === 'MemberExpression' &&
|
48
|
+
node.callee.property.name === 'create' &&
|
49
|
+
getBaseIdentifier(node.callee.object) &&
|
50
|
+
getBaseIdentifier(node.callee.object).name === 'tss';
|
51
|
+
|
52
|
+
if (!isMakeStyles && !isModernApi) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
const styles = (() => {
|
57
|
+
if (isMakeStyles) {
|
58
|
+
return node.parent.arguments[0];
|
59
|
+
}
|
60
|
+
|
61
|
+
if (isModernApi) {
|
62
|
+
return node.callee.parent.arguments[0];
|
63
|
+
}
|
64
|
+
})();
|
65
|
+
|
66
|
+
if (!styles) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
|
70
|
+
switch (styles.type) {
|
71
|
+
case 'ObjectExpression':
|
72
|
+
return styles;
|
73
|
+
case 'ArrowFunctionExpression':
|
74
|
+
{
|
75
|
+
const { body } = styles;
|
76
|
+
|
77
|
+
switch (body.type) {
|
78
|
+
case 'ObjectExpression':
|
79
|
+
return body;
|
80
|
+
case 'BlockStatement': {
|
81
|
+
let stylesObj;
|
82
|
+
|
83
|
+
body.body.forEach(bodyNode => {
|
84
|
+
if (
|
85
|
+
bodyNode.type === 'ReturnStatement' &&
|
86
|
+
bodyNode.argument.type === 'ObjectExpression'
|
87
|
+
) {
|
88
|
+
stylesObj = bodyNode.argument;
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
return stylesObj;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
function isCamelCase(value) {
|
101
|
+
return /^[a-z][a-zA-Z0-9]*$/.test(value);
|
102
|
+
}
|
103
|
+
|
104
|
+
module.exports = {
|
105
|
+
getBasicIdentifier: getBasicIdentifier,
|
106
|
+
getBaseIdentifier: getBaseIdentifier,
|
107
|
+
getStyesObj: getStyesObj,
|
108
|
+
isCamelCase: isCamelCase
|
109
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-plugin",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.2",
|
4
4
|
"description": "Agilebot's ESLint plugin",
|
5
5
|
"main": "lib",
|
6
6
|
"license": "MIT",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"@typescript-eslint/utils": "^7.6.0",
|
21
21
|
"eslint-plugin-react": "^7.34.1",
|
22
22
|
"fast-glob": "^3.3.2",
|
23
|
-
"@agilebot/eslint-utils": "0.2.
|
23
|
+
"@agilebot/eslint-utils": "0.2.2"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"eslint": "^7.0.0 || ^8.0.0"
|