Sample Header Ad - 728x90

Shellcheck reporting SC2030 on BATS test description line

2 votes
1 answer
66 views
I have Shellcheck flagging strange statements when applied to BATS MRE:
#!/usr/bin/env bats


@test "test descirption" {
 :
}

my_function() {
  api_key=$(jq -r '.key' <<<"$output")
}
Line 4:
@test "test descirption" {
^-- SC2030 (info): Modification of output is local (to subshell caused by @bats test).
 
Line 9:
  api_key=$(jq -r '.key' <<<"$output")
  ^-- SC2034 (warning): api_key appears unused. Verify use (or export if used externally).
                             ^-- SC2031 (info): output was modified in a subshell. That change might be lost.
I'm not even modifying the $output, I'm just reading it. The BATS run command would be setting it (omitted in MRE). I also don't understand why would it be reported for the test description line? There is also SC2031 reported for <<<"$output" when I'm not modifying it at all. It seems to be caused by defining a regular function in the BATS file (to handle the repeating part of test cases). If I move the function into setup() it makes the findings go away. Yet I'd prefer not to do it. Doing things in the global scope of BATS test is discouraged but not forbidden. Defining the function there doesn't seem to break BATS, but it looks like Shellcheck has a problem with it. Why?
Asked by Jakub Bochenski (325 rep)
Jun 13, 2025, 03:14 PM
Last activity: Jun 14, 2025, 12:41 PM