Skip to content

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

Merged
merged 7 commits into from
Jun 13, 2025

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Jun 11, 2025

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 for autofix to fix.

While running MRVA, a few patterns of false positives were observed. Note that all of these cases are rare:

  • Packages like yup may produce false positives. Yup uses special variables such as ${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 like ${expected} are used to inform users about variable values. Fixed bafe7e6
  • Some cases involve "manual interpolation", where a placeholder like ${usedAsPlaceHolder} is later replaced using replaceAll or replace functions. Fixed 923aff2

High accuracy seems appropriate for the following query.

@github-actions github-actions bot added the JS label Jun 11, 2025
@Napalys Napalys marked this pull request as ready for review June 11, 2025 10:47
@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 10:47
@Napalys Napalys requested a review from a team as a code owner June 11, 2025 10:47
@Napalys Napalys added the no-change-note-required This PR does not need a change note label Jun 11, 2025
Copy link
Contributor

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

@Napalys Napalys marked this pull request as draft June 12, 2025 08:28
@Napalys Napalys marked this pull request as ready for review June 12, 2025 09:39
@Napalys Napalys removed the no-change-note-required This PR does not need a change note label Jun 12, 2025
* 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()
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added here d7ad625.

@Napalys Napalys requested a review from asgerf June 13, 2025 10:10
@Napalys Napalys merged commit 0906d85 into github:main Jun 13, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants