Hi, rule javascript:S1656 (“Variables should not be self‑assigned”) reports a violation for:
location.href = location.href;
This is reported as:
“Variables should not be self-assigned.”
This is a false positive (or misleading positive).
Assigning the same value to location.href is a valid and intentional idiom: browsers treat it as a page reload without adding a history entry. It is not redundant and it has a real side‑effect (rightly or wrongly, it’s what it is)
Please consider adding an exception for location.href = location.href.
Thanks
- What language is this for?
javascript
- Which rule?
javascript:S1656 Variables should be self-assigned
- Why do you believe it’s a false-positive/false-negative?
assigning to location.href is not a “variable” and has the side effect of reloading the page.
- Are you using
- SonarQube Cloud?
- SonarQube Server
2025.04
- How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
location.href = location.href;