javascript:S3786

in SonarQube 8.9.3.48735 the following code results in javascript:S3786:

const size = "100";
const str = "<Component :style='{ width: `${size}pt` }'/>";

which imho completely ignores the string template ticks around the template placeholder variable.

could the check function be optimized here to take this into account?

Sorry but I don’t follow, in your example you have a string containing template-like syntax ${x} which is not actually evaluated. str will NOT have value <Component :style='{ width: 100pt }'/>.

So I believe it’s a rightful issue.

1 Like

um yes, you are right. the example does not give the full picture.

actually, str is going to be evaluated by a framework that knows how to transform an attribute value like ‘{ width: `${size}pt` }’ in such a component string.

still, i think sonarlint should take the ticks into account before considering the template literal placeholder being inside of a normal string…

Hi Tobi,

How SonarLint can know that presence of backticks inside of string literal means something special? I can recommend you disabling the rule if you are using such templating system as probably most (or all) of reported issues will be wrong.

yes i see, this would be too much magic indeed. gotta think about what is worse, disabling the rule or living with the sonarqube alert… thanks for your insights, elena.

P.S. It’s possible to disable the rule on particular files ( Project Settings > General Settings > Analysis Scope > Issues).