@plumeria/eslint-plugin 7.0.0 → 7.0.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/README.md CHANGED
@@ -7,6 +7,7 @@ Below are the available rules and the recommended configuration.
7
7
 
8
8
  The `plugin:@plumeria/recommended` config enables the following:
9
9
 
10
+ - `@plumeria/no-combinator`: **error**
10
11
  - `@plumeria/no-destructure`: **error**
11
12
  - `@plumeria/no-inner-call`: **error**
12
13
  - `@plumeria/no-unused-keys`: **warn**
@@ -21,6 +22,10 @@ export default [plumeria.flatConfigs.recommended];
21
22
 
22
23
  ## Rules
23
24
 
25
+ ### no-combinator
26
+
27
+ Disallow combinators `>`, `+`, `~` and descendant combinator (space) unless inside functional pseudo-classes.
28
+
24
29
  ### no-destructure
25
30
 
26
31
  Disallow destructuring `css.create` and `css.props`, etc.
@@ -16,6 +16,9 @@ exports.noCombinator = {
16
16
  const plumeriaAliases = {};
17
17
  function isCombinatorAllowed(selector) {
18
18
  const s = selector.trim();
19
+ if (s.startsWith('@')) {
20
+ return true;
21
+ }
19
22
  const len = s.length;
20
23
  let i = 0;
21
24
  while (i < len) {
@@ -127,28 +130,38 @@ exports.noCombinator = {
127
130
  const propertyName = node.callee.property.type === 'Identifier'
128
131
  ? node.callee.property.name
129
132
  : null;
130
- if (propertyName === 'create' ||
131
- propertyName === 'createStatic' ||
132
- propertyName === 'variants') {
133
+ if (propertyName === 'create' || propertyName === 'variants') {
133
134
  node.arguments.forEach((arg) => {
134
135
  if (arg.type === 'ObjectExpression') {
135
136
  checkForCombinatorsRecursively(arg);
136
137
  }
137
138
  });
138
139
  }
140
+ else if (propertyName === 'createStatic') {
141
+ node.arguments.forEach((arg) => {
142
+ if (arg.type === 'ObjectExpression') {
143
+ checkCreateStaticValues(arg);
144
+ }
145
+ });
146
+ }
139
147
  }
140
148
  }
141
149
  else if (node.callee.type === 'Identifier') {
142
150
  const alias = plumeriaAliases[node.callee.name];
143
- if (alias === 'create' ||
144
- alias === 'createStatic' ||
145
- alias === 'variants') {
151
+ if (alias === 'create' || alias === 'variants') {
146
152
  node.arguments.forEach((arg) => {
147
153
  if (arg.type === 'ObjectExpression') {
148
154
  checkForCombinatorsRecursively(arg);
149
155
  }
150
156
  });
151
157
  }
158
+ else if (alias === 'createStatic') {
159
+ node.arguments.forEach((arg) => {
160
+ if (arg.type === 'ObjectExpression') {
161
+ checkCreateStaticValues(arg);
162
+ }
163
+ });
164
+ }
152
165
  }
153
166
  },
154
167
  };
@@ -163,31 +176,7 @@ exports.noCombinator = {
163
176
  keyName = String(prop.key.value);
164
177
  }
165
178
  if (keyName) {
166
- if (keyName.includes('>') ||
167
- keyName.includes('+') ||
168
- keyName.includes('~') ||
169
- keyName.includes(' ') ||
170
- keyName.includes('\t') ||
171
- keyName.includes('\n')) {
172
- if (!isCombinatorAllowed(keyName)) {
173
- let found = '';
174
- if (keyName.includes('>'))
175
- found = '>';
176
- else if (keyName.includes('+'))
177
- found = '+';
178
- else if (keyName.includes('~'))
179
- found = '~';
180
- else if (keyName.includes(' ') ||
181
- keyName.includes('\t') ||
182
- keyName.includes('\n'))
183
- found = '(space)';
184
- context.report({
185
- node: prop.key,
186
- messageId: 'noCombinator',
187
- data: { combinator: found },
188
- });
189
- }
190
- }
179
+ checkAndReport(keyName, prop.key);
191
180
  }
192
181
  if (prop.value.type === 'ObjectExpression') {
193
182
  checkForCombinatorsRecursively(prop.value);
@@ -195,5 +184,42 @@ exports.noCombinator = {
195
184
  }
196
185
  }
197
186
  }
187
+ function checkCreateStaticValues(node) {
188
+ for (const prop of node.properties) {
189
+ if (prop.type === 'Property') {
190
+ if (prop.value.type === 'Literal') {
191
+ const value = String(prop.value.value);
192
+ checkAndReport(value, prop.value);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ function checkAndReport(text, node) {
198
+ if (text.includes('>') ||
199
+ text.includes('+') ||
200
+ text.includes('~') ||
201
+ text.includes(' ') ||
202
+ text.includes('\t') ||
203
+ text.includes('\n')) {
204
+ if (!isCombinatorAllowed(text)) {
205
+ let found = '';
206
+ if (text.includes('>'))
207
+ found = '>';
208
+ else if (text.includes('+'))
209
+ found = '+';
210
+ else if (text.includes('~'))
211
+ found = '~';
212
+ else if (text.includes(' ') ||
213
+ text.includes('\t') ||
214
+ text.includes('\n'))
215
+ found = '(space)';
216
+ context.report({
217
+ node: node,
218
+ messageId: 'noCombinator',
219
+ data: { combinator: found },
220
+ });
221
+ }
222
+ }
223
+ }
198
224
  },
199
225
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",