@lvce-editor/eslint-plugin-virtual-dom 17.0.0 → 17.0.1

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 +45 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -150,6 +150,13 @@ const isStaticIdentifier = (sourceCode, node) => {
150
150
  const variable = findVariable(sourceCode, node);
151
151
  return Boolean(variable && isStaticModuleVariable(variable));
152
152
  };
153
+ const isVirtualDomElement = node => {
154
+ if (!isVirtualDomNode(node) || !hasProperty(node, 'childCount')) {
155
+ return false;
156
+ }
157
+ const type = getProperty(node, 'type');
158
+ return Boolean(type && !isStringLiteral(type.value));
159
+ };
153
160
  const isStaticProperty = (sourceCode, node) => {
154
161
  if (node.type === 'SpreadElement' || node.kind !== 'init' || node.method) {
155
162
  return false;
@@ -190,7 +197,7 @@ const isStaticExpression = (sourceCode, node) => {
190
197
  const create$b = context => {
191
198
  return {
192
199
  ObjectExpression(node) {
193
- if (!isVirtualDomNode(node)) {
200
+ if (!isVirtualDomElement(node)) {
194
201
  return;
195
202
  }
196
203
  if (!context.sourceCode.getAncestors(node).some(isFunctionNode$1)) {
@@ -553,6 +560,9 @@ const preferLazyDateTimeFormat = {
553
560
  const isClassNameKey = node => {
554
561
  return getStaticPropertyName(node) === 'className';
555
562
  };
563
+ const isClassNameProperty = node => {
564
+ return isPropertyNode(node) && isClassNameKey(node);
565
+ };
556
566
  const isStringLiteralWithSpace = node => {
557
567
  return isStringLiteral(node) && /\s/.test(node.value);
558
568
  };
@@ -574,6 +584,24 @@ const isManualClassNameConcatenation = node => {
574
584
  }
575
585
  return isStringLiteralWithSpace(node.left) || isStringLiteralWithSpace(node.right) || isManualClassNameConcatenation(node.left) || isManualClassNameConcatenation(node.right);
576
586
  };
587
+ const hasClassNamesReference = node => {
588
+ if (isMemberExpressionNode(node)) {
589
+ return isIdentifierNode(node.object) && node.object.name === 'ClassNames' || hasClassNamesReference(node.object) || node.computed && hasClassNamesReference(node.property);
590
+ }
591
+ if (isBinaryExpressionNode(node)) {
592
+ return hasClassNamesReference(node.left) || hasClassNamesReference(node.right);
593
+ }
594
+ if (isTemplateLiteralNode(node)) {
595
+ return node.expressions.some(hasClassNamesReference);
596
+ }
597
+ return false;
598
+ };
599
+ const getParent = node => {
600
+ if (typeof node === 'object' && node !== null && 'parent' in node) {
601
+ return node.parent;
602
+ }
603
+ return undefined;
604
+ };
577
605
  const meta$2 = {
578
606
  docs: {
579
607
  description: 'Prefer mergeClassNames for composing virtual-dom className values'
@@ -584,7 +612,21 @@ const meta$2 = {
584
612
  type: 'suggestion'
585
613
  };
586
614
  const create$2 = context => {
615
+ const reportNamespacedClassNameComposition = node => {
616
+ if (!isManualClassNameConcatenation(node) || !hasClassNamesReference(node)) {
617
+ return;
618
+ }
619
+ const parent = getParent(node);
620
+ if (isManualClassNameConcatenation(parent) || isClassNameProperty(parent)) {
621
+ return;
622
+ }
623
+ context.report({
624
+ messageId: 'preferMergeClassNames',
625
+ node: node
626
+ });
627
+ };
587
628
  return {
629
+ BinaryExpression: reportNamespacedClassNameComposition,
588
630
  Property(node) {
589
631
  if (!isPropertyNode(node) || !isClassNameKey(node) || !isManualClassNameConcatenation(node.value)) {
590
632
  return;
@@ -593,7 +635,8 @@ const create$2 = context => {
593
635
  messageId: 'preferMergeClassNames',
594
636
  node: node.value
595
637
  });
596
- }
638
+ },
639
+ TemplateLiteral: reportNamespacedClassNameComposition
597
640
  };
598
641
  };
599
642
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-virtual-dom",
3
- "version": "17.0.0",
3
+ "version": "17.0.1",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",