False positive in S9114 for non-React PascalCase functions

Rule: javascript:S9114 — “Lodash and Underscore.js debounced or throttled functions should not be recreated on every React render”

import { debounce } from 'lodash';

export function CreateSearchThrottler() {    return debounce((query: string) => query.trim(), 200);}

This is a contrived example - we have some code that uses the old style functions as classes, so they are Capitalized but nothing to do with react ;- perhaps you could also check if the function takes one argument and it has props in it or something more elaborate.

Analysis

The rule does not use TypeScript type information (requiresTypeChecking: false). Its function-component detection is syntactic: any enclosing function with a PascalCase name, or a use[A-Z] name, is treated as a React component/hook.

This produces false positives for non-React utilities, factories, and helper functions that follow PascalCase naming. The rule should verify React component usage more reliably, or restrict reporting to code with React component evidence rather than name casing alone.

Hey @lukpsaxo, thanks for reporting, I will flag this for the team. Just one quick question: which product/version (if applicable) are you using? I had a look and I don’t think that there were any recent fixes for this, but regardless, it’s good practice to always let us know in which environment you are running into the false positive/negative.

We use sonar qube server but locally we use eslint-plugin-sonarjs and the above issue was found after upgrading the eslint plugin to the latest 4.2.1

It was implemented a month ago:

and here is the LOC where it relies on the first letter case to understand if its a react component: