org.sonar.l10n.javascript.rules.javascript.S138.html Maven / Gradle / Ivy
Why is this an issue?
A function that grows too large tends to aggregate too many responsibilities.
Such functions inevitably become harder to understand and therefore harder to maintain.
Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.
Those smaller functions will not only be easier to understand, but also probably easier to test.
Exceptions
This rule ignores Immediately Invoked Function Expressions (IIFE), which are functions that are created and invoked without ever being assigned a
name.
(function () { // Ignored by this rule
function open() { // Classic function declaration; not ignored
// ...
}
function read() {
// ...
}
function readlines() {
// ...
}
})();
This rule also ignores React Functional Components, which are JavaScript functions named with a capital letter and returning a React element (JSX
syntax).
function Welcome() {
const greeting = 'Hello, World!';
// ...
return (
<div className="Welcome">
<p>{greeting}</p>
</div>
);
}