Skip to content

Commit

Permalink
disable shellcheck rule SC2043 (fix #355)
Browse files Browse the repository at this point in the history
because it is reported as the result of placeholder replacement.

```
- run: |
    for elem in ${{ inputs.foo }}; do
        echo "$elem"
    done
```
  • Loading branch information
rhysd committed Oct 21, 2024
1 parent b7ebeb4 commit c71a576
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rule_shellcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ func (rule *RuleShellcheck) runShellcheck(src, shell string, pos *Pos) {
// so this rule can cause false positives (#53).
// - SC2157: Argument to -z is always false due to literal strings. When the argument of -z is replaced from ${{ }},
// this can happen. For example, `if [ -z ${{ env.FOO }} ]` -> `if [ -z ______________ ]` (#113).
args := []string{"--norc", "-f", "json", "-x", "--shell", sh, "-e", "SC1091,SC2194,SC2050,SC2154,SC2157", "-"}
// - SC2043: Loop can be detected as only running once when the target of iteration is a placeholder. (#355)
// e.g. `for foo in ${{ inputs.foo }}; do`
args := []string{"--norc", "-f", "json", "-x", "--shell", sh, "-e", "SC1091,SC2194,SC2050,SC2154,SC2157,SC2043", "-"}
rule.Debug("%s: Running %s command with %s", pos, rule.cmd.exe, args)

// Use same options to run shell process described at document
Expand Down
9 changes: 9 additions & 0 deletions testdata/ok/issue-355-shellcheck-sc2043.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: |
for x in ${{ github.run_number }}; do
echo "$x"
done

0 comments on commit c71a576

Please sign in to comment.