@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.
@@ -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 "{{name}}" from "css". Use dot notation instead.',
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 === 'css') {
22
- for (const prop of node.id.properties) {
23
- if (prop.type === 'Property' &&
24
- prop.key.type === 'Identifier' &&
25
- (prop.key.name === 'create' ||
26
- prop.key.name === 'props' ||
27
- prop.key.name === 'keyframes' ||
28
- prop.key.name === 'viewTransition' ||
29
- prop.key.name === 'createStatic' ||
30
- prop.key.name === 'createTheme')) {
31
- context.report({
32
- node: prop,
33
- messageId: 'noDestructure',
34
- data: { name: prop.key.name },
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
- if (node.callee.type === 'MemberExpression' &&
39
- 'name' in node.callee.object &&
40
- 'name' in node.callee.property) {
41
- const objectName = node.callee.object.name;
42
- const propertyName = node.callee.property.name;
43
- if (objectName === 'css') {
44
- const fullName = `${objectName}.${propertyName}`;
45
- if (propertyName === 'create' ||
46
- propertyName === 'keyframes' ||
47
- propertyName === 'viewTransition' ||
48
- propertyName === 'createStatic' ||
49
- propertyName === 'createTheme') {
50
- context.report({
51
- node,
52
- messageId: 'noInnerCall',
53
- data: { name: fullName },
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "6.1.1",
3
+ "version": "6.1.2",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",