eslint-plugin-hyoban 0.9.0 → 0.9.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/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
2
 
3
- var version = "0.9.0";
3
+ var version = "0.9.2";
4
4
 
5
5
  const hasDocs = new Set([
6
6
  'prefer-tailwind-icons'
@@ -294,7 +294,7 @@ function hasRegexMatch(value, regex) {
294
294
  return regex.test(value);
295
295
  }
296
296
  function normalizeSegment(value) {
297
- return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '');
297
+ return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '').toLowerCase();
298
298
  }
299
299
  function getIconClass(importName, source, config, globalPrefix) {
300
300
  config.sourceRegex.lastIndex = 0;
@@ -365,10 +365,18 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
365
365
  return `{${JSON.stringify(merged)}}`;
366
366
  }
367
367
  if (classNameAttribute.value.type === 'JSXExpressionContainer') {
368
- const expression = sourceCode.getText(classNameAttribute.value.expression);
369
- return `{[${JSON.stringify(classNames)}, ${expression}].filter(Boolean).join(' ')}`;
368
+ const expression = classNameAttribute.value.expression;
369
+ if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier' && expression.callee.name === 'cn') {
370
+ const existingArguments = expression.arguments.map((argument)=>sourceCode.getText(argument));
371
+ const argumentsText = [
372
+ JSON.stringify(classNames),
373
+ ...existingArguments
374
+ ].join(', ');
375
+ return `{cn(${argumentsText})}`;
376
+ }
377
+ return null;
370
378
  }
371
- return `{${JSON.stringify(classNames)}}`;
379
+ return null;
372
380
  }
373
381
  function hasRuntimeReference(sourceCode, specifier) {
374
382
  try {
@@ -494,6 +502,7 @@ const rule = createEslintRule({
494
502
  iconClass,
495
503
  ...mappedClasses
496
504
  ].filter(Boolean).join(' ');
505
+ const classValue = getClassNameValueText(classesToAdd, classNameAttribute, sourceCode);
497
506
  if (node.parent.type !== 'JSXElement') return;
498
507
  context.report({
499
508
  node,
@@ -503,31 +512,32 @@ const rule = createEslintRule({
503
512
  componentName: iconInfo.localName,
504
513
  source: iconInfo.source
505
514
  },
506
- suggest: [
507
- {
508
- messageId: 'preferTailwindIcon',
509
- data: {
510
- iconClass,
511
- componentName: iconInfo.localName,
512
- source: iconInfo.source
513
- },
514
- fix (fixer) {
515
- const classValue = getClassNameValueText(classesToAdd, classNameAttribute, sourceCode);
516
- const otherAttributes = node.attributes.filter((attribute)=>{
517
- if (attribute === classNameAttribute) return false;
518
- if (attribute.type !== 'JSXAttribute') return true;
519
- return !consumedMappedAttributes.has(attribute);
520
- }).map((attribute)=>sourceCode.getText(attribute)).join(' ');
521
- const attrsText = otherAttributes ? `className=${classValue} ${otherAttributes}` : `className=${classValue}`;
522
- if (node.selfClosing) return fixer.replaceText(node.parent, `<span ${attrsText} />`);
523
- const fixes = [
524
- fixer.replaceText(node, `<span ${attrsText}>`)
525
- ];
526
- if (node.parent.closingElement) fixes.push(fixer.replaceText(node.parent.closingElement, '</span>'));
527
- return fixes;
515
+ ...classValue ? {
516
+ suggest: [
517
+ {
518
+ messageId: 'preferTailwindIcon',
519
+ data: {
520
+ iconClass,
521
+ componentName: iconInfo.localName,
522
+ source: iconInfo.source
523
+ },
524
+ fix (fixer) {
525
+ const otherAttributes = node.attributes.filter((attribute)=>{
526
+ if (attribute === classNameAttribute) return false;
527
+ if (attribute.type !== 'JSXAttribute') return true;
528
+ return !consumedMappedAttributes.has(attribute);
529
+ }).map((attribute)=>sourceCode.getText(attribute)).join(' ');
530
+ const attrsText = otherAttributes ? `className=${classValue} ${otherAttributes}` : `className=${classValue}`;
531
+ if (node.selfClosing) return fixer.replaceText(node.parent, `<span ${attrsText} />`);
532
+ const fixes = [
533
+ fixer.replaceText(node, `<span ${attrsText}>`)
534
+ ];
535
+ if (node.parent.closingElement) fixes.push(fixer.replaceText(node.parent.closingElement, '</span>'));
536
+ return fixes;
537
+ }
528
538
  }
529
- }
530
- ]
539
+ ]
540
+ } : {}
531
541
  });
532
542
  },
533
543
  'Program:exit': function() {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.9.0";
1
+ var version = "0.9.2";
2
2
 
3
3
  const hasDocs = new Set([
4
4
  'prefer-tailwind-icons'
@@ -292,7 +292,7 @@ function hasRegexMatch(value, regex) {
292
292
  return regex.test(value);
293
293
  }
294
294
  function normalizeSegment(value) {
295
- return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '');
295
+ return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '').toLowerCase();
296
296
  }
297
297
  function getIconClass(importName, source, config, globalPrefix) {
298
298
  config.sourceRegex.lastIndex = 0;
@@ -363,10 +363,18 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
363
363
  return `{${JSON.stringify(merged)}}`;
364
364
  }
365
365
  if (classNameAttribute.value.type === 'JSXExpressionContainer') {
366
- const expression = sourceCode.getText(classNameAttribute.value.expression);
367
- return `{[${JSON.stringify(classNames)}, ${expression}].filter(Boolean).join(' ')}`;
366
+ const expression = classNameAttribute.value.expression;
367
+ if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier' && expression.callee.name === 'cn') {
368
+ const existingArguments = expression.arguments.map((argument)=>sourceCode.getText(argument));
369
+ const argumentsText = [
370
+ JSON.stringify(classNames),
371
+ ...existingArguments
372
+ ].join(', ');
373
+ return `{cn(${argumentsText})}`;
374
+ }
375
+ return null;
368
376
  }
369
- return `{${JSON.stringify(classNames)}}`;
377
+ return null;
370
378
  }
371
379
  function hasRuntimeReference(sourceCode, specifier) {
372
380
  try {
@@ -492,6 +500,7 @@ const rule = createEslintRule({
492
500
  iconClass,
493
501
  ...mappedClasses
494
502
  ].filter(Boolean).join(' ');
503
+ const classValue = getClassNameValueText(classesToAdd, classNameAttribute, sourceCode);
495
504
  if (node.parent.type !== 'JSXElement') return;
496
505
  context.report({
497
506
  node,
@@ -501,31 +510,32 @@ const rule = createEslintRule({
501
510
  componentName: iconInfo.localName,
502
511
  source: iconInfo.source
503
512
  },
504
- suggest: [
505
- {
506
- messageId: 'preferTailwindIcon',
507
- data: {
508
- iconClass,
509
- componentName: iconInfo.localName,
510
- source: iconInfo.source
511
- },
512
- fix (fixer) {
513
- const classValue = getClassNameValueText(classesToAdd, classNameAttribute, sourceCode);
514
- const otherAttributes = node.attributes.filter((attribute)=>{
515
- if (attribute === classNameAttribute) return false;
516
- if (attribute.type !== 'JSXAttribute') return true;
517
- return !consumedMappedAttributes.has(attribute);
518
- }).map((attribute)=>sourceCode.getText(attribute)).join(' ');
519
- const attrsText = otherAttributes ? `className=${classValue} ${otherAttributes}` : `className=${classValue}`;
520
- if (node.selfClosing) return fixer.replaceText(node.parent, `<span ${attrsText} />`);
521
- const fixes = [
522
- fixer.replaceText(node, `<span ${attrsText}>`)
523
- ];
524
- if (node.parent.closingElement) fixes.push(fixer.replaceText(node.parent.closingElement, '</span>'));
525
- return fixes;
513
+ ...classValue ? {
514
+ suggest: [
515
+ {
516
+ messageId: 'preferTailwindIcon',
517
+ data: {
518
+ iconClass,
519
+ componentName: iconInfo.localName,
520
+ source: iconInfo.source
521
+ },
522
+ fix (fixer) {
523
+ const otherAttributes = node.attributes.filter((attribute)=>{
524
+ if (attribute === classNameAttribute) return false;
525
+ if (attribute.type !== 'JSXAttribute') return true;
526
+ return !consumedMappedAttributes.has(attribute);
527
+ }).map((attribute)=>sourceCode.getText(attribute)).join(' ');
528
+ const attrsText = otherAttributes ? `className=${classValue} ${otherAttributes}` : `className=${classValue}`;
529
+ if (node.selfClosing) return fixer.replaceText(node.parent, `<span ${attrsText} />`);
530
+ const fixes = [
531
+ fixer.replaceText(node, `<span ${attrsText}>`)
532
+ ];
533
+ if (node.parent.closingElement) fixes.push(fixer.replaceText(node.parent.closingElement, '</span>'));
534
+ return fixes;
535
+ }
526
536
  }
527
- }
528
- ]
537
+ ]
538
+ } : {}
529
539
  });
530
540
  },
531
541
  'Program:exit': function() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-hyoban",
3
3
  "type": "module",
4
- "version": "0.9.0",
4
+ "version": "0.9.2",
5
5
  "description": "Hyoban extended ESLint rules.",
6
6
  "author": {
7
7
  "name": "hyoban",