All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S1516.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

Creating multiline strings by using a backslash (\) before a newline is known as "line continuation" or "line breaking." While it may seem like a convenient way to format multiline strings, it is generally considered bad practice.

  • Line continuation can make the code harder to read and understand, especially when dealing with long strings. It introduces an extra character at the end of each line, which can clutter the code and reduce its readability.
  • If the string content changes, it might require reformatting the entire multiline string, involving adjusting the line breaks and ensuring the backslashes are correctly placed. This can be error-prone and cumbersome, leading to maintenance issues.
  • Line continuation can sometimes behave unexpectedly, particularly when there are trailing spaces or tabs after the backslash. This can lead to subtle bugs that are difficult to spot and debug.
let myString = 'A rather long string of English text, an error message \
                actually that just keeps going and going -- an error \
                message to make the Energizer bunny blush (right through \
                those Schwarzenegger shades)! Where was I? Oh yes, \
                you\'ve got an error and all the extraneous whitespace is \
                just gravy.  Have a nice day.';  // Noncompliant

Instead, you should use string concatenation for multiline strings, which involves combining multiple strings to create a single string that spans multiple lines.

let myString = 'A rather long string of English text, an error message ' +
               'actually that just keeps going and going -- an error ' +
               'message to make the Energizer bunny blush (right through ' +
               'those Schwarzenegger shades)! Where was I? Oh yes, ' +
               'you\'ve got an error and all the extraneous whitespace is ' +
               'just gravy.  Have a nice day.';

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy