@plumeria/eslint-plugin 6.1.1 → 6.1.2
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/rules/no-destructure.js +41 -17
- package/dist/rules/no-inner-call.js +50 -18
- package/package.json +1 -1
|
@@ -8,31 +8,55 @@ exports.noDestructure = {
|
|
|
8
8
|
description: 'Disallow destructuring css.props and css.global',
|
|
9
9
|
},
|
|
10
10
|
messages: {
|
|
11
|
-
noDestructure: 'Do not destructure "{{
|
|
11
|
+
noDestructure: 'Do not destructure "{{property}}" from "{{object}}". Use dot notation instead.',
|
|
12
12
|
},
|
|
13
13
|
schema: [],
|
|
14
14
|
},
|
|
15
15
|
create(context) {
|
|
16
|
+
const plumeriaAliases = {};
|
|
16
17
|
return {
|
|
18
|
+
ImportDeclaration(node) {
|
|
19
|
+
if (node.source.value === '@plumeria/core') {
|
|
20
|
+
node.specifiers.forEach((specifier) => {
|
|
21
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
22
|
+
plumeriaAliases[specifier.local.name] = 'NAMESPACE';
|
|
23
|
+
}
|
|
24
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
25
|
+
plumeriaAliases[specifier.local.name] = 'NAMESPACE';
|
|
26
|
+
}
|
|
27
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
28
|
+
const importedName = specifier.imported.type === 'Identifier'
|
|
29
|
+
? specifier.imported.name
|
|
30
|
+
: String(specifier.imported.value);
|
|
31
|
+
plumeriaAliases[specifier.local.name] = importedName;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
},
|
|
17
36
|
VariableDeclarator(node) {
|
|
18
37
|
if (node.id.type === 'ObjectPattern' &&
|
|
19
38
|
node.init &&
|
|
20
|
-
node.init.type === 'Identifier'
|
|
21
|
-
node.init.name
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(prop.key.
|
|
26
|
-
prop.key.name
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
node.init.type === 'Identifier') {
|
|
40
|
+
const initName = node.init.name;
|
|
41
|
+
const alias = plumeriaAliases[initName];
|
|
42
|
+
if (alias === 'NAMESPACE') {
|
|
43
|
+
for (const prop of node.id.properties) {
|
|
44
|
+
if (prop.type === 'Property' && prop.key.type === 'Identifier') {
|
|
45
|
+
const keyName = prop.key.name;
|
|
46
|
+
if (keyName === 'create' ||
|
|
47
|
+
keyName === 'createStatic' ||
|
|
48
|
+
keyName === 'createTheme' ||
|
|
49
|
+
keyName === 'keyframes' ||
|
|
50
|
+
keyName === 'viewTransition' ||
|
|
51
|
+
keyName === 'variants' ||
|
|
52
|
+
keyName === 'props') {
|
|
53
|
+
context.report({
|
|
54
|
+
node: prop,
|
|
55
|
+
messageId: 'noDestructure',
|
|
56
|
+
data: { property: keyName, object: initName },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
}
|
|
38
62
|
}
|
|
@@ -14,7 +14,26 @@ exports.noInnerCall = {
|
|
|
14
14
|
},
|
|
15
15
|
create(context) {
|
|
16
16
|
let functionDepth = 0;
|
|
17
|
+
const plumeriaAliases = {};
|
|
17
18
|
return {
|
|
19
|
+
ImportDeclaration(node) {
|
|
20
|
+
if (node.source.value === '@plumeria/core') {
|
|
21
|
+
node.specifiers.forEach((specifier) => {
|
|
22
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
23
|
+
plumeriaAliases[specifier.local.name] = 'NAMESPACE';
|
|
24
|
+
}
|
|
25
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
26
|
+
plumeriaAliases[specifier.local.name] = 'NAMESPACE';
|
|
27
|
+
}
|
|
28
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
29
|
+
const importedName = specifier.imported.type === 'Identifier'
|
|
30
|
+
? specifier.imported.name
|
|
31
|
+
: String(specifier.imported.value);
|
|
32
|
+
plumeriaAliases[specifier.local.name] = importedName;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
},
|
|
18
37
|
FunctionDeclaration() {
|
|
19
38
|
functionDepth++;
|
|
20
39
|
},
|
|
@@ -35,26 +54,39 @@ exports.noInnerCall = {
|
|
|
35
54
|
},
|
|
36
55
|
CallExpression(node) {
|
|
37
56
|
if (functionDepth > 0) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
const callee = node.callee;
|
|
58
|
+
let propertyName;
|
|
59
|
+
let fullName;
|
|
60
|
+
if (callee.type === 'MemberExpression' &&
|
|
61
|
+
callee.object.type === 'Identifier' &&
|
|
62
|
+
callee.property.type === 'Identifier') {
|
|
63
|
+
const objectName = callee.object.name;
|
|
64
|
+
const alias = plumeriaAliases[objectName];
|
|
65
|
+
if (alias === 'NAMESPACE') {
|
|
66
|
+
propertyName = callee.property.name;
|
|
67
|
+
fullName = `${objectName}.${propertyName}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (callee.type === 'Identifier') {
|
|
71
|
+
const name = callee.name;
|
|
72
|
+
const alias = plumeriaAliases[name];
|
|
73
|
+
if (alias && alias !== 'NAMESPACE') {
|
|
74
|
+
propertyName = alias;
|
|
75
|
+
fullName = name;
|
|
56
76
|
}
|
|
57
77
|
}
|
|
78
|
+
if (propertyName === 'create' ||
|
|
79
|
+
propertyName === 'createStatic' ||
|
|
80
|
+
propertyName === 'createTheme' ||
|
|
81
|
+
propertyName === 'keyframes' ||
|
|
82
|
+
propertyName === 'viewTransition' ||
|
|
83
|
+
propertyName === 'variants') {
|
|
84
|
+
context.report({
|
|
85
|
+
node,
|
|
86
|
+
messageId: 'noInnerCall',
|
|
87
|
+
data: { name: fullName || propertyName },
|
|
88
|
+
});
|
|
89
|
+
}
|
|
58
90
|
}
|
|
59
91
|
},
|
|
60
92
|
};
|