SonarJS icon indicating copy to clipboard operation
SonarJS copied to clipboard

Fix FP S3800 (`function-return-type`): Exceptions for React components

Open ericmorand-sonarsource opened this issue 1 year ago • 1 comments

Add an exception for React components:

  • ignore when returning null or false

This issue was extracted from #4527 to not delay the sanitation fix.

ericmorand-sonarsource avatar Feb 02 '24 09:02 ericmorand-sonarsource

I was not able to reproduce the first issue (React components, ignore when returning null or false): based on my testings with the current state of SonarJS, the S3800 rule never triggers when either the render method of a React Component or a React FunctionComponent returns false conditionally. Typically, the following code is compliant according to S3800:

export const MyComponent = ({flag}) => {
    if (flag) {
        return <>5</>;
    }

    return false;
};

I'll try to get more information about the edge case from the developer who dismissed the rule because of conditionally returning false.

ericmorand-sonarsource avatar Feb 02 '24 09:02 ericmorand-sonarsource

Migrated to Jira. New ticket number: JS-31

Wohops avatar Apr 24 '24 15:04 Wohops