Skip to content

Commit 6898a67

Browse files
nzakasclaude
andcommitted
fix: quote the original expansion in no-unquoted-expansions message
The message rebuilt every parameter as ${name}, dropping subscripts and operators. It now interpolates the expansion's source text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3771e5a commit 6898a67

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎src/rules/no-unquoted-expansions.spec.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ruleTester.run("no-unquoted-expansions", rule as never, {
5050
errors: [
5151
{
5252
messageId: "unquotedParameterExpansion",
53+
data: { expansion: "$var" },
5354
line: 1,
5455
column: 6,
5556
endColumn: 10,
@@ -61,6 +62,27 @@ ruleTester.run("no-unquoted-expansions", rule as never, {
6162
output: 'echo "${var}"',
6263
errors: [{ messageId: "unquotedParameterExpansion" }],
6364
},
65+
{
66+
// The message quotes the expansion as written
67+
code: "echo ${arr[@]}",
68+
output: 'echo "${arr[@]}"',
69+
errors: [
70+
{
71+
messageId: "unquotedParameterExpansion",
72+
data: { expansion: "${arr[@]}" },
73+
},
74+
],
75+
},
76+
{
77+
code: "echo ${var:-default}",
78+
output: 'echo "${var:-default}"',
79+
errors: [
80+
{
81+
messageId: "unquotedParameterExpansion",
82+
data: { expansion: "${var:-default}" },
83+
},
84+
],
85+
},
6486
{
6587
code: "echo $@",
6688
output: 'echo "$@"',

‎src/rules/no-unquoted-expansions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const rule: BashRuleDefinition<{
2929
schema: [],
3030
messages: {
3131
unquotedParameterExpansion:
32-
'Double quote "${{name}}" to prevent word splitting and globbing. (ShellCheck SC2086)',
32+
'Double quote "{{expansion}}" to prevent word splitting and globbing. (ShellCheck SC2086)',
3333
unquotedCommandSubstitution:
3434
"Quote this command substitution to prevent word splitting. (ShellCheck SC2046)",
3535
},
@@ -67,7 +67,7 @@ const rule: BashRuleDefinition<{
6767
: "unquotedCommandSubstitution",
6868
data:
6969
part.type === "ParameterExpansion"
70-
? { name: part.name }
70+
? { expansion: sourceCode.getText(part) }
7171
: {},
7272
fix: isWholeWord
7373
? fixer =>

0 commit comments

Comments
 (0)