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

New rule: Disallow ternary conditions inside template literals #117

Open
fsubal opened this issue Feb 18, 2025 · 1 comment
Open

New rule: Disallow ternary conditions inside template literals #117

fsubal opened this issue Feb 18, 2025 · 1 comment
Assignees

Comments

@fsubal
Copy link
Owner

fsubal commented Feb 18, 2025

Examples of incorrect code for this rule:

<button className={`${ cond && 'bg-blue-300' }`}>Hello</button>;

This could lead to unexpected results like <button className="false"> .
But currently, this code is not warned nor fixed.

Their should be a rule that auto-fixes this into

<button className={classNames(cond && 'bg-blue-300')}>Hello</button>;

or maybe

<button className={classNames({ 'bg-blue-300': cond })}>Hello</button>;
@fsubal fsubal self-assigned this Feb 18, 2025
@fsubal
Copy link
Owner Author

fsubal commented Feb 18, 2025

Candidates of the name of this rule:

  • no-ternary-conditions-in-template-literals
  • no-conditional-template-literals

Or, should this behavior a part of prefer-classnames-function ?

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

No branches or pull requests

1 participant