SonarTS
SonarTS copied to clipboard
Rule Idea: console.log using spaces in arguments
These 2 lines doing the same thing, while second line should be preferred
console.log("Hello " + name); // Noncompliant
console.log(name + " is my friend"); // Noncompliant
// OK
console.log("Hello", name);
console.log("Hello ${name}");
console.log(name, " is my friend");
// should this be Noncompliant as well?
console.log("Hello ", name); // 2 spaces in output
Sounds like what you want to do id forbid the + operator when the left hand is a string. What about string interpolation? Is it allowed? Preferred?
There is tslint prefer-template
which forces developer to prefer string interpolation over concatenation.
This rule is only about string concatenation inside console
methods. Indeed, one might prefer console.log("Hello ${name}");
to console.log("Hello", name);
, but that's a matter of taste and btw there is property allow-single-concat
to prefer-template
.
I also thinking about case like that which might be considered as noncompliant for this rule: console.log("Hello ", name);
. There will be 2 spaces in output.
Note I updated first comment with more examples