@plumeria/eslint-plugin 13.1.4 → 13.2.0

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 CHANGED
@@ -42,7 +42,7 @@ Disallow destructuring APIs.
42
42
 
43
43
  ### no-inline-object
44
44
 
45
- Disallow passing inline object to `styleName` and `css.use()`. Only compiled styles from `css.create()` are allowed.
45
+ Disallow passing inline object to `styleName`, `css.use()` and `css.variants()`. Only compiled styles from `css.create()` are allowed.
46
46
 
47
47
  ### no-inner-call
48
48
 
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.noInlineObject = void 0;
4
+ function isPlumeriaMemberCall(node, aliases, method) {
5
+ const callee = node.callee;
6
+ if (callee.type === 'MemberExpression') {
7
+ if (callee.object.type !== 'Identifier')
8
+ return false;
9
+ if (callee.property.type !== 'Identifier')
10
+ return false;
11
+ return (aliases[callee.object.name] === 'NAMESPACE' &&
12
+ callee.property.name === method);
13
+ }
14
+ if (callee.type === 'Identifier') {
15
+ return aliases[callee.name] === method;
16
+ }
17
+ return false;
18
+ }
4
19
  exports.noInlineObject = {
5
20
  meta: {
6
21
  type: 'problem',
@@ -10,44 +25,90 @@ exports.noInlineObject = {
10
25
  messages: {
11
26
  noInlineObjectInStyleName: 'Do not pass inline objects to styleName. It only accepts compiled styles from css.create().',
12
27
  noInlineObjectInCssUse: 'Do not pass inline objects to css.use(). It only accepts compiled styles from css.create().',
28
+ noInlineObjectInCssVariants: 'Do not pass inline objects to css.variants(). It only accepts compiled styles from css.create().',
13
29
  },
14
30
  schema: [],
15
31
  },
16
32
  create(context) {
17
- function isInsideOtherCall(node) {
18
- let current = node.parent;
19
- while (current && current.type !== 'JSXAttribute') {
20
- if (current.type === 'CallExpression') {
21
- const callee = current.callee;
22
- if (callee.type === 'MemberExpression' &&
23
- callee.object.type === 'Identifier' &&
24
- callee.object.name === 'css' &&
25
- callee.property.type === 'Identifier' &&
26
- callee.property.name === 'use') {
27
- return false;
33
+ const plumeriaAliases = {};
34
+ return {
35
+ ImportDeclaration(node) {
36
+ if (node.source.value === '@plumeria/core') {
37
+ node.specifiers.forEach((specifier) => {
38
+ if (specifier.type === 'ImportNamespaceSpecifier') {
39
+ plumeriaAliases[specifier.local.name] = 'NAMESPACE';
40
+ }
41
+ else if (specifier.type === 'ImportDefaultSpecifier') {
42
+ plumeriaAliases[specifier.local.name] = 'NAMESPACE';
43
+ }
44
+ else {
45
+ const spec = specifier;
46
+ const importedName = spec.imported.type === 'Identifier'
47
+ ? spec.imported.name
48
+ : String(spec.imported.value);
49
+ plumeriaAliases[specifier.local.name] = importedName;
50
+ }
51
+ });
52
+ }
53
+ },
54
+ JSXAttribute(node) {
55
+ if (node.name.type === 'JSXIdentifier' &&
56
+ node.name.name === 'styleName') {
57
+ const value = node.value;
58
+ if (value?.type === 'JSXExpressionContainer') {
59
+ const expr = value.expression;
60
+ if (expr.type === 'ObjectExpression') {
61
+ context.report({
62
+ node: expr,
63
+ messageId: 'noInlineObjectInStyleName',
64
+ });
65
+ }
66
+ else if (expr.type === 'ArrayExpression') {
67
+ expr.elements.forEach((el) => {
68
+ if (el?.type === 'ObjectExpression') {
69
+ context.report({
70
+ node: el,
71
+ messageId: 'noInlineObjectInStyleName',
72
+ });
73
+ }
74
+ });
75
+ }
28
76
  }
29
- return true;
30
77
  }
31
- current = current.parent;
32
- }
33
- return false;
34
- }
35
- return {
36
- 'JSXAttribute[name.name="styleName"] ObjectExpression'(node) {
37
- if (isInsideOtherCall(node))
38
- return;
39
- context.report({
40
- node,
41
- messageId: 'noInlineObjectInStyleName',
42
- });
43
78
  },
44
- 'CallExpression[callee.object.name="css"][callee.property.name="use"] ObjectExpression'(node) {
45
- if (isInsideOtherCall(node))
46
- return;
47
- context.report({
48
- node,
49
- messageId: 'noInlineObjectInCssUse',
50
- });
79
+ CallExpression(node) {
80
+ const callNode = node;
81
+ if (isPlumeriaMemberCall(callNode, plumeriaAliases, 'use')) {
82
+ callNode.arguments.forEach((arg) => {
83
+ if (arg.type === 'ObjectExpression') {
84
+ context.report({
85
+ node: arg,
86
+ messageId: 'noInlineObjectInCssUse',
87
+ });
88
+ }
89
+ });
90
+ }
91
+ if (isPlumeriaMemberCall(callNode, plumeriaAliases, 'variants')) {
92
+ const config = callNode.arguments[0];
93
+ if (config?.type !== 'ObjectExpression')
94
+ return;
95
+ config.properties.forEach((prop) => {
96
+ if (prop.type !== 'Property')
97
+ return;
98
+ if (prop.value.type !== 'ObjectExpression')
99
+ return;
100
+ prop.value.properties.forEach((nested) => {
101
+ if (nested.type !== 'Property')
102
+ return;
103
+ if (nested.value.type === 'ObjectExpression') {
104
+ context.report({
105
+ node: nested.value,
106
+ messageId: 'noInlineObjectInCssVariants',
107
+ });
108
+ }
109
+ });
110
+ });
111
+ }
51
112
  },
52
113
  };
53
114
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "13.1.4",
3
+ "version": "13.2.0",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "devDependencies": {
44
44
  "@types/eslint": "^9.6.1",
45
45
  "@types/estree": "^1.0.9",
46
+ "@types/estree-jsx": "^1.0.5",
46
47
  "@typescript-eslint/parser": "^8.60.0",
47
48
  "eslint": "^10.4.0"
48
49
  },