Skip to content

Commit

Permalink
Allow specifying color= in shellcheckrc (closes #2350)
Browse files Browse the repository at this point in the history
Signed-off-by: Olliver Schinagl <[email protected]>
  • Loading branch information
oliv3r committed Oct 7, 2021
1 parent 6f7eee4 commit cf26262
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Git (0.8.0)
### Added
- `color=` directive can be added to .shellceckrc
- `disable=all` now conveniently disables all warnings
- `external-sources=true` directive can be added to .shellcheckrc to make
shellcheck behave as if `-x` was specified.
Expand Down
10 changes: 10 additions & 0 deletions shellcheck.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ not warn at all, as `ksh` supports decimals in arithmetic contexts.
is *auto*. **--color** without an argument is equivalent to
**--color=always**.

This option may also be enabled using `color=` in
`.shellcheckrc`. This flag takes precedence.

**-i**\ *CODE1*[,*CODE2*...],\ **--include=***CODE1*[,*CODE2*...]

: Explicitly include only the specified codes in the report. Subsequent **-i**
Expand Down Expand Up @@ -232,6 +235,10 @@ Here a shell brace group is used to suppress a warning on multiple lines:

Valid keys are:

**color**
: Set to `auto`, `never` or `always` in `.shellcheckrc` to automatically
detect, never or always use color output with the `tty` output format.

**disable**
: Disables a comma separated list of error codes for the following command.
The command can be a simple command like `echo foo`, or a compound command
Expand Down Expand Up @@ -277,6 +284,9 @@ it will read `key=value` pairs from it and treat them as file-wide directives.

Here is an example `.shellcheckrc`:

# Always force color output on the tty output
color=always

# Look for 'source'd files relative to the checked script,
# and also look for absolute paths in /mnt/chroot
source-path=SCRIPTDIR
Expand Down
8 changes: 8 additions & 0 deletions src/ShellCheck/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,14 @@ readAnnotationWithoutPrefix sandboxed = do
key <- many1 (letter <|> char '-')
char '=' <|> fail "Expected '=' after directive key"
annotations <- case key of
"color" -> do
color <- many1 $ noneOf " \n"
option <- parseColorOption color
return options {
formatterOptions = (formatterOptions options) {
foColorOption = option
}
}
"disable" -> readElement `sepBy` char ','
where
readElement = readRange <|> readAll
Expand Down

0 comments on commit cf26262

Please sign in to comment.