-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: Improve useless-expression
query to avoid duplicate alerts on compound expressions
#19579
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: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
Enhance the isDomProperty
predicate to detect property reads on DOM nodes (e.g., offsetHeight
, clientWidth
) and reduce false positives in the js/useless-expression
query.
- Extend
isDomProperty
to also match property names accessed via data-flow property reads. - Add a test case validating layout-affecting reads on DOM elements.
- Record the change in the project’s change notes.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
javascript/ql/lib/Expressions/DOMProperties.qll | Extend isDomProperty predicate with a DataFlow::SourceNode branch. |
javascript/ql/test/query-tests/Expressions/ExprHasNoEffect/dom.js | New test verifying that reads like offsetHeight and clientWidth are side-effectful. |
javascript/ql/lib/change-notes/2025-05-26-dom-property-access.md | Add change note documenting the enhancement to isDomProperty . |
Comments suppressed due to low confidence (1)
javascript/ql/lib/Expressions/DOMProperties.qll:14
- [nitpick] The variable name
domNode
implies a DOM AST node but actually refers to a data-flow source; consider renaming it tosourceNode
orpropSourceNode
for clearer intent.
exists(DataFlow::SourceNode domNode | isDomNode(domNode) |
201ee08
to
59fe03f
Compare
59fe03f
to
1f256ab
Compare
isDomProperty
useless-expression
query to avoid duplicate alerts on compound expressions
e instanceof SeqExpr | ||
or | ||
e instanceof ParExpr and | ||
not e.stripParens() instanceof FunctionExpr |
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.
Why this last condition about functions? Deserves a comment at least.
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.
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.
But why is the function expression itself not flagged in this case?
We decided to alert on the innermost expression, as opposed to the outermost one. But this makes an exception for function expressions; for function expressions we now flag the enclosing parenthesis. I just don't see why there should be a special case for function expressions.
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.
15b1dae
to
aac56e0
Compare
This PR improves the
js/useless-expression
query by adding logic to avoid flagging compound expressions that may contain sub-expressions with side effects.