Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-unnecessary-arbitrary-value overwrites intentional arbitrary values with design system classes #375

Open
CMWR421 opened this issue Nov 8, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@CMWR421
Copy link

CMWR421 commented Nov 8, 2024

Describe the bug
The no-unnecessary-arbitrary-value rule incorrectly flags custom utility classes defined in the Tailwind config as unnecessary arbitrary values, suggesting they be replaced with arbitrary values like h-[48px]. This happens even though the custom classes are properly defined in the Tailwind preset/config.

To Reproduce

  1. Define custom utilities in your Tailwind config:
// tailwind.config.js
module.exports = {
 theme: {
   height: {
     "ds-icon-3xl": "48px",
     "ds-icon-xl": "32px",
     // ... more custom values
   },
   width: {
     "ds-icon-3xl": "48px",
     "ds-icon-xl": "32px",
     // ... more custom values
   }
 }
}
  1. Use these custom utilities in your code:
<div className="h-[48px] w-[48px]" />
  1. The linter flags these arbitrary values and suggests replacing them with:
<div className="h-ds-icon-3xl w-ds-icon-3xl" />

Expected behavior
The rule may allow arbitrary values when they are intentionally different from our design system values, or when we explicitly want to use pixel values instead of semantic names.


Environment
eslint-plugin-tailwindcss: 3.17.4


Additional context
While generally it's good practice to use design system tokens, there are valid cases where we want to use arbitrary values. The current behavior of the rule makes it difficult to use arbitrary values even in legitimate cases.


Workaround

const tailwind = require('eslint-plugin-tailwindcss');

/** @type {import('eslint').Linter.Config[]} */
module.exports = [
  ...tailwind.configs['flat/recommended'],
  {
    rules: {
      'tailwindcss/no-unnecessary-arbitrary-value': [
        'error',
        {
          config: {}, // We do not want this rule to take custom tailwind utilities into consideration.
        },
      ],
    },
  },
];
@CMWR421 CMWR421 added the bug Something isn't working label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant