Skip to content

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

Merged
merged 6 commits into from
Apr 20, 2020

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Mar 20, 2020

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)

@erik-krogh erik-krogh added JS Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish labels Mar 20, 2020
@erik-krogh erik-krogh marked this pull request as ready for review April 17, 2020 09:35
@erik-krogh erik-krogh requested a review from a team as a code owner April 17, 2020 09:35
Copy link
Contributor

@esbena esbena left a 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.

@erik-krogh
Copy link
Contributor Author

LGTM, if this scales to big-apps.slugs, and a change-note is added.

Big-apps look good.

(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`.
Copy link
Contributor

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?

Copy link
Contributor Author

@erik-krogh erik-krogh Apr 20, 2020

Choose a reason for hiding this comment

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

Yes it should.
Thanks.

@semmle-qlci semmle-qlci merged commit e965e5c into github:master Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish JS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants