syntax colorization on code blocks

Romain Dartigues
2019-10-30 11:03:06 +00:00
parent eb5c97f3d9
commit a7c35872e2

@@ -1,35 +1,43 @@
Shellcheck directives allow you to control how `shellcheck` works, and take the form of comments in files: Shellcheck directives allow you to control how `shellcheck` works, and take the form of comments in files:
hexToAscii() { ```sh
hexToAscii() {
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf "\x$1" printf "\x$1"
} }
```
Supported directives are Supported directives are
### disable ### disable
Prevent shellcheck from processing one or more warnings: Prevent shellcheck from processing one or more warnings:
# shellcheck disable=code[,code...] ```sh
statement_where_warning_should_be_disabled # shellcheck disable=code[,code...]
statement_where_warning_should_be_disabled
```
### source ### source
Tell ShellCheck where to find a sourced file (since 0.4.0): Tell ShellCheck where to find a sourced file (since 0.4.0):
# shellcheck source=src/examples/config.sh ```sh
. "$(locate_config)" # shellcheck source=src/examples/config.sh
. "$(locate_config)"
```
### shell ### shell
Specify the shell for a script (similar to the shebang, if you for any reason don't want to add one) (since [0.4.5](https://github.com/koalaman/shellcheck/issues/581#issuecomment-249437837)): Specify the shell for a script (similar to the shebang, if you for any reason don't want to add one) (since [0.4.5](https://github.com/koalaman/shellcheck/issues/581#issuecomment-249437837)):
# shellcheck shell=sh ```sh
echo foo &> bar # shellcheck shell=sh
echo foo &> bar
```
Directives that replace or are immediately after the shebang apply to the entire script. Otherwise, they are scoped to the command that follows it (including compound commands like function definitions, loops and case statements). A directive may only be applied to a complete command, and can not be used immediately preceding an `else` block or individual `case` branch: Directives that replace or are immediately after the shebang apply to the entire script. Otherwise, they are scoped to the command that follows it (including compound commands like function definitions, loops and case statements). A directive may only be applied to a complete command, and can not be used immediately preceding an `else` block or individual `case` branch:
```sh
# Directive VALID here, applies to whole `case` # Directive VALID here, applies to whole `case`
case $1 in case $1 in
# Directive INVALID, `-v)` is not a complete command # Directive INVALID, `-v)` is not a complete command
-v) -v)
# Directive VALID here, applies to whole `if` # Directive VALID here, applies to whole `if`
@@ -42,18 +50,20 @@ Directives that replace or are immediately after the shebang apply to the entire
v=1 v=1
fi ;; fi ;;
esac esac
```
There is no support for scoping a directive to the first structure of the script. In these cases, use a dummy command `true` or `:` and then add directives, such as There is no support for scoping a directive to the first structure of the script. In these cases, use a dummy command `true` or `:` and then add directives, such as
# This directive applies to the entire script ```sh
# shellcheck disable=2086 # This directive applies to the entire script
true # shellcheck disable=2086
true
# This directive only applies to this function # This directive only applies to this function
# shellcheck disable=2043 # shellcheck disable=2043
f() { f() {
... ...
} }
```
Silencing parser errors is purely cosmetic; any parser error found will still stop ShellCheck at the point of the error. Silencing parser errors is purely cosmetic; any parser error found will still stop ShellCheck at the point of the error.