
org.sonar.l10n.javascript.rules.javascript.S1472.html Maven / Gradle / Ivy
Because semicolons at the ends of statements are optional, starting function call arguments on a separate line makes the code confusing. It could lead to errors and most likely will lead to questions for maintainers.
What was the initial purpose of the developer ?
- Was it to define a function and then to execute some unrelated code inside a closure ?
- Or to pass the second function as a parameter to the first one ?
The first option will be the one chosen by the JavaScript interpreter..
Noncompliant Code Example
var fn = function () {
//...
}
(function () { // Noncompliant
//...
})();
Compliant Solution
Either
// define a function
var fn = function () {
//...
}; // <-- semicolon added
// then execute some code inside a closure
(function () {
//...
})();
Or
var fn = function () {
//...
}(function () { // <-- start function call arguments on same line
//...
})();
By extension and to improve readability, any kind of function call arguments should not start on new line.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy