Skip to content

Commit 70ea3a1

Browse files
committed
fix(lint): exclude GitHub Actions expressions from noTemplateCurlyInString
GitHub Actions uses `${{ ... }}` syntax (double curly braces) which was incorrectly flagged as a template literal placeholder. This fix detects and skips patterns that have double opening braces followed by double closing braces, as these are GitHub Actions expressions, not JavaScript template literal mistakes.
1 parent 1550e73 commit 70ea3a1

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

crates/biome_js_analyze/src/lint/suspicious/no_template_curly_in_string.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ declare_lint_rule! {
4040
/// const a = templateFunction`Hello ${name}`;
4141
/// ```
4242
///
43+
/// GitHub Actions expressions using double curly braces are also valid:
44+
///
45+
/// ```js
46+
/// const a = "${{ inputs.abc }}";
47+
/// ```
48+
///
4349
pub NoTemplateCurlyInString {
4450
version: "1.9.3",
4551
name: "noTemplateCurlyInString",
@@ -61,13 +67,23 @@ impl Rule for NoTemplateCurlyInString {
6167
let token = node.value_token().ok()?;
6268
let text = token.text_trimmed();
6369

64-
let mut byte_iter = text.bytes().enumerate();
70+
let mut byte_iter = text.bytes().enumerate().peekable();
6571
while let Some((i, byte)) = byte_iter.next() {
6672
if byte == b'$'
6773
&& let Some((_, b'{')) = byte_iter.next()
6874
{
75+
// Check for GitHub Actions syntax: ${{ ... }}
76+
// Skip if we have double braces on both sides
77+
let is_double_open = byte_iter.peek().is_some_and(|(_, b)| *b == b'{');
78+
6979
for (j, inner_byte) in byte_iter.by_ref() {
7080
if inner_byte == b'}' {
81+
// For ${{ syntax, only skip if it closes with }}
82+
if is_double_open && byte_iter.peek().is_some_and(|(_, b)| *b == b'}') {
83+
// This is GitHub Actions syntax ${{ ... }}, skip it
84+
byte_iter.next(); // consume the second }
85+
break;
86+
}
7187
return Some((i as u32, (j + 1) as u32));
7288
}
7389
}

crates/biome_js_analyze/tests/specs/suspicious/noTemplateCurlyInString/valid.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ let a = '$2';
1212
let a = '${';
1313
let a = '$}';
1414
let a = '{foo}';
15-
let a = '{foo: "bar"}';
15+
let a = '{foo: "bar"}';
16+
17+
// GitHub Actions expressions (double curly braces)
18+
let a = "${{ inputs.abc }}";
19+
let a = '${{ github.event.action }}';
20+
let a = "environment: ${{ inputs.environment }}";
21+
let a = "${{ secrets.MY_SECRET }}";

crates/biome_js_analyze/tests/specs/suspicious/noTemplateCurlyInString/valid.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ let a = '${';
1919
let a = '$}';
2020
let a = '{foo}';
2121
let a = '{foo: "bar"}';
22+
23+
// GitHub Actions expressions (double curly braces)
24+
let a = "${{ inputs.abc }}";
25+
let a = '${{ github.event.action }}';
26+
let a = "environment: ${{ inputs.environment }}";
27+
let a = "${{ secrets.MY_SECRET }}";
2228
```

0 commit comments

Comments
 (0)