-
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
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
15b1dae
to
aac56e0
Compare
8bd817c
to
c97da2e
Compare
Co-authored-by: Asger F <asgerf@github.com>
Co-authored-by: Asger F <asgerf@github.com>
Co-Authored-By: Asger F <316427+asgerf@users.noreply.github.com>
This PR improves the
js/useless-expression
query by adding logic to avoid flagging compound expressions that may contain sub-expressions with side effects.