mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Revert e8cb74cc185d80bae6ec5a736e90aac55bdf8215...3f78e63e5e682b905d59df45ae617021adee0fdc on Directive
26
Directive.md
26
Directive.md
@@ -1,4 +1,4 @@
|
|||||||
# ShellCheck directives
|
# ShellCheck Directives
|
||||||
|
|
||||||
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:
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@ hexToAscii() {
|
|||||||
|
|
||||||
or entries in a `.shellcheckrc` in the project root or user's home directory:
|
or entries in a `.shellcheckrc` in the project root or user's home directory:
|
||||||
|
|
||||||
```shellcheckrc
|
```none
|
||||||
# ~/.shellcheckrc
|
$ cat ~/.shellcheckrc
|
||||||
|
|
||||||
# Don't suggest [ -n "$VAR" ] over [ ! -z "$VAR" ]
|
# Don't suggest [ -n "$VAR" ] over [ ! -z "$VAR" ]
|
||||||
disable=SC2236
|
disable=SC2236
|
||||||
@@ -23,23 +23,21 @@ enable=require-variable-braces
|
|||||||
|
|
||||||
## Supported directives
|
## Supported directives
|
||||||
|
|
||||||
### `disable`
|
### disable
|
||||||
Prevent ShellCheck from processing one or more warnings:
|
Prevent shellcheck from processing one or more warnings:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# shellcheck disable=code[,code...]
|
# shellcheck disable=code[,code...]
|
||||||
statement_where_warning_should_be_disabled
|
statement_where_warning_should_be_disabled
|
||||||
```
|
```
|
||||||
|
|
||||||
A range of errors can also be specified, handy when disabling things for the entire file.
|
A range of errors can also be specified, handy when disbaling things for the entire file.
|
||||||
```sh
|
```sh
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# shellcheck disable=SC1000-SC9999
|
# shellcheck disable=SC1000-SC9999
|
||||||
```
|
```
|
||||||
|
|
||||||
An alias `all` is available instead of specifying 0-9999 to disable all checks.
|
### enable
|
||||||
|
|
||||||
### `enable`
|
|
||||||
|
|
||||||
Enables an [[optional]] check (since 0.7.0).
|
Enables an [[optional]] check (since 0.7.0).
|
||||||
|
|
||||||
@@ -51,7 +49,7 @@ echo "Hello $USER" # Will suggest ${USER}
|
|||||||
|
|
||||||
To see a list of optional checks with examples, run `shellcheck --list-optional`. See [[here|optional]] for more information.
|
To see a list of optional checks with examples, run `shellcheck --list-optional`. See [[here|optional]] for more information.
|
||||||
|
|
||||||
### `external-sources`
|
### external-sources
|
||||||
|
|
||||||
Set whether or not to follow arbitrary file paths in `source` statements (since 0.8.0).
|
Set whether or not to follow arbitrary file paths in `source` statements (since 0.8.0).
|
||||||
|
|
||||||
@@ -59,7 +57,7 @@ Use `external-sources=true` in `.shellcheckrc` to let shellcheck access arbitrar
|
|||||||
|
|
||||||
Individual script files can disable but not enable this option.
|
Individual script files can disable but not enable this option.
|
||||||
|
|
||||||
### `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):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -67,9 +65,9 @@ Tell ShellCheck where to find a sourced file (since 0.4.0):
|
|||||||
. "$(locate_config)"
|
. "$(locate_config)"
|
||||||
```
|
```
|
||||||
|
|
||||||
### `source-path`
|
### source-path
|
||||||
|
|
||||||
Give ShellCheck a path in which to search for sourced files (since 0.7.0).
|
Give ShellCheck a path in which to search for sourced file (since 0.7.0).
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# The script will now look for src/examples/mylib.sh
|
# The script will now look for src/examples/mylib.sh
|
||||||
@@ -89,7 +87,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
|||||||
. "$here/utils.sh"
|
. "$here/utils.sh"
|
||||||
```
|
```
|
||||||
|
|
||||||
### `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)):
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user