Skip to content

SONARPHP-1972 Exempt underscore-prefixed unused local variables - #1853

Merged
lijun-chen-sonarsource merged 2 commits into
masterfrom
lc/SONARPHP-1972
Oct 22, 2026
Merged

lijun-chen-sonarsource merged 2 commits into
masterfrom
lc/SONARPHP-1972

Conversation

@lijun-chen-sonarsource

@lijun-chen-sonarsource lijun-chen-sonarsource commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Stack created with GitHub Stacks CLI • Give Feedback 💬


Summary by Gitar

  • Behavior change:
    • Exempted unused local variables whose names start with $_ from UnusedLocalVariableCheck
  • Tests:
    • Added cases for $_ variables in foreach, list, static, closure captures, and object assignments in UnusedLocalVariableCheck.php

This will update automatically on new commits.

@lijun-chen-sonarsource
lijun-chen-sonarsource added this pull request to stack #1856 October 19, 2026 13:20
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

SONARPHP-1972

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add sample cases that you mention in JIRA ticket to clarify actual usage. Provided sample doesn't illustrate purpose of change.

@sonarqube-next

Copy link
Copy Markdown

@gitar-bot

gitar-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Exempting all local variables prefixed $_ from the unused-variable check could let genuinely unused locals escape detection.

Exempts local variables whose names start with $_ from UnusedLocalVariableCheck, covering foreach, list, static, closure capture, and object assignment cases with added test coverage. No issues found.

Verification Rules 1/1 met Repos 3 inspected · PRs 2 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact Repos 3 inspected PRs 2 inspected
Cross-repo 3 repositories inspected 0 open impacts

SonarSource/sonarlint-vscode Inspected
SonarSource/sonarlint-language-server Inspected
SonarSource/sonarlint-core Inspected

Cross-PR 2 PRs inspected 0 open impacts

PR #1854: SONARPHP-1593 Track reads through sibling and nested closure references Inspected
PR #1855: SONARPHP-1969 Account for dynamically accessed local variables Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@karim-ouerghemmi-sonarsource

Copy link
Copy Markdown
Contributor

@lijun-chen-sonarsource I let you guys merge the automatically created metadata update PR #1859 (review) once this is on master. I was about to merge, but Gitar made me aware that the underscore prefix exception is not yet on master.

@lijun-chen-sonarsource

lijun-chen-sonarsource commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@karim-ouerghemmi-sonarsource Opss. Merged the rspec to hastily. Thanks for the heads up. I'll merge #1859 once this PR is merged (which should happen today).

@lijun-chen-sonarsource
lijun-chen-sonarsource merged commit acac69a into master Oct 22, 2026
24 checks passed
@lijun-chen-sonarsource
lijun-chen-sonarsource deleted the lc/SONARPHP-1972 branch October 22, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants