From 7cc93f3c4d1447f2da4945e1f615636d2f457b43 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 29 Oct 2017 16:59:09 -0700 Subject: [PATCH] Created SC1124 (markdown) --- SC1124.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 SC1124.md diff --git a/SC1124.md b/SC1124.md new file mode 100644 index 0000000..102e620 --- /dev/null +++ b/SC1124.md @@ -0,0 +1,48 @@ +## ShellCheck directives are only valid in front of complete commands like 'case' statements, not individual case branches. + +### Problematic code: + +```sh +case $? in + 0) echo "Success" ;; + # shellcheck disable=2154 + *) echo "$cmd $flag returned failure" ;; +esac + +``` + +### Correct code: +```sh +# Applies to everything in the `case` statement +# shellcheck disable=2154 +case $? in + 0) echo "Success" ;; + *) echo "$cmd $flag returned failure" ;; +esac +``` + +or + +```sh +case $? in + 0) echo "Success" ;; + *) + # Applies to a single command within the `case` + # shellcheck disable=2154 + echo "$cmd $flag returned failure" + ;; +esac +``` + + +### Rationale: + +You appear to have put a directive before a branch in a case statement. + +ShellCheck directives can not be scoped to individual branches of `case` statements, only to the entire `case`, or to individual commands within it. Please move the directive as appropriate. + +(It is possible to apply directives to all commands within a `{ ..: }` command group, if you truly wish to apply a directive to multiple commands but not the full `case` statement.) + +### Exceptions: + +None. \ No newline at end of file