eslint-plugin-sonarjs icon indicating copy to clipboard operation
eslint-plugin-sonarjs copied to clipboard

Prevent error of sonarjs/no-duplicate-string with CSS classes (Tailwind, Foundation, Boostrap...)

Open RodrigoTomeES opened this issue 1 year ago • 8 comments

I want to request a feature.

I want that sonarjs/no-duplicate-string doesn't throw erros with Tailiwnd classes.

const Card = () => 
<div class="flex">
  <div class="flex">
    <img .../>
  </div>

  <div class="flex" />
</div>

RodrigoTomeES avatar Aug 07 '23 07:08 RodrigoTomeES

Would this option meet your needs? https://github.com/SonarSource/eslint-plugin-sonarjs/blob/8e3a6835e646c15bfe76f30fc7f5dd37c49579a1/docs/rules/no-duplicate-string.md#L24

arianrhodsandlot avatar Aug 09 '23 07:08 arianrhodsandlot

Hi!, thanks but I think that doesn't meet my need because Tailwind has hundreds or thousands of classes 🙈

RodrigoTomeES avatar Aug 09 '23 07:08 RodrigoTomeES

Thanks a lot - that indeed makes sense, we will look at it.

alex-sonar avatar Aug 11 '23 08:08 alex-sonar

@alexander-kamushkin-sonarsource great thanks! It would be awesome if the implementation can be made for css classes in general because in this case others CSS frameworks will work

RodrigoTomeES avatar Aug 11 '23 09:08 RodrigoTomeES

@RodrigoTomeES I analyzed the snippet you provided and the rule doesn't report any issue on it. I also checked the rule implementation and it already makes an exception to all JSX attributes.

Was this a feature suggestion or are you facing an actual false positive from the rule?

@yassin-kammoun-sonarsource now I on vacation and I can't provide you an real example but when I will go back to my work I will show you real code that have this problem

RodrigoTomeES avatar Aug 16 '23 14:08 RodrigoTomeES

I have the same issue. Mostly happens when for me with tailwind-merge using an array of classes like this: CleanShot 2023-08-25 at 14 57 36@2x And yes, it might be an abomination to pass classes as an array, but it lets prettier format them nicely.

man-trackunit avatar Aug 25 '23 12:08 man-trackunit

To bump, it would be sweet to be able to pass a regex to ignoreStrings

olafurns7 avatar Nov 03 '23 16:11 olafurns7

This issue has been migrated to Jira. ESLINTJS-26

Wohops avatar Apr 29 '24 08:04 Wohops