Skip to content

feat(rule): no-string-interpolation#441

Open
angelos24 wants to merge 1 commit intofrancoismassart:masterfrom
angelos24:feat/no-string-interpolation
Open

feat(rule): no-string-interpolation#441
angelos24 wants to merge 1 commit intofrancoismassart:masterfrom
angelos24:feat/no-string-interpolation

Conversation

@angelos24
Copy link
Copy Markdown

add no-string-interpolation rule

Description

This PR introduces a new ESLint rule no-string-interpolation designed to prevent dynamic
Tailwind class construction. Tailwind CSS relies on static analysis to generate CSS, and
constructing class names via string interpolation (e.g., bg-${color}) prevents the
compiler from identifying used classes.

The rule specifically targets class and className attributes in JSX and reports instances
where an interpolated value is directly attached to a string literal without a space
delimiter.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

The changes were verified by adding a comprehensive test suite in
tests/lib/rules/no-string-interpolation.js.

  • Test A: Verified that partial string interpolation like bg-${color} or ${variant}-text
    is correctly flagged as an error.
  • Test B: Confirmed that full variable interpolation (e.g., ${color} text-lg)
    remains valid, as it doesn't involve dynamic construction of a specific Tailwind
    utility name.

Test Configuration:

Test Configuration:

  • OS + version: Linux
  • NPM version: 10.x (as per environment)
  • Node version: 18.x/20.x/22.x/24.x

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant