[typescript:S125 (`no-commented-code`)] False Negative: commented out properties

Hey,

we started using SonarCloud recently. We shouldn’t have commented out code and wanted to sue sonar cloud as the tool to detect that in our code base. We noticed that commented out properties in the jsx/HTML code is not found.

  • What language is this for?: Typescript
  • Which rule?: typescript:S125
  • Why do you believe it’s a false-negative?
    • It has weird brackets as comments. It should be recognized as code
  • Are you using: SonarCloud & SonarLint VsCode Extension v4.10.0 happens in both modes

To reproduce it, it was enough for me to just open this code as a index.tsx:

'use client';

import * as React from 'react';
import { DateCalendar } from "@mui/x-date-pickers";


const Calendar: React.FC = () => {
	return (
		<DateCalendar
			data-testid="header-calendar"
			value={1234}
			openTo="year"
			// views={["year"]}
			// maxDate={new Date()}
			onChange={date => {
				console.log(date);
			}}
		/>
	);
};

export { Calendar };

It even appears, that code that is otherwised found correctly is not found when in proximity to these commented out properties. The first commented out code is recognized, the second not :(.

'use client';

import * as React from 'react';
import { DateCalendar } from "@mui/x-date-pickers";

//const test= 1234;

const Calendar: React.FC = () => {
	return (
		<DateCalendar
			data-testid="header-calendar"
			value={1234}
			openTo="year"
			//const test= 1234;
			// views={["year"]}
			// maxDate={new Date()}
			onChange={date => {
				console.log(date);
			}}
		/>
	);
};

export { Calendar };

I know, that this rule works with heuristics, but maybe they can be improved with properties :smiley:

Hello Thimo,

Thank you for the feedback. The rule works by trying to parse the content of the comments to determine whether it’s code.
However, JSX element attributes taken out of context are not valid JS/TS, so they are not picked up.
Proceeding as such allows us to minimize the rate of false positives.

The following block is not picked up because it is handled as a single block contrary to the single comment //const test= 1234; above:

			//const test= 1234;
			// views={["year"]}
			// maxDate={new Date()}

I opened a Jira issue about this feature request: [JS-366] - Jira