-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: Promote js/template-syntax-in-string-literal
to the Code Quality suite.
#19726
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
This PR promotes the js/template-syntax-in-string-literal
query into the Code Quality suite by updating its metadata tags and including it in the integration test list.
- Expanded the query’s
@tags
metadata to classify it under quality, reliability, correctness, and language-features. - Added the query path to
javascript-code-quality.qls.expected
for integration testing.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
javascript/ql/src/LanguageFeatures/TemplateSyntaxInStringLiteral.ql | Updated @tags metadata lines to add new classifications. |
javascript/ql/integration-tests/query-suite/javascript-code-quality.qls.expected | Inserted the new query into the Code Quality suite expected list. |
javascript/ql/src/LanguageFeatures/TemplateSyntaxInStringLiteral.ql
Outdated
Show resolved
Hide resolved
* Tracks data flow from a string literal that may flow to a replace operation. | ||
*/ | ||
DataFlow::SourceNode trackString(CandidateStringLiteral lit, DataFlow::TypeTracker t) { | ||
t.start() and result = lit.flow() |
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.
Tracking all string literals in the program seems unnecessarily expensive. Could you restrict this to just the string literals that we might have flagged otherwise?
Adding exists(lit.getAReferencedVariable())
might be good enough.
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.
Added here d7ad625.
…al.ql Co-Authored-By: Asger F <316427+asgerf@users.noreply.github.com>
This pull request adds the query
js/template-syntax-in-string-literal
to the Code Quality suite. The problem that the query aims to highlight is straightforward forautofix
to fix.While running MRVA, a few patterns of false positives were observed. Note that all of these cases are rare:
${min}
,${max}
,${path}
,${less}
, etc., which are correctly interpolated, even when included inside single (''
) or double (""
) quotes and passed to the respective yup methods. These false positives are uncommon, as they only occur when there is a variable with the exact same name in the current scope.In certain test framework code, template placeholders likeFixed bafe7e6${expected}
are used to inform users about variable values.Some cases involve "manual interpolation", where a placeholder likeFixed 923aff2${usedAsPlaceHolder}
is later replaced usingreplaceAll
orreplace
functions.High
accuracy seems appropriate for the following query.