-
Notifications
You must be signed in to change notification settings - Fork 192
Fix false positive for JS-131 #6016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Have a look at the |
|
✅ Addressed review feedback in the latest commit. |
✅ Addressed in the latest commit. Fixed all 5 SonarQube quality gate issues in
|
✅ Addressed in the latest commit. Applied |
| { | ||
| code: ` | ||
| // FP: imported variable should not raise issue (JS-131) | ||
| // This should NOT raise an issue because 'imported' could be modified elsewhere | ||
| import { imported } from 'module'; | ||
| while (imported) { | ||
| doSomething(); | ||
| }`, | ||
| }, | ||
| { | ||
| code: ` | ||
| // FP: required variable should not raise issue (JS-131) | ||
| // This should NOT raise an issue because 'required' could be modified elsewhere | ||
| const required = require('module'); | ||
| while (required) { | ||
| doSomething(); | ||
| }`, | ||
| }, | ||
| { | ||
| code: ` | ||
| // FP: file-scope variable with function call in loop (JS-131) | ||
| // This should NOT raise an issue because someFunction() might modify globalVar | ||
| let globalVar = true; | ||
| while (globalVar) { | ||
| someFunction(); | ||
| }`, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the unit tests, please make sure that all of the cases from the algorithm in the Jira ticket are covered
The rule was raising issues for imported/required variables in loop conditions. Since imported variables could be modified by external modules, these are false positives. Added check to skip reporting for variables that come from import statements or require() calls. This aligns with the principle of avoiding false positives when cross-procedural modifications are possible. When unable to determine if a variable is modified across procedures, prefer not raising an issue. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
eb95ad7 to
2ac2d0e
Compare
Added test cases for: - Required variables (variables from require() calls) - Variables passed as arguments to functions - Variables used as method receivers These test cases cover the key scenarios from the algorithm described in the Jira ticket to reduce false positives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
✅ Addressed in the latest commit. Added test cases covering key scenarios from the algorithm:
These tests validate that the implementation correctly avoids false positives for cases where cross-procedural modifications are possible. |
|




This PR fixes the false positive issue reported in https://sonarsource.atlassian.net/browse/JS-131
Generated by Claude Code.