typescript:S2603 false positive on jsx callbacks

  • TypeScript
  • typescript:S2603
  • Using SonarQube Server Enterprise v2025.6.1
  • Code snippet:

                         <ToggleButton>
                            onActiveChange={(isActive) => {
                                if (isActive) {
                                    setActiveKey(key);
                                } else if (activeKey === key) {
                                    setActiveKey(null);
                                }
                            }}
                         </ToggleButton>

This is a false positive - I cannot refactor this into 2 functions.

I believe this is similiar to Jira except that only fixed a function inside a useCallback (which is not required if using react compiler) and the error triggers inside direct jsx.

Hi Luke, welcome to the community!

I’ve been looking into the false positive you reported regarding the code snippet inside your ToggleButton. To investigate this properly, I checked the official Sonar rules documentation, but it appears typescript:S2603 isn’t a known rule ID in the TypeScript analyzer.

It’s possible there was a slight typo when copying it down. Could you please double-check the ID listed for this issue in your SonarQube Server?

Once we have the confirmed ID, I can dig into the logic and see why it’s triggering inside your JSX so we can get this addressed!

1 Like

I’m so sorry I don’t know how I copied the wrong rule id.
it is S2301

Hi Luke!

Great catch on this one. Thank you for following up with the correct rule ID (S2301) and providing that snippet.

After looking into the code structure, we’ve confirmed that the rule is incorrectly flagging your function because it’s being used directly within JSX. You are absolutely right—in this React context, the standard refactoring advice doesn’t apply, and it’s definitely a false positive.

We have opened a ticket to address this so the analyzer can better recognize these React patterns. You can track the progress here: JS-1173.

Thanks for helping us improve the TypeScript analyzer!

2 Likes