You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that the current implementation is ignoring functions that have only a couple of lines, which seems fair.
However, this also means the rule is finding an issue for functions that have a few statements in multiple lines. This is particularly visible when you have a single expression that takes multiple lines.
Particularly in JSX, there can be a single expression that can take many lines. Like when mapping over an Array to create JSX components. See the given example.
The coupling of using a common function is not worth the little duplication, since in this case there would be little or no logic involved.
Suggestion
The rule should ignore functions with a single expression
The rule should ignore functions with few statements
We should consider ignoring arrow functions that are passed to Array methods like map, filter, find, etc. unless they have many statements.
The text was updated successfully, but these errors were encountered:
gabriel-vivas-sonarsource
changed the title
S4144 should be based on statements and not lines
S4144 should ignore functions with few statements or a single expression
Aug 1, 2022
I changed the rule to look only at function declaration, method definition, and variable declarations. That's to say, it only looks at functions that are defined in a syntactic scope ignoring all function expressions.
// Function declarationsfunctionfoo(){}classFoo{// Method definitionsfoo(){}}// Variable declarators:constfoo=()=>{};
The motivation is that it's not practically possible to determine when a function returns just an expression, as there are many different types of expressions. Moreover, there are several ways for a function to return a simple expression (block with a return statement, expression in the body).
Therefore we can expect some true positives to be ignored from now on.
Explanation
Suggestion
The text was updated successfully, but these errors were encountered: