@lvce-editor/eslint-plugin-virtual-dom 18.11.0 → 18.13.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/dist/index.js +164 -56
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import json from '@eslint/json';
|
|
2
|
+
import { validRange, subset } from 'semver';
|
|
3
|
+
|
|
1
4
|
const isPropertyNode = node => {
|
|
2
5
|
return typeof node === 'object' && node !== null && 'type' in node && node.type === 'Property' && 'key' in node && 'value' in node && 'computed' in node;
|
|
3
6
|
};
|
|
@@ -93,7 +96,7 @@ const controlsAllowingChildren = new Set(['A', 'Button']);
|
|
|
93
96
|
const hasDirectName = node => {
|
|
94
97
|
return Boolean(getProperty(node, 'ariaLabel') || getProperty(node, 'ariaLabelledBy') || getProperty(node, 'title'));
|
|
95
98
|
};
|
|
96
|
-
const meta$
|
|
99
|
+
const meta$w = {
|
|
97
100
|
docs: {
|
|
98
101
|
description: 'Require a statically determinable accessible name for virtual-dom controls'
|
|
99
102
|
},
|
|
@@ -102,7 +105,7 @@ const meta$v = {
|
|
|
102
105
|
},
|
|
103
106
|
type: 'problem'
|
|
104
107
|
};
|
|
105
|
-
const create$
|
|
108
|
+
const create$w = context => {
|
|
106
109
|
return {
|
|
107
110
|
ObjectExpression(node) {
|
|
108
111
|
if (!isVirtualDomNode(node) || hasDirectName(node)) {
|
|
@@ -144,11 +147,11 @@ const create$v = context => {
|
|
|
144
147
|
|
|
145
148
|
const accessibleControlName = {
|
|
146
149
|
__proto__: null,
|
|
147
|
-
create: create$
|
|
148
|
-
meta: meta$
|
|
150
|
+
create: create$w,
|
|
151
|
+
meta: meta$w
|
|
149
152
|
};
|
|
150
153
|
|
|
151
|
-
const meta$
|
|
154
|
+
const meta$v = {
|
|
152
155
|
docs: {
|
|
153
156
|
description: 'Require an explicit role on clickable virtual-dom div nodes'
|
|
154
157
|
},
|
|
@@ -157,7 +160,7 @@ const meta$u = {
|
|
|
157
160
|
},
|
|
158
161
|
type: 'problem'
|
|
159
162
|
};
|
|
160
|
-
const create$
|
|
163
|
+
const create$v = context => {
|
|
161
164
|
return {
|
|
162
165
|
ObjectExpression(node) {
|
|
163
166
|
if (!isVirtualDomNode(node)) {
|
|
@@ -179,11 +182,11 @@ const create$u = context => {
|
|
|
179
182
|
|
|
180
183
|
const clickableDivNeedsRole = {
|
|
181
184
|
__proto__: null,
|
|
182
|
-
create: create$
|
|
183
|
-
meta: meta$
|
|
185
|
+
create: create$v,
|
|
186
|
+
meta: meta$v
|
|
184
187
|
};
|
|
185
188
|
|
|
186
|
-
const meta$
|
|
189
|
+
const meta$u = {
|
|
187
190
|
docs: {
|
|
188
191
|
description: 'Require static mergeClassNames calls inside functions to be hoisted to module scope'
|
|
189
192
|
},
|
|
@@ -257,7 +260,7 @@ const isStatic = (sourceCode, node, seen = new Set()) => {
|
|
|
257
260
|
return false;
|
|
258
261
|
}
|
|
259
262
|
};
|
|
260
|
-
const create$
|
|
263
|
+
const create$u = context => {
|
|
261
264
|
return {
|
|
262
265
|
CallExpression(node) {
|
|
263
266
|
if (node.type !== 'CallExpression' || node.optional || !isMergeClassNames(context.sourceCode, node.callee)) {
|
|
@@ -281,11 +284,11 @@ const create$t = context => {
|
|
|
281
284
|
|
|
282
285
|
const hoistClassNames = {
|
|
283
286
|
__proto__: null,
|
|
284
|
-
create: create$
|
|
285
|
-
meta: meta$
|
|
287
|
+
create: create$u,
|
|
288
|
+
meta: meta$u
|
|
286
289
|
};
|
|
287
290
|
|
|
288
|
-
const meta$
|
|
291
|
+
const meta$t = {
|
|
289
292
|
docs: {
|
|
290
293
|
description: 'Require static virtual-dom nodes created inside functions to be hoisted to module scope'
|
|
291
294
|
},
|
|
@@ -420,7 +423,7 @@ const isStaticExpression = (sourceCode, node) => {
|
|
|
420
423
|
return false;
|
|
421
424
|
}
|
|
422
425
|
};
|
|
423
|
-
const create$
|
|
426
|
+
const create$t = context => {
|
|
424
427
|
return {
|
|
425
428
|
ObjectExpression(node) {
|
|
426
429
|
if (!isVirtualDomElement(node)) {
|
|
@@ -445,11 +448,11 @@ const create$s = context => {
|
|
|
445
448
|
|
|
446
449
|
const hoistStaticNodes = {
|
|
447
450
|
__proto__: null,
|
|
448
|
-
create: create$
|
|
449
|
-
meta: meta$
|
|
451
|
+
create: create$t,
|
|
452
|
+
meta: meta$t
|
|
450
453
|
};
|
|
451
454
|
|
|
452
|
-
const meta$
|
|
455
|
+
const meta$s = {
|
|
453
456
|
docs: {
|
|
454
457
|
description: 'Disallow conditional spreads in virtual-dom arrays'
|
|
455
458
|
},
|
|
@@ -467,7 +470,7 @@ const isVirtualDomArray$1 = node => {
|
|
|
467
470
|
const addsVirtualDomChildren = spread => {
|
|
468
471
|
return isVirtualDomArray$1(spread.argument.consequent) || isVirtualDomArray$1(spread.argument.alternate);
|
|
469
472
|
};
|
|
470
|
-
const create$
|
|
473
|
+
const create$s = context => {
|
|
471
474
|
return {
|
|
472
475
|
ArrayExpression(node) {
|
|
473
476
|
const conditionalSpreads = node.elements.filter(isConditionalSpread);
|
|
@@ -486,11 +489,11 @@ const create$r = context => {
|
|
|
486
489
|
|
|
487
490
|
const noConditionalSpread = {
|
|
488
491
|
__proto__: null,
|
|
489
|
-
create: create$
|
|
490
|
-
meta: meta$
|
|
492
|
+
create: create$s,
|
|
493
|
+
meta: meta$s
|
|
491
494
|
};
|
|
492
495
|
|
|
493
|
-
const meta$
|
|
496
|
+
const meta$r = {
|
|
494
497
|
docs: {
|
|
495
498
|
description: 'Disallow element helpers for creating virtual DOM nodes'
|
|
496
499
|
},
|
|
@@ -499,7 +502,7 @@ const meta$q = {
|
|
|
499
502
|
},
|
|
500
503
|
type: 'problem'
|
|
501
504
|
};
|
|
502
|
-
const create$
|
|
505
|
+
const create$r = context => {
|
|
503
506
|
return {
|
|
504
507
|
CallExpression(node) {
|
|
505
508
|
if (!isIdentifierNode(node.callee) || node.callee.name !== 'element' || !getVirtualDomElementName(node.arguments[0])) {
|
|
@@ -515,11 +518,11 @@ const create$q = context => {
|
|
|
515
518
|
|
|
516
519
|
const noElementHelper = {
|
|
517
520
|
__proto__: null,
|
|
518
|
-
create: create$
|
|
519
|
-
meta: meta$
|
|
521
|
+
create: create$r,
|
|
522
|
+
meta: meta$r
|
|
520
523
|
};
|
|
521
524
|
|
|
522
|
-
const meta$
|
|
525
|
+
const meta$q = {
|
|
523
526
|
docs: {
|
|
524
527
|
description: 'Disallow empty ARIA values in virtual-dom nodes'
|
|
525
528
|
},
|
|
@@ -531,7 +534,7 @@ const meta$p = {
|
|
|
531
534
|
const isAriaProperty = name => {
|
|
532
535
|
return /^aria[A-Z]/.test(name);
|
|
533
536
|
};
|
|
534
|
-
const create$
|
|
537
|
+
const create$q = context => {
|
|
535
538
|
return {
|
|
536
539
|
ObjectExpression(node) {
|
|
537
540
|
if (!isVirtualDomNode(node)) {
|
|
@@ -556,11 +559,11 @@ const create$p = context => {
|
|
|
556
559
|
|
|
557
560
|
const noEmptyAria = {
|
|
558
561
|
__proto__: null,
|
|
559
|
-
create: create$
|
|
560
|
-
meta: meta$
|
|
562
|
+
create: create$q,
|
|
563
|
+
meta: meta$q
|
|
561
564
|
};
|
|
562
565
|
|
|
563
|
-
const meta$
|
|
566
|
+
const meta$p = {
|
|
564
567
|
docs: {
|
|
565
568
|
description: 'Disallow empty className values in virtual-dom nodes'
|
|
566
569
|
},
|
|
@@ -569,7 +572,7 @@ const meta$o = {
|
|
|
569
572
|
},
|
|
570
573
|
type: 'problem'
|
|
571
574
|
};
|
|
572
|
-
const create$
|
|
575
|
+
const create$p = context => {
|
|
573
576
|
return {
|
|
574
577
|
ObjectExpression(node) {
|
|
575
578
|
if (!isVirtualDomNode(node)) {
|
|
@@ -589,11 +592,11 @@ const create$o = context => {
|
|
|
589
592
|
|
|
590
593
|
const noEmptyClassName = {
|
|
591
594
|
__proto__: null,
|
|
592
|
-
create: create$
|
|
593
|
-
meta: meta$
|
|
595
|
+
create: create$p,
|
|
596
|
+
meta: meta$p
|
|
594
597
|
};
|
|
595
598
|
|
|
596
|
-
const meta$
|
|
599
|
+
const meta$o = {
|
|
597
600
|
docs: {
|
|
598
601
|
description: 'Disallow inline event handlers in virtual-dom nodes'
|
|
599
602
|
},
|
|
@@ -608,7 +611,7 @@ const isEventPropertyName = name => {
|
|
|
608
611
|
const isInlineEventHandler = node => {
|
|
609
612
|
return isStringLiteral(node) || isTemplateLiteralNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
|
|
610
613
|
};
|
|
611
|
-
const create$
|
|
614
|
+
const create$o = context => {
|
|
612
615
|
return {
|
|
613
616
|
ObjectExpression(node) {
|
|
614
617
|
if (!isVirtualDomNode(node)) {
|
|
@@ -633,11 +636,11 @@ const create$n = context => {
|
|
|
633
636
|
|
|
634
637
|
const noInlineEventHandlers = {
|
|
635
638
|
__proto__: null,
|
|
636
|
-
create: create$
|
|
637
|
-
meta: meta$
|
|
639
|
+
create: create$o,
|
|
640
|
+
meta: meta$o
|
|
638
641
|
};
|
|
639
642
|
|
|
640
|
-
const meta$
|
|
643
|
+
const meta$n = {
|
|
641
644
|
docs: {
|
|
642
645
|
description: 'Disallow inline style attributes in virtual-dom nodes'
|
|
643
646
|
},
|
|
@@ -646,7 +649,7 @@ const meta$m = {
|
|
|
646
649
|
},
|
|
647
650
|
type: 'problem'
|
|
648
651
|
};
|
|
649
|
-
const create$
|
|
652
|
+
const create$n = context => {
|
|
650
653
|
return {
|
|
651
654
|
ObjectExpression(node) {
|
|
652
655
|
if (!isVirtualDomNode(node)) {
|
|
@@ -666,8 +669,8 @@ const create$m = context => {
|
|
|
666
669
|
|
|
667
670
|
const noInlineStyle = {
|
|
668
671
|
__proto__: null,
|
|
669
|
-
create: create$
|
|
670
|
-
meta: meta$
|
|
672
|
+
create: create$n,
|
|
673
|
+
meta: meta$n
|
|
671
674
|
};
|
|
672
675
|
|
|
673
676
|
const ignoredProperties$1 = new Set(['childCount', 'type']);
|
|
@@ -677,7 +680,7 @@ const isOptionalExpression = node => {
|
|
|
677
680
|
const isNullish = node => {
|
|
678
681
|
return isLiteralNode(node) && node.value === null || isIdentifierNode(node) && node.name === 'undefined' || isOptionalExpression(node);
|
|
679
682
|
};
|
|
680
|
-
const meta$
|
|
683
|
+
const meta$m = {
|
|
681
684
|
docs: {
|
|
682
685
|
description: 'Disallow nullish virtual-dom attribute values'
|
|
683
686
|
},
|
|
@@ -686,7 +689,7 @@ const meta$l = {
|
|
|
686
689
|
},
|
|
687
690
|
type: 'problem'
|
|
688
691
|
};
|
|
689
|
-
const create$
|
|
692
|
+
const create$m = context => {
|
|
690
693
|
return {
|
|
691
694
|
ObjectExpression(node) {
|
|
692
695
|
if (!isVirtualDomNode(node)) {
|
|
@@ -714,11 +717,11 @@ const create$l = context => {
|
|
|
714
717
|
|
|
715
718
|
const noNullishAttributeValues = {
|
|
716
719
|
__proto__: null,
|
|
717
|
-
create: create$
|
|
718
|
-
meta: meta$
|
|
720
|
+
create: create$m,
|
|
721
|
+
meta: meta$m
|
|
719
722
|
};
|
|
720
723
|
|
|
721
|
-
const meta$
|
|
724
|
+
const meta$l = {
|
|
722
725
|
docs: {
|
|
723
726
|
description: 'Disallow object-like attribute values in virtual-dom nodes'
|
|
724
727
|
},
|
|
@@ -731,7 +734,7 @@ const ignoredProperties = new Set(['childCount', 'type']);
|
|
|
731
734
|
const isObjectLikeAttributeValue = node => {
|
|
732
735
|
return isObjectExpressionNode(node) || isArrayExpressionNode(node) || isArrowFunctionExpressionNode(node) || isFunctionExpressionNode(node);
|
|
733
736
|
};
|
|
734
|
-
const create$
|
|
737
|
+
const create$l = context => {
|
|
735
738
|
return {
|
|
736
739
|
ObjectExpression(node) {
|
|
737
740
|
if (!isVirtualDomNode(node)) {
|
|
@@ -756,11 +759,11 @@ const create$k = context => {
|
|
|
756
759
|
|
|
757
760
|
const noObjectAttributeValues = {
|
|
758
761
|
__proto__: null,
|
|
759
|
-
create: create$
|
|
760
|
-
meta: meta$
|
|
762
|
+
create: create$l,
|
|
763
|
+
meta: meta$l
|
|
761
764
|
};
|
|
762
765
|
|
|
763
|
-
const meta$
|
|
766
|
+
const meta$k = {
|
|
764
767
|
docs: {
|
|
765
768
|
description: 'Disallow positive virtual-dom tabIndex values'
|
|
766
769
|
},
|
|
@@ -769,7 +772,7 @@ const meta$j = {
|
|
|
769
772
|
},
|
|
770
773
|
type: 'problem'
|
|
771
774
|
};
|
|
772
|
-
const create$
|
|
775
|
+
const create$k = context => {
|
|
773
776
|
return {
|
|
774
777
|
ObjectExpression(node) {
|
|
775
778
|
if (!isVirtualDomNode(node)) {
|
|
@@ -790,11 +793,11 @@ const create$j = context => {
|
|
|
790
793
|
|
|
791
794
|
const noPositiveTabIndex = {
|
|
792
795
|
__proto__: null,
|
|
793
|
-
create: create$
|
|
794
|
-
meta: meta$
|
|
796
|
+
create: create$k,
|
|
797
|
+
meta: meta$k
|
|
795
798
|
};
|
|
796
799
|
|
|
797
|
-
const meta$
|
|
800
|
+
const meta$j = {
|
|
798
801
|
docs: {
|
|
799
802
|
description: 'Disallow raw string children in virtual-dom arrays'
|
|
800
803
|
},
|
|
@@ -806,7 +809,7 @@ const meta$i = {
|
|
|
806
809
|
const isVirtualDomArray = node => {
|
|
807
810
|
return isArrayExpressionNode(node) && node.elements.some(element => isVirtualDomNode(element) || isTextCall(element));
|
|
808
811
|
};
|
|
809
|
-
const create$
|
|
812
|
+
const create$j = context => {
|
|
810
813
|
return {
|
|
811
814
|
ArrayExpression(node) {
|
|
812
815
|
if (!isVirtualDomArray(node)) {
|
|
@@ -826,6 +829,98 @@ const create$i = context => {
|
|
|
826
829
|
};
|
|
827
830
|
|
|
828
831
|
const noRawTextChildren = {
|
|
832
|
+
__proto__: null,
|
|
833
|
+
create: create$j,
|
|
834
|
+
meta: meta$j
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
const defaultRestrictions = {
|
|
838
|
+
eslint: '<10.10.0-0',
|
|
839
|
+
typescript: '>=6.0.0-0 <7.0.0-0'
|
|
840
|
+
};
|
|
841
|
+
const dependencySections = new Set(['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']);
|
|
842
|
+
const meta$i = {
|
|
843
|
+
docs: {
|
|
844
|
+
description: 'Disallow dependencies and version ranges outside the supported versions'
|
|
845
|
+
},
|
|
846
|
+
messages: {
|
|
847
|
+
forbidden: 'Dependency "{{name}}" is not allowed.',
|
|
848
|
+
unsupported: 'Dependency "{{name}}" must use a version range within "{{allowed}}"; received "{{version}}".'
|
|
849
|
+
},
|
|
850
|
+
schema: [{
|
|
851
|
+
additionalProperties: false,
|
|
852
|
+
properties: {
|
|
853
|
+
restrictions: {
|
|
854
|
+
additionalProperties: {
|
|
855
|
+
anyOf: [{
|
|
856
|
+
minLength: 1,
|
|
857
|
+
type: 'string'
|
|
858
|
+
}, {
|
|
859
|
+
enum: [false]
|
|
860
|
+
}]
|
|
861
|
+
},
|
|
862
|
+
type: 'object'
|
|
863
|
+
}
|
|
864
|
+
},
|
|
865
|
+
type: 'object'
|
|
866
|
+
}],
|
|
867
|
+
type: 'problem'
|
|
868
|
+
};
|
|
869
|
+
const create$i = context => {
|
|
870
|
+
const restrictions = {
|
|
871
|
+
...defaultRestrictions,
|
|
872
|
+
...context.options[0]?.restrictions
|
|
873
|
+
};
|
|
874
|
+
for (const [name, allowed] of Object.entries(restrictions)) {
|
|
875
|
+
if (allowed !== false && !validRange(allowed)) {
|
|
876
|
+
throw new Error(`Invalid allowed version range for dependency "${name}": ${allowed}`);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
Document(node) {
|
|
881
|
+
if (node.body?.type !== 'Object') {
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
884
|
+
for (const section of node.body.members) {
|
|
885
|
+
if (!dependencySections.has(section.name.value) || section.value.type !== 'Object') {
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
for (const dependency of section.value.members) {
|
|
889
|
+
const name = dependency.name.value;
|
|
890
|
+
if (Object.hasOwn(restrictions, name)) {
|
|
891
|
+
const allowed = restrictions[name];
|
|
892
|
+
if (allowed === false) {
|
|
893
|
+
context.report({
|
|
894
|
+
data: {
|
|
895
|
+
name
|
|
896
|
+
},
|
|
897
|
+
loc: dependency.name.loc,
|
|
898
|
+
messageId: 'forbidden'
|
|
899
|
+
});
|
|
900
|
+
} else {
|
|
901
|
+
const version = dependency.value.value;
|
|
902
|
+
if (typeof version !== 'string' || !validRange(version) || !subset(version, allowed, {
|
|
903
|
+
includePrerelease: true
|
|
904
|
+
})) {
|
|
905
|
+
context.report({
|
|
906
|
+
data: {
|
|
907
|
+
allowed,
|
|
908
|
+
name,
|
|
909
|
+
version: String(version)
|
|
910
|
+
},
|
|
911
|
+
loc: dependency.value.loc,
|
|
912
|
+
messageId: 'unsupported'
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
const noRestrictedDependencies = {
|
|
829
924
|
__proto__: null,
|
|
830
925
|
create: create$i,
|
|
831
926
|
meta: meta$i
|
|
@@ -1778,6 +1873,7 @@ const plugin = {
|
|
|
1778
1873
|
'no-object-attribute-values': noObjectAttributeValues,
|
|
1779
1874
|
'no-positive-tab-index': noPositiveTabIndex,
|
|
1780
1875
|
'no-raw-text-children': noRawTextChildren,
|
|
1876
|
+
'no-restricted-dependencies': noRestrictedDependencies,
|
|
1781
1877
|
'no-shared-event-listener-handlers': noSharedEventListenerHandlers,
|
|
1782
1878
|
'no-text-helper': noTextHelper,
|
|
1783
1879
|
'no-tree-helper': noTreeHelper,
|
|
@@ -1798,7 +1894,19 @@ const plugin = {
|
|
|
1798
1894
|
'valid-node-shape': validNodeShape
|
|
1799
1895
|
}
|
|
1800
1896
|
};
|
|
1801
|
-
const
|
|
1897
|
+
const recommendedDependencies = [{
|
|
1898
|
+
files: ['**/package.json'],
|
|
1899
|
+
language: 'json/json',
|
|
1900
|
+
plugins: {
|
|
1901
|
+
// @ts-ignore
|
|
1902
|
+
json,
|
|
1903
|
+
'virtual-dom': plugin
|
|
1904
|
+
},
|
|
1905
|
+
rules: {
|
|
1906
|
+
'virtual-dom/no-restricted-dependencies': 'error'
|
|
1907
|
+
}
|
|
1908
|
+
}];
|
|
1909
|
+
const recommended = [...recommendedDependencies, {
|
|
1802
1910
|
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
|
1803
1911
|
plugins: {
|
|
1804
1912
|
'virtual-dom': plugin
|
|
@@ -1856,4 +1964,4 @@ const strict = [...recommended, {
|
|
|
1856
1964
|
}
|
|
1857
1965
|
}];
|
|
1858
1966
|
|
|
1859
|
-
export { recommended as default, strict };
|
|
1967
|
+
export { recommended as default, recommendedDependencies, strict };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/eslint-plugin-virtual-dom",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.13.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,5 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"description": "ESLint rules for @lvce-editor/virtual-dom usage."
|
|
11
|
+
"description": "ESLint rules for @lvce-editor/virtual-dom usage.",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"semver": "^7.7.2"
|
|
14
|
+
}
|
|
12
15
|
}
|