If your question is about SonarLint in the IntelliJ Platform, VS Code, Visual Studio, or Eclipse, please post it in that sub-category.
Otherwise, please provide:
- Operating system: Linux, Feedora 39
- IDE name and flavor/env: jetbrains-idea + npm 8.19.4 + node v16.20.0
And a thorough description of the problem / question:
I hope this message finds you well. I am writing to report an issue encountered during the integration of eslint-plugin-sonarjs
into our project. After addressing all identified issues and pushing the changes, the subsequent merge request triggered a Sonar validation failure.
The specific error message received is as follows:
Expected a
for-ofloop instead of a
for loop with this simple iteration.
Code affected:
for (let resultId = 0; resultId < results.length; resultId++) {
const result = results[resultId] as unknown as {
id: number;
isinventory: string;
availablequantity: number;
};
if (result !== undefined && result.isinventory === "T") {
itemsQuantityAvailable.set(result.id, result.availablequantity ? result.availablequantity : 0);
}
}
To provide context, the integration involved fixing various issues flagged by the eslint-plugin-sonarjs
. The changes were made following the plugin’s recommendations, and the code passed the local linting successfully. However, the Sonar validation process appears to be encountering difficulties with the updated code.
Steps taken to address the issue:
- Installed
eslint-plugin-sonarjs
. - Plugin configuration:
plugins: ["sonarjs"],
extends: ["plugin:sonarjs/recommended"],
rules: {
"sonarjs/no-duplicate-string": "off",
},
//.eslintrc.json
overrides: {
"files": [
"SalesOrderService.ts",
"SalesOrderMultiStepScreen.tsx",
"SalesOrderItemsMultiStep.tsx",
"CustomerService.ts",
"ItemLineToolbarActions.tsx"
],
"rules": { "sonarjs/cognitive-complexity": "off" }
},
{
"files": [
"SalesOrderEntryContext.tsx",
"SalesNavigator.tsx"
],
"rules": {
"react/display-name": "off"
}
}
- Resolved all flagged issues locally using the plugin’s recommendations.
- Pushed the changes to the repository.
- Created a merge request.
It’s worth noting that the code passed the local linting process successfully, and the issue surfaced only during the Sonar validation in the CI/CD pipeline.
We would appreciate any assistance in identifying the root cause of this Sonar validation failure and guidance on how to address it effectively. If there are specific Sonar configurations or additional steps we need to take in conjunction with eslint-plugin-sonarjs
, please advise accordingly.
Thank you for your attention to this matter, and we look forward to resolving this issue promptly.
Best regards,
Andres