@lvce-editor/eslint-plugin-virtual-dom 17.5.0 → 17.7.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 +143 -58
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -93,7 +93,7 @@ const controlsAllowingChildren = new Set(['A', 'Button']);
93
93
  const hasDirectName = node => {
94
94
  return Boolean(getProperty(node, 'ariaLabel') || getProperty(node, 'ariaLabelledBy') || getProperty(node, 'title'));
95
95
  };
96
- const meta$p = {
96
+ const meta$q = {
97
97
  docs: {
98
98
  description: 'Require a statically determinable accessible name for virtual-dom controls'
99
99
  },
@@ -102,7 +102,7 @@ const meta$p = {
102
102
  },
103
103
  type: 'problem'
104
104
  };
105
- const create$p = context => {
105
+ const create$q = context => {
106
106
  return {
107
107
  ObjectExpression(node) {
108
108
  if (!isVirtualDomNode(node) || hasDirectName(node)) {
@@ -144,11 +144,11 @@ const create$p = context => {
144
144
 
145
145
  const accessibleControlName = {
146
146
  __proto__: null,
147
- create: create$p,
148
- meta: meta$p
147
+ create: create$q,
148
+ meta: meta$q
149
149
  };
150
150
 
151
- const meta$o = {
151
+ const meta$p = {
152
152
  docs: {
153
153
  description: 'Require an explicit role on clickable virtual-dom div nodes'
154
154
  },
@@ -157,7 +157,7 @@ const meta$o = {
157
157
  },
158
158
  type: 'problem'
159
159
  };
160
- const create$o = context => {
160
+ const create$p = context => {
161
161
  return {
162
162
  ObjectExpression(node) {
163
163
  if (!isVirtualDomNode(node)) {
@@ -179,11 +179,11 @@ const create$o = context => {
179
179
 
180
180
  const clickableDivNeedsRole = {
181
181
  __proto__: null,
182
- create: create$o,
183
- meta: meta$o
182
+ create: create$p,
183
+ meta: meta$p
184
184
  };
185
185
 
186
- const meta$n = {
186
+ const meta$o = {
187
187
  docs: {
188
188
  description: 'Require static virtual-dom nodes created inside functions to be hoisted to module scope'
189
189
  },
@@ -221,6 +221,28 @@ const isStaticIdentifier = (sourceCode, node) => {
221
221
  const variable = findVariable(sourceCode, node);
222
222
  return Boolean(variable && isStaticModuleVariable(variable));
223
223
  };
224
+ const isMergeClassNamesImport = variable => {
225
+ return variable.defs.some(definition => {
226
+ if (definition.type !== 'ImportBinding' || definition.node.type !== 'ImportSpecifier') {
227
+ return false;
228
+ }
229
+ return (definition.node.imported.type === 'Identifier' ? definition.node.imported.name : definition.node.imported.value) === 'mergeClassNames';
230
+ });
231
+ };
232
+ const isNamespaceImport = variable => {
233
+ return variable.defs.some(definition => definition.type === 'ImportBinding' && definition.node.type === 'ImportNamespaceSpecifier');
234
+ };
235
+ const isMergeClassNamesCallee = (sourceCode, node) => {
236
+ if (node.type === 'Identifier') {
237
+ const variable = findVariable(sourceCode, node);
238
+ return Boolean(variable && isMergeClassNamesImport(variable));
239
+ }
240
+ if (node.type !== 'MemberExpression' || node.computed || node.object.type !== 'Identifier' || node.property.type !== 'Identifier' || node.property.name !== 'mergeClassNames') {
241
+ return false;
242
+ }
243
+ const variable = findVariable(sourceCode, node.object);
244
+ return Boolean(variable && isNamespaceImport(variable));
245
+ };
224
246
  const isPropertyMutation = (sourceCode, identifier) => {
225
247
  const ancestors = sourceCode.getAncestors(identifier);
226
248
  let current = identifier;
@@ -276,6 +298,8 @@ const isStaticExpression = (sourceCode, node) => {
276
298
  case 'BinaryExpression':
277
299
  case 'LogicalExpression':
278
300
  return isStaticExpression(sourceCode, node.left) && isStaticExpression(sourceCode, node.right);
301
+ case 'CallExpression':
302
+ return isMergeClassNamesCallee(sourceCode, node.callee) && node.arguments.every(argument => argument.type !== 'SpreadElement' && isStaticExpression(sourceCode, argument));
279
303
  case 'ConditionalExpression':
280
304
  return isStaticExpression(sourceCode, node.test) && isStaticExpression(sourceCode, node.consequent) && isStaticExpression(sourceCode, node.alternate);
281
305
  case 'Identifier':
@@ -294,7 +318,7 @@ const isStaticExpression = (sourceCode, node) => {
294
318
  return false;
295
319
  }
296
320
  };
297
- const create$n = context => {
321
+ const create$o = context => {
298
322
  return {
299
323
  ObjectExpression(node) {
300
324
  if (!isVirtualDomElement(node)) {
@@ -319,11 +343,11 @@ const create$n = context => {
319
343
 
320
344
  const hoistStaticNodes = {
321
345
  __proto__: null,
322
- create: create$n,
323
- meta: meta$n
346
+ create: create$o,
347
+ meta: meta$o
324
348
  };
325
349
 
326
- const meta$m = {
350
+ const meta$n = {
327
351
  docs: {
328
352
  description: 'Disallow conditional spreads in virtual-dom arrays'
329
353
  },
@@ -341,7 +365,7 @@ const isVirtualDomArray$1 = node => {
341
365
  const addsVirtualDomChildren = spread => {
342
366
  return isVirtualDomArray$1(spread.argument.consequent) || isVirtualDomArray$1(spread.argument.alternate);
343
367
  };
344
- const create$m = context => {
368
+ const create$n = context => {
345
369
  return {
346
370
  ArrayExpression(node) {
347
371
  const conditionalSpreads = node.elements.filter(isConditionalSpread);
@@ -360,11 +384,11 @@ const create$m = context => {
360
384
 
361
385
  const noConditionalSpread = {
362
386
  __proto__: null,
363
- create: create$m,
364
- meta: meta$m
387
+ create: create$n,
388
+ meta: meta$n
365
389
  };
366
390
 
367
- const meta$l = {
391
+ const meta$m = {
368
392
  docs: {
369
393
  description: 'Disallow empty ARIA values in virtual-dom nodes'
370
394
  },
@@ -376,7 +400,7 @@ const meta$l = {
376
400
  const isAriaProperty = name => {
377
401
  return /^aria[A-Z]/.test(name);
378
402
  };
379
- const create$l = context => {
403
+ const create$m = context => {
380
404
  return {
381
405
  ObjectExpression(node) {
382
406
  if (!isVirtualDomNode(node)) {
@@ -401,11 +425,11 @@ const create$l = context => {
401
425
 
402
426
  const noEmptyAria = {
403
427
  __proto__: null,
404
- create: create$l,
405
- meta: meta$l
428
+ create: create$m,
429
+ meta: meta$m
406
430
  };
407
431
 
408
- const meta$k = {
432
+ const meta$l = {
409
433
  docs: {
410
434
  description: 'Disallow empty className values in virtual-dom nodes'
411
435
  },
@@ -414,7 +438,7 @@ const meta$k = {
414
438
  },
415
439
  type: 'problem'
416
440
  };
417
- const create$k = context => {
441
+ const create$l = context => {
418
442
  return {
419
443
  ObjectExpression(node) {
420
444
  if (!isVirtualDomNode(node)) {
@@ -434,11 +458,11 @@ const create$k = context => {
434
458
 
435
459
  const noEmptyClassName = {
436
460
  __proto__: null,
437
- create: create$k,
438
- meta: meta$k
461
+ create: create$l,
462
+ meta: meta$l
439
463
  };
440
464
 
441
- const meta$j = {
465
+ const meta$k = {
442
466
  docs: {
443
467
  description: 'Disallow inline event handlers in virtual-dom nodes'
444
468
  },
@@ -453,7 +477,7 @@ const isEventPropertyName = name => {
453
477
  const isInlineEventHandler = node => {
454
478
  return isStringLiteral(node) || isTemplateLiteralNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
455
479
  };
456
- const create$j = context => {
480
+ const create$k = context => {
457
481
  return {
458
482
  ObjectExpression(node) {
459
483
  if (!isVirtualDomNode(node)) {
@@ -478,11 +502,11 @@ const create$j = context => {
478
502
 
479
503
  const noInlineEventHandlers = {
480
504
  __proto__: null,
481
- create: create$j,
482
- meta: meta$j
505
+ create: create$k,
506
+ meta: meta$k
483
507
  };
484
508
 
485
- const meta$i = {
509
+ const meta$j = {
486
510
  docs: {
487
511
  description: 'Disallow inline style attributes in virtual-dom nodes'
488
512
  },
@@ -491,7 +515,7 @@ const meta$i = {
491
515
  },
492
516
  type: 'problem'
493
517
  };
494
- const create$i = context => {
518
+ const create$j = context => {
495
519
  return {
496
520
  ObjectExpression(node) {
497
521
  if (!isVirtualDomNode(node)) {
@@ -511,8 +535,8 @@ const create$i = context => {
511
535
 
512
536
  const noInlineStyle = {
513
537
  __proto__: null,
514
- create: create$i,
515
- meta: meta$i
538
+ create: create$j,
539
+ meta: meta$j
516
540
  };
517
541
 
518
542
  const ignoredProperties$1 = new Set(['childCount', 'type']);
@@ -522,7 +546,7 @@ const isOptionalExpression = node => {
522
546
  const isNullish = node => {
523
547
  return isLiteralNode(node) && node.value === null || isIdentifierNode(node) && node.name === 'undefined' || isOptionalExpression(node);
524
548
  };
525
- const meta$h = {
549
+ const meta$i = {
526
550
  docs: {
527
551
  description: 'Disallow nullish virtual-dom attribute values'
528
552
  },
@@ -531,7 +555,7 @@ const meta$h = {
531
555
  },
532
556
  type: 'problem'
533
557
  };
534
- const create$h = context => {
558
+ const create$i = context => {
535
559
  return {
536
560
  ObjectExpression(node) {
537
561
  if (!isVirtualDomNode(node)) {
@@ -559,11 +583,11 @@ const create$h = context => {
559
583
 
560
584
  const noNullishAttributeValues = {
561
585
  __proto__: null,
562
- create: create$h,
563
- meta: meta$h
586
+ create: create$i,
587
+ meta: meta$i
564
588
  };
565
589
 
566
- const meta$g = {
590
+ const meta$h = {
567
591
  docs: {
568
592
  description: 'Disallow object-like attribute values in virtual-dom nodes'
569
593
  },
@@ -576,7 +600,7 @@ const ignoredProperties = new Set(['childCount', 'type']);
576
600
  const isObjectLikeAttributeValue = node => {
577
601
  return isObjectExpressionNode(node) || isArrayExpressionNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
578
602
  };
579
- const create$g = context => {
603
+ const create$h = context => {
580
604
  return {
581
605
  ObjectExpression(node) {
582
606
  if (!isVirtualDomNode(node)) {
@@ -601,11 +625,11 @@ const create$g = context => {
601
625
 
602
626
  const noObjectAttributeValues = {
603
627
  __proto__: null,
604
- create: create$g,
605
- meta: meta$g
628
+ create: create$h,
629
+ meta: meta$h
606
630
  };
607
631
 
608
- const meta$f = {
632
+ const meta$g = {
609
633
  docs: {
610
634
  description: 'Disallow positive virtual-dom tabIndex values'
611
635
  },
@@ -614,7 +638,7 @@ const meta$f = {
614
638
  },
615
639
  type: 'problem'
616
640
  };
617
- const create$f = context => {
641
+ const create$g = context => {
618
642
  return {
619
643
  ObjectExpression(node) {
620
644
  if (!isVirtualDomNode(node)) {
@@ -635,11 +659,11 @@ const create$f = context => {
635
659
 
636
660
  const noPositiveTabIndex = {
637
661
  __proto__: null,
638
- create: create$f,
639
- meta: meta$f
662
+ create: create$g,
663
+ meta: meta$g
640
664
  };
641
665
 
642
- const meta$e = {
666
+ const meta$f = {
643
667
  docs: {
644
668
  description: 'Disallow raw string children in virtual-dom arrays'
645
669
  },
@@ -651,7 +675,7 @@ const meta$e = {
651
675
  const isVirtualDomArray = node => {
652
676
  return isArrayExpressionNode(node) && node.elements.some(element => isVirtualDomNode(element) || isTextCall(element));
653
677
  };
654
- const create$e = context => {
678
+ const create$f = context => {
655
679
  return {
656
680
  ArrayExpression(node) {
657
681
  if (!isVirtualDomArray(node)) {
@@ -672,11 +696,11 @@ const create$e = context => {
672
696
 
673
697
  const noRawTextChildren = {
674
698
  __proto__: null,
675
- create: create$e,
676
- meta: meta$e
699
+ create: create$f,
700
+ meta: meta$f
677
701
  };
678
702
 
679
- const meta$d = {
703
+ const meta$e = {
680
704
  docs: {
681
705
  description: 'Require each virtual-dom event listener to call its dedicated handler'
682
706
  },
@@ -685,7 +709,7 @@ const meta$d = {
685
709
  },
686
710
  type: 'problem'
687
711
  };
688
- const create$d = context => {
712
+ const create$e = context => {
689
713
  return {
690
714
  ObjectExpression(node) {
691
715
  if (!isObjectExpressionNode(node)) {
@@ -715,11 +739,11 @@ const create$d = context => {
715
739
 
716
740
  const noSharedEventListenerHandlers = {
717
741
  __proto__: null,
718
- create: create$d,
719
- meta: meta$d
742
+ create: create$e,
743
+ meta: meta$e
720
744
  };
721
745
 
722
- const meta$c = {
746
+ const meta$d = {
723
747
  docs: {
724
748
  description: 'Prefer constants for single literal virtual-dom class names'
725
749
  },
@@ -728,7 +752,7 @@ const meta$c = {
728
752
  },
729
753
  type: 'suggestion'
730
754
  };
731
- const create$c = context => {
755
+ const create$d = context => {
732
756
  return {
733
757
  ObjectExpression(node) {
734
758
  if (!isVirtualDomNode(node)) {
@@ -748,11 +772,11 @@ const create$c = context => {
748
772
 
749
773
  const preferClassNameConstants = {
750
774
  __proto__: null,
751
- create: create$c,
752
- meta: meta$c
775
+ create: create$d,
776
+ meta: meta$d
753
777
  };
754
778
 
755
- const meta$b = {
779
+ const meta$c = {
756
780
  docs: {
757
781
  description: 'Prefer virtual-dom constants over raw type, role, aria boolean, and tabIndex values'
758
782
  },
@@ -768,7 +792,7 @@ const meta$b = {
768
792
  const isAriaBooleanProperty = name => {
769
793
  return /^aria[A-Z]/.test(name);
770
794
  };
771
- const create$b = context => {
795
+ const create$c = context => {
772
796
  return {
773
797
  ObjectExpression(node) {
774
798
  if (!isVirtualDomNode(node)) {
@@ -822,6 +846,65 @@ const create$b = context => {
822
846
  };
823
847
 
824
848
  const preferConstants = {
849
+ __proto__: null,
850
+ create: create$c,
851
+ meta: meta$c
852
+ };
853
+
854
+ const meta$b = {
855
+ docs: {
856
+ description: 'Prefer destructuring layout properties before use'
857
+ },
858
+ messages: {
859
+ preferLayoutDestructuring: 'Prefer destructuring from layout instead of using layout.{{property}}.'
860
+ },
861
+ type: 'suggestion'
862
+ };
863
+ const isIdentifier$1 = node => {
864
+ return node?.type === 'Identifier';
865
+ };
866
+ const isWriteExpression$1 = node => {
867
+ const {
868
+ parent
869
+ } = node;
870
+ if (!parent) {
871
+ return false;
872
+ }
873
+ if (parent.type === 'AssignmentExpression' && parent.left === node) {
874
+ return true;
875
+ }
876
+ if (parent.type === 'UpdateExpression' && parent.argument === node) {
877
+ return true;
878
+ }
879
+ return parent.type === 'UnaryExpression' && parent.operator === 'delete' && parent.argument === node;
880
+ };
881
+ const create$b = context => {
882
+ return {
883
+ MemberExpression(node) {
884
+ if (node.computed) {
885
+ return;
886
+ }
887
+ if (!isIdentifier$1(node.object) || node.object.name !== 'layout') {
888
+ return;
889
+ }
890
+ if (!isIdentifier$1(node.property)) {
891
+ return;
892
+ }
893
+ if (isWriteExpression$1(node)) {
894
+ return;
895
+ }
896
+ context.report({
897
+ data: {
898
+ property: node.property.name
899
+ },
900
+ messageId: 'preferLayoutDestructuring',
901
+ node
902
+ });
903
+ }
904
+ };
905
+ };
906
+
907
+ const preferLayoutDestructuring = {
825
908
  __proto__: null,
826
909
  create: create$b,
827
910
  meta: meta$b
@@ -1450,6 +1533,7 @@ const plugin = {
1450
1533
  'no-shared-event-listener-handlers': noSharedEventListenerHandlers,
1451
1534
  'prefer-class-name-constants': preferClassNameConstants,
1452
1535
  'prefer-constants': preferConstants,
1536
+ 'prefer-layout-destructuring': preferLayoutDestructuring,
1453
1537
  'prefer-lazy-date-time-format': preferLazyDateTimeFormat,
1454
1538
  'prefer-merge-class-names': preferMergeClassNames,
1455
1539
  'prefer-state-destructuring': preferStateDestructuring,
@@ -1480,6 +1564,7 @@ const recommended = [{
1480
1564
  'virtual-dom/no-raw-text-children': 'error',
1481
1565
  'virtual-dom/no-shared-event-listener-handlers': 'error',
1482
1566
  'virtual-dom/prefer-constants': 'error',
1567
+ 'virtual-dom/prefer-layout-destructuring': 'error',
1483
1568
  'virtual-dom/prefer-lazy-date-time-format': 'error',
1484
1569
  'virtual-dom/prefer-merge-class-names': 'error',
1485
1570
  'virtual-dom/prefer-state-destructuring': 'error',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-virtual-dom",
3
- "version": "17.5.0",
3
+ "version": "17.7.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",