Why you should care
If a function literal is anonymous, there should be one space between the word function and the ( (left parenthesis). If the space is omitted, then it can appear that the function’s name is function, which is an incorrect reading.
Business Impacts
It is recommended to allow no spaces between the name of a function and the opening parenthesis of the list because more bugs in the portfolio and it prevents the code from being cost-effective.
CAST Recommendations
CAST recommends having no space between function name and parenthesis. The JavaScript style guidelines by Douglas Crockford establish very consistent rules that help the code work well and perform with cost efficiency.
How we detect
function MyFunction (param) { // bad !!!
// good (it’s a literal anonymous function:
div.onclick = function (e) {
return false;
};
that = {
// bad (it’s a literal function)
method: function literal_fct (e) {
return this.datum;
},
datum: 0
};
}
About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.