eslint-plugin-hyoban 0.9.2 → 0.9.4

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.2";
3
+ var version = "0.9.4";
4
4
 
5
5
  const hasDocs = new Set([
6
6
  'prefer-tailwind-icons'
@@ -297,6 +297,7 @@ function normalizeSegment(value) {
297
297
  return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '').toLowerCase();
298
298
  }
299
299
  function getIconClass(importName, source, config, globalPrefix) {
300
+ const prefix = config.prefix ?? globalPrefix;
300
301
  config.sourceRegex.lastIndex = 0;
301
302
  config.nameRegex.lastIndex = 0;
302
303
  const sourceMatch = source.match(config.sourceRegex);
@@ -314,7 +315,7 @@ function getIconClass(importName, source, config, globalPrefix) {
314
315
  const iconNamePart = camelToKebab(getGroup('name', 'icon') || importName) || camelToKebab(importName);
315
316
  const variantPart = normalizeSegment(getGroup('variant'));
316
317
  return [
317
- globalPrefix,
318
+ prefix,
318
319
  iconSetPart,
319
320
  iconNamePart,
320
321
  variantPart
@@ -333,7 +334,8 @@ function normalizeLibraryConfig(config) {
333
334
  if (!nameRegex) return null;
334
335
  return {
335
336
  sourceRegex,
336
- nameRegex
337
+ nameRegex,
338
+ prefix: config.prefix
337
339
  };
338
340
  }
339
341
  function normalizeLibraryConfigs(configs) {
@@ -366,6 +368,7 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
366
368
  }
367
369
  if (classNameAttribute.value.type === 'JSXExpressionContainer') {
368
370
  const expression = classNameAttribute.value.expression;
371
+ if (expression.type === 'JSXEmptyExpression') return `{${JSON.stringify(classNames)}}`;
369
372
  if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier' && expression.callee.name === 'cn') {
370
373
  const existingArguments = expression.arguments.map((argument)=>sourceCode.getText(argument));
371
374
  const argumentsText = [
@@ -374,7 +377,9 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
374
377
  ].join(', ');
375
378
  return `{cn(${argumentsText})}`;
376
379
  }
377
- return null;
380
+ const expressionText = sourceCode.getText(expression);
381
+ const escapedClassNames = classNames.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${');
382
+ return `{\`${escapedClassNames} \${${expressionText}}\`}`;
378
383
  }
379
384
  return null;
380
385
  }
@@ -415,6 +420,9 @@ const rule = createEslintRule({
415
420
  },
416
421
  name: {
417
422
  type: 'string'
423
+ },
424
+ prefix: {
425
+ type: 'string'
418
426
  }
419
427
  },
420
428
  required: [
package/dist/index.d.cts CHANGED
@@ -7,6 +7,7 @@ type RuleModule<T extends readonly unknown[]> = Rule.RuleModule & {
7
7
  type LibraryConfig = {
8
8
  source: string;
9
9
  name?: string;
10
+ prefix?: string;
10
11
  };
11
12
  type UserOptions = {
12
13
  libraries?: LibraryConfig[];
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ type RuleModule<T extends readonly unknown[]> = Rule.RuleModule & {
7
7
  type LibraryConfig = {
8
8
  source: string;
9
9
  name?: string;
10
+ prefix?: string;
10
11
  };
11
12
  type UserOptions = {
12
13
  libraries?: LibraryConfig[];
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.9.2";
1
+ var version = "0.9.4";
2
2
 
3
3
  const hasDocs = new Set([
4
4
  'prefer-tailwind-icons'
@@ -295,6 +295,7 @@ function normalizeSegment(value) {
295
295
  return value.replaceAll('/', '-').replaceAll('_', '-').replace(/\s+/g, '').replace(/-+/g, '-').replace(/^-|-$/g, '').toLowerCase();
296
296
  }
297
297
  function getIconClass(importName, source, config, globalPrefix) {
298
+ const prefix = config.prefix ?? globalPrefix;
298
299
  config.sourceRegex.lastIndex = 0;
299
300
  config.nameRegex.lastIndex = 0;
300
301
  const sourceMatch = source.match(config.sourceRegex);
@@ -312,7 +313,7 @@ function getIconClass(importName, source, config, globalPrefix) {
312
313
  const iconNamePart = camelToKebab(getGroup('name', 'icon') || importName) || camelToKebab(importName);
313
314
  const variantPart = normalizeSegment(getGroup('variant'));
314
315
  return [
315
- globalPrefix,
316
+ prefix,
316
317
  iconSetPart,
317
318
  iconNamePart,
318
319
  variantPart
@@ -331,7 +332,8 @@ function normalizeLibraryConfig(config) {
331
332
  if (!nameRegex) return null;
332
333
  return {
333
334
  sourceRegex,
334
- nameRegex
335
+ nameRegex,
336
+ prefix: config.prefix
335
337
  };
336
338
  }
337
339
  function normalizeLibraryConfigs(configs) {
@@ -364,6 +366,7 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
364
366
  }
365
367
  if (classNameAttribute.value.type === 'JSXExpressionContainer') {
366
368
  const expression = classNameAttribute.value.expression;
369
+ if (expression.type === 'JSXEmptyExpression') return `{${JSON.stringify(classNames)}}`;
367
370
  if (expression.type === 'CallExpression' && expression.callee.type === 'Identifier' && expression.callee.name === 'cn') {
368
371
  const existingArguments = expression.arguments.map((argument)=>sourceCode.getText(argument));
369
372
  const argumentsText = [
@@ -372,7 +375,9 @@ function getClassNameValueText(classNames, classNameAttribute, sourceCode) {
372
375
  ].join(', ');
373
376
  return `{cn(${argumentsText})}`;
374
377
  }
375
- return null;
378
+ const expressionText = sourceCode.getText(expression);
379
+ const escapedClassNames = classNames.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${');
380
+ return `{\`${escapedClassNames} \${${expressionText}}\`}`;
376
381
  }
377
382
  return null;
378
383
  }
@@ -413,6 +418,9 @@ const rule = createEslintRule({
413
418
  },
414
419
  name: {
415
420
  type: 'string'
421
+ },
422
+ prefix: {
423
+ type: 'string'
416
424
  }
417
425
  },
418
426
  required: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-hyoban",
3
3
  "type": "module",
4
- "version": "0.9.2",
4
+ "version": "0.9.4",
5
5
  "description": "Hyoban extended ESLint rules.",
6
6
  "author": {
7
7
  "name": "hyoban",