-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Change js/misspelled-variable-name to sometimes report the local variable as the misspelling #3094
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
Conversation
…ces of the global
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.
LGTM, if this scales to big-apps.slugs, and a change-note is added.
Co-Authored-By: Esben Sparre Andreasen <esbena@github.com>
(Except TypeScript, but that also fails on master). |
int globalAccesses(string name) { result = count(GlobalVarAccess acc | acc.getName() = name) } | ||
|
||
/** | ||
* Holds if our heuristic says that the local variable `lvd` seems to be a misspelling of the global variable `gvd`. |
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.
Shouldn't this be gva
?
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.
Yes it should.
Thanks.
Inspired by these alerts: https://lgtm.com/projects/g/MicrosoftDocs/iis-docs/alerts?id=js%2Fmisspelled-variable-name&mode=list
(From an anomalous query result)
The
js/misspelled-variable-name
query finds a pair of a local and global variable, where one seems to be a misspelling of the other. And the query always reports the global variable as the misspelling.This PR adds a heuristic to check if the local variable is likely the misspelling, based on the number of occurrences of each spelling.
If the local seems to be the misspelling, then the alert message is changed, but the alert location stays the same to avoid alerts shifting around.
It seems to work in practice, and gives an alert message that makes sense in more cases than previously.
(Here are results on a larger benchmark selection)