SonarJS icon indicating copy to clipboard operation
SonarJS copied to clipboard

Fix FP css:S5362 ('function-calc-no-invalid'): Consider SCSS-specific syntaxes

Open yassin-kammoun-sonarsource opened this issue 2 years ago • 1 comments

Reported in https://community.sonarsource.com/t/scss-css-s5362-invalid-malformed-calc-function/62691

Has there been progress on this ticket? I'm still getting false positives when using valid SCSS interpolation in conjunction with the CSS calc function...

crush83 avatar Aug 16 '22 18:08 crush83

any progress? I still recieve this as critical!

sohaleKing avatar Sep 30 '22 15:09 sohaleKing

Hello there is there any progress we are getting critical issues because of this?

davidgataric avatar Oct 03 '22 14:10 davidgataric

This is an old issue. We have hundreds of this. Please fix this

kuschti avatar Oct 03 '22 14:10 kuschti

An initial investigation of the false positive shows that the parsing of calc scss-like argument produces a malformed abstract syntax tree.

Given the definition

p {
  width: calc(100% - #{$foo} - #{bar(20)});
}

we observe that the term #{bar(20)} is wrongly parsed as #{bar and }. This is due to the fact that the rule is currently able to parse property values with CSS syntax only.

As the original implementation from Stylelint did, we need to implement a proper parser not only for the calc syntax but also to consider SCSS-specific syntax.

For now, we advise disabling the rule when it is executed outside the scope of a plain CSS stylesheet until a proper fix is implemented.

link to stylelint removal: https://github.com/stylelint/stylelint/pull/5296

victor-diez-sonarsource avatar Oct 11 '22 08:10 victor-diez-sonarsource

We chose to deprecate this rule because:

  • It was originally dropped by Stylelint
  • It is too noisy as it currently does not support syntaxes other than CSS
  • It needs a proper parser which requires too much work and maintainability for what it's worth

You can track its deprecation in here: https://github.com/SonarSource/SonarJS/issues/3470

ilia-kebets-sonarsource avatar Oct 12 '22 09:10 ilia-kebets-sonarsource