@lvce-editor/eslint-plugin-virtual-dom 14.2.0 → 15.0.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.
Files changed (2) hide show
  1. package/dist/index.js +95 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -77,7 +77,7 @@ const isStringLiteral = node => {
77
77
  return isLiteralNode(node) && typeof node.value === 'string';
78
78
  };
79
79
 
80
- const meta$9 = {
80
+ const meta$a = {
81
81
  docs: {
82
82
  description: 'Require an explicit role on clickable virtual-dom div nodes'
83
83
  },
@@ -86,7 +86,7 @@ const meta$9 = {
86
86
  },
87
87
  type: 'problem'
88
88
  };
89
- const create$9 = context => {
89
+ const create$a = context => {
90
90
  return {
91
91
  ObjectExpression(node) {
92
92
  if (!isVirtualDomNode(node)) {
@@ -108,11 +108,11 @@ const create$9 = context => {
108
108
 
109
109
  const clickableDivNeedsRole = {
110
110
  __proto__: null,
111
- create: create$9,
112
- meta: meta$9
111
+ create: create$a,
112
+ meta: meta$a
113
113
  };
114
114
 
115
- const meta$8 = {
115
+ const meta$9 = {
116
116
  docs: {
117
117
  description: 'Disallow empty ARIA values in virtual-dom nodes'
118
118
  },
@@ -124,7 +124,7 @@ const meta$8 = {
124
124
  const isAriaProperty = name => {
125
125
  return /^aria[A-Z]/.test(name);
126
126
  };
127
- const create$8 = context => {
127
+ const create$9 = context => {
128
128
  return {
129
129
  ObjectExpression(node) {
130
130
  if (!isVirtualDomNode(node)) {
@@ -149,11 +149,11 @@ const create$8 = context => {
149
149
 
150
150
  const noEmptyAria = {
151
151
  __proto__: null,
152
- create: create$8,
153
- meta: meta$8
152
+ create: create$9,
153
+ meta: meta$9
154
154
  };
155
155
 
156
- const meta$7 = {
156
+ const meta$8 = {
157
157
  docs: {
158
158
  description: 'Disallow empty className values in virtual-dom nodes'
159
159
  },
@@ -162,7 +162,7 @@ const meta$7 = {
162
162
  },
163
163
  type: 'problem'
164
164
  };
165
- const create$7 = context => {
165
+ const create$8 = context => {
166
166
  return {
167
167
  ObjectExpression(node) {
168
168
  if (!isVirtualDomNode(node)) {
@@ -182,11 +182,11 @@ const create$7 = context => {
182
182
 
183
183
  const noEmptyClassName = {
184
184
  __proto__: null,
185
- create: create$7,
186
- meta: meta$7
185
+ create: create$8,
186
+ meta: meta$8
187
187
  };
188
188
 
189
- const meta$6 = {
189
+ const meta$7 = {
190
190
  docs: {
191
191
  description: 'Disallow inline event handlers in virtual-dom nodes'
192
192
  },
@@ -201,7 +201,7 @@ const isEventPropertyName = name => {
201
201
  const isInlineEventHandler = node => {
202
202
  return isStringLiteral(node) || isTemplateLiteralNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
203
203
  };
204
- const create$6 = context => {
204
+ const create$7 = context => {
205
205
  return {
206
206
  ObjectExpression(node) {
207
207
  if (!isVirtualDomNode(node)) {
@@ -226,11 +226,11 @@ const create$6 = context => {
226
226
 
227
227
  const noInlineEventHandlers = {
228
228
  __proto__: null,
229
- create: create$6,
230
- meta: meta$6
229
+ create: create$7,
230
+ meta: meta$7
231
231
  };
232
232
 
233
- const meta$5 = {
233
+ const meta$6 = {
234
234
  docs: {
235
235
  description: 'Disallow inline style attributes in virtual-dom nodes'
236
236
  },
@@ -239,7 +239,7 @@ const meta$5 = {
239
239
  },
240
240
  type: 'problem'
241
241
  };
242
- const create$5 = context => {
242
+ const create$6 = context => {
243
243
  return {
244
244
  ObjectExpression(node) {
245
245
  if (!isVirtualDomNode(node)) {
@@ -259,11 +259,11 @@ const create$5 = context => {
259
259
 
260
260
  const noInlineStyle = {
261
261
  __proto__: null,
262
- create: create$5,
263
- meta: meta$5
262
+ create: create$6,
263
+ meta: meta$6
264
264
  };
265
265
 
266
- const meta$4 = {
266
+ const meta$5 = {
267
267
  docs: {
268
268
  description: 'Disallow object-like attribute values in virtual-dom nodes'
269
269
  },
@@ -276,7 +276,7 @@ const ignoredProperties = new Set(['childCount', 'type']);
276
276
  const isObjectLikeAttributeValue = node => {
277
277
  return isObjectExpressionNode(node) || isArrayExpressionNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
278
278
  };
279
- const create$4 = context => {
279
+ const create$5 = context => {
280
280
  return {
281
281
  ObjectExpression(node) {
282
282
  if (!isVirtualDomNode(node)) {
@@ -301,11 +301,11 @@ const create$4 = context => {
301
301
 
302
302
  const noObjectAttributeValues = {
303
303
  __proto__: null,
304
- create: create$4,
305
- meta: meta$4
304
+ create: create$5,
305
+ meta: meta$5
306
306
  };
307
307
 
308
- const meta$3 = {
308
+ const meta$4 = {
309
309
  docs: {
310
310
  description: 'Disallow raw string children in virtual-dom arrays'
311
311
  },
@@ -317,7 +317,7 @@ const meta$3 = {
317
317
  const isVirtualDomArray = node => {
318
318
  return isArrayExpressionNode(node) && node.elements.some(element => isVirtualDomNode(element) || isTextCall(element));
319
319
  };
320
- const create$3 = context => {
320
+ const create$4 = context => {
321
321
  return {
322
322
  ArrayExpression(node) {
323
323
  if (!isVirtualDomArray(node)) {
@@ -338,11 +338,11 @@ const create$3 = context => {
338
338
 
339
339
  const noRawTextChildren = {
340
340
  __proto__: null,
341
- create: create$3,
342
- meta: meta$3
341
+ create: create$4,
342
+ meta: meta$4
343
343
  };
344
344
 
345
- const meta$2 = {
345
+ const meta$3 = {
346
346
  docs: {
347
347
  description: 'Prefer virtual-dom constants over raw type, role, aria boolean, and tabIndex values'
348
348
  },
@@ -357,7 +357,7 @@ const meta$2 = {
357
357
  const isAriaBooleanProperty = name => {
358
358
  return /^aria[A-Z]/.test(name);
359
359
  };
360
- const create$2 = context => {
360
+ const create$3 = context => {
361
361
  return {
362
362
  ObjectExpression(node) {
363
363
  if (!isVirtualDomNode(node)) {
@@ -405,8 +405,8 @@ const create$2 = context => {
405
405
 
406
406
  const preferConstants = {
407
407
  __proto__: null,
408
- create: create$2,
409
- meta: meta$2
408
+ create: create$3,
409
+ meta: meta$3
410
410
  };
411
411
 
412
412
  const isClassNameKey = node => {
@@ -433,7 +433,7 @@ const isManualClassNameConcatenation = node => {
433
433
  }
434
434
  return isStringLiteralWithSpace(node.left) || isStringLiteralWithSpace(node.right) || isManualClassNameConcatenation(node.left) || isManualClassNameConcatenation(node.right);
435
435
  };
436
- const meta$1 = {
436
+ const meta$2 = {
437
437
  docs: {
438
438
  description: 'Prefer mergeClassNames for composing virtual-dom className values'
439
439
  },
@@ -442,7 +442,7 @@ const meta$1 = {
442
442
  },
443
443
  type: 'suggestion'
444
444
  };
445
- const create$1 = context => {
445
+ const create$2 = context => {
446
446
  return {
447
447
  Property(node) {
448
448
  if (!isPropertyNode(node) || !isClassNameKey(node) || !isManualClassNameConcatenation(node.value)) {
@@ -457,6 +457,65 @@ const create$1 = context => {
457
457
  };
458
458
 
459
459
  const preferMergeClassNames = {
460
+ __proto__: null,
461
+ create: create$2,
462
+ meta: meta$2
463
+ };
464
+
465
+ const meta$1 = {
466
+ docs: {
467
+ description: 'Prefer destructuring state properties before use'
468
+ },
469
+ messages: {
470
+ preferStateDestructuring: 'Prefer destructuring from state instead of using state.{{property}}.'
471
+ },
472
+ type: 'suggestion'
473
+ };
474
+ const isIdentifier = node => {
475
+ return node?.type === 'Identifier';
476
+ };
477
+ const isWriteExpression = node => {
478
+ const {
479
+ parent
480
+ } = node;
481
+ if (!parent) {
482
+ return false;
483
+ }
484
+ if (parent.type === 'AssignmentExpression' && parent.left === node) {
485
+ return true;
486
+ }
487
+ if (parent.type === 'UpdateExpression' && parent.argument === node) {
488
+ return true;
489
+ }
490
+ return parent.type === 'UnaryExpression' && parent.operator === 'delete' && parent.argument === node;
491
+ };
492
+ const create$1 = context => {
493
+ return {
494
+ MemberExpression(node) {
495
+ if (node.computed) {
496
+ return;
497
+ }
498
+ if (!isIdentifier(node.object) || node.object.name !== 'state') {
499
+ return;
500
+ }
501
+ if (!isIdentifier(node.property)) {
502
+ return;
503
+ }
504
+ if (isWriteExpression(node)) {
505
+ return;
506
+ }
507
+ context.report({
508
+ data: {
509
+ property: node.property.name
510
+ },
511
+ messageId: 'preferStateDestructuring',
512
+ node
513
+ });
514
+ }
515
+ };
516
+ };
517
+
518
+ const preferStateDestructuring = {
460
519
  __proto__: null,
461
520
  create: create$1,
462
521
  meta: meta$1
@@ -587,6 +646,7 @@ const plugin = {
587
646
  'no-raw-text-children': noRawTextChildren,
588
647
  'prefer-constants': preferConstants,
589
648
  'prefer-merge-class-names': preferMergeClassNames,
649
+ 'prefer-state-destructuring': preferStateDestructuring,
590
650
  'valid-child-count': validChildCount
591
651
  }
592
652
  };
@@ -605,6 +665,7 @@ const recommended = [{
605
665
  'virtual-dom/no-raw-text-children': 'error',
606
666
  'virtual-dom/prefer-constants': 'error',
607
667
  'virtual-dom/prefer-merge-class-names': 'error',
668
+ 'virtual-dom/prefer-state-destructuring': 'error',
608
669
  'virtual-dom/valid-child-count': 'error'
609
670
  }
610
671
  }];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-virtual-dom",
3
- "version": "14.2.0",
3
+ "version": "15.0.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",