Showing 106 of 106 total issues
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line. Open
"PKG" \
- Read upRead up
- Exclude checks
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
Problematic code:
var='This is long \
piece of text'
Correct code:
var='This is a long '\
'piece of text'
Rationale:
You have a single quoted string containing a backslash followed by a linefeed (newline). Unlike double quotes or unquoted strings, this has no special meaning. The string will contain a literal backslash and a linefeed.
If you wanted to break the line but not add a linefeed to the string, stop the single quote, break the line, and reopen it. This is demonstrated in the correct code.
If you wanted to break the line and also include the linefeed as a literal, you don't need a backslash:
var='This is a multi-line string
with an embedded linefeed'
Exceptions:
If you do want a string containing a literal backslash+linefeed combo, such as with sed
, you can [[ignore]] this warning.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Line length Open
<img src="https://raw.githubusercontent.com/soumya92/barista/gh-pages/logo/128.png" height="128" width="128" alt="Logo" />
- Read upRead up
- Exclude checks
MD013 - Line length
Tags: line_length
Aliases: line-length Parameters: linelength, codeblocks, tables (number; default 80, boolean; default true)
This rule is triggered when there are lines that are longer than the configured line length (default: 80 characters). To fix this, split the line up into multiple lines.
This rule has an exception where there is no whitespace beyond the configured line length. This allows you to still include items such as long URLs without being forced to break them in the middle.
You also have the option to exclude this rule for code blocks and tables. To
do this, set the code_blocks
and/or tables
parameters to false.
Code blocks are included in this rule by default since it is often a requirement for document readability, and tentatively compatible with code rules. Still, some languages do not lend themselves to short lines.
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line. Open
-covermode=atomic \
- Read upRead up
- Exclude checks
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
Problematic code:
var='This is long \
piece of text'
Correct code:
var='This is a long '\
'piece of text'
Rationale:
You have a single quoted string containing a backslash followed by a linefeed (newline). Unlike double quotes or unquoted strings, this has no special meaning. The string will contain a literal backslash and a linefeed.
If you wanted to break the line but not add a linefeed to the string, stop the single quote, break the line, and reopen it. This is demonstrated in the correct code.
If you wanted to break the line and also include the linefeed as a literal, you don't need a backslash:
var='This is a multi-line string
with an embedded linefeed'
Exceptions:
If you do want a string containing a literal backslash+linefeed combo, such as with sed
, you can [[ignore]] this warning.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2017 Google Inc.
- Exclude checks
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2020 Google Inc.
- Exclude checks
var rootId should be rootID Open
var rootId = identify(Root)
- Exclude checks
Double quote array expansions to avoid re-splitting elements. Open
for KEY in ${KEYS[@]}; do
- Read upRead up
- Exclude checks
Double quote array expansions to avoid re-splitting elements.
Problematic code:
cp $@ ~/dir
Correct code:
cp "$@" ~/dir
Rationale:
Double quotes around $@
(and similarly, ${array[@]}
) prevents globbing and word splitting of individual elements, while still expanding to multiple separate arguments.
Let's say you have three arguments: baz
, foo bar
and *
"$@"
will expand into exactly that: baz
, foo bar
and *
$@
will expand into multiple other arguments: baz
, foo
, bar
, file.txt
and otherfile.jpg
Since the latter is rarely expected or desired, ShellCheck warns about it.
Exceptions
When you want globbing of individual elements.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
var parentId should be parentID Open
if parentId := nodes[childId].parent; !parentId.zero() {
- Exclude checks
func nameAndId should be nameAndID Open
func nameAndId(thing interface{}) (name string, id ident) {
- Exclude checks
Double quote to prevent globbing and word splitting. Open
seq 1 $total | xargs -n 1 -P $parallel $0 BARISTA_FLAKE_TEST "$tmpdir" go test -v -race -tags debuglog "$@" -- -finelog=
- Read upRead up
- Exclude checks
Double quote to prevent globbing and word splitting.
Problematic code:
echo $1
for i in $*; do :; done # this done and the next one also applies to expanding arrays.
for i in $@; do :; done
Correct code:
echo "$1"
for i in "$@"; do :; done # or, 'for i; do'
Rationale
The first code looks like "print the first argument". It's actually "Split the first argument by IFS (spaces, tabs and line feeds). Expand each of them as if it was a glob. Join all the resulting strings and filenames with spaces. Print the result."
The second one looks like "iterate through all arguments". It's actually "join all the arguments by the first character of IFS (space), split them by IFS and expand each of them as globs, and iterate on the resulting list". The third one skips the joining part.
Quoting variables prevents word splitting and glob expansion, and prevents the script from breaking when input contains spaces, line feeds, glob characters and such.
Strictly speaking, only expansions themselves need to be quoted, but for stylistic reasons, entire arguments with multiple variable and literal parts are often quoted as one:
$HOME/$dir/dist/bin/$file # Unquoted (bad)
"$HOME"/"$dir"/dist/bin/"$file" # Minimal quoting (good)
"$HOME/$dir/dist/bin/$file" # Canonical quoting (good)
When quoting composite arguments, make sure to exclude globs and brace expansions, which lose their special meaning in double quotes: "$HOME/$dir/src/*.c"
will not expand, but "$HOME/$dir/src"/*.c
will.
Note that $( )
starts a new context, and variables in it have to be quoted independently:
echo "This $variable is quoted $(but this $variable is not)"
echo "This $variable is quoted $(and now this "$variable" is too)"
Exceptions
Sometimes you want to split on spaces, like when building a command line:
options="-j 5 -B"
make $options file
Just quoting this doesn't work. Instead, you should have used an array (bash, ksh, zsh):
options=(-j 5 -B) # ksh: set -A options -- -j 5 -B
make "${options[@]}" file
or a function (POSIX):
make_with_flags() { make -j 5 -B "$@"; }
make_with_flags file
To split on spaces but not perform glob expansion, Posix has a set -f
to disable globbing. You can disable word splitting by setting IFS=''
.
Similarly, you might want an optional argument:
debug=""
[[ $1 == "--trace-commands" ]] && debug="-x"
bash $debug script
Quoting this doesn't work, since in the default case, "$debug"
would expand to one empty argument while $debug
would expand into zero arguments. In this case, you can use an array with zero or one elements as outlined above, or you can use an unquoted expansion with an alternate value:
debug=""
[[ $1 == "--trace-commands" ]] && debug="yes"
bash ${debug:+"-x"} script
This is better than an unquoted value because the alternative value can be properly quoted, e.g. wget ${output:+ -o "$output"}
.
As always, this warning can be [[ignore]]d on a case-by-case basis.
this is especially relevant when BASH many not be available for the array work around. For example, use in eval or in command options where script has total control of the variables...
FLAGS="-av -e 'ssh -x' --delete --delete-excluded"
...
# shellcheck disable=SC2086
eval rsync $FLAGS ~/dir remote_host:dir
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Expressions don't expand in single quotes, use double quotes for that. Open
'for try in `seq 1 3`; do
- Read upRead up
- Exclude checks
Expressions don't expand in single quotes, use double quotes for that.
Problematic code:
name=World
echo 'Hello $name'
Correct code:
name=World
echo "Hello $name"
Rationale:
Single quotes prevent expansion of everything, including variables and command substitution.
If you want to use the values of variables and such, use double quotes instead.
Note that if you have other items that needs single quoting, you can use both in a single word:
echo '$1 USD is '"$rate GBP"
Exceptions
If you want $stuff
to be a literal dollar sign followed by the characters "stuff", you can [[ignore]] this message.
ShellCheck tries to be smart about it, and won't warn when this is used with awk, perl and similar, but there are some inherent ambiguities like 'I have $1 in my wallet'
, which could be "one dollar" or "whatever's in the first parameter".
In the particular case of sed
, ShellCheck uses additional heuristics to try to separate cases like 's/$foo/bar/'
(failing to replace the variable $foo
) with from the false positives like '$d'
(delete last line). If you're still triggering these, consider being more generous with your spaces: use $ { s/foo/bar; }
instead of ${s/foo/bar/;}
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2020 Google Inc.
- Exclude checks
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2018 Google Inc.
- Exclude checks
var parentId should be parentID Open
parentName, parentId := nameAndId(parent)
- Exclude checks
Inline HTML Open
<img src="https://raw.githubusercontent.com/soumya92/barista/gh-pages/logo/128.png" height="128" width="128" alt="Logo" />
- Read upRead up
- Exclude checks
MD033 - Inline HTML
Tags: html
Aliases: no-inline-html
This rule is triggered whenever raw HTML is used in a markdown document:
Inline HTML header
To fix this, use 'pure' markdown instead of including raw HTML:
# Markdown header
Rationale: Raw HTML is allowed in markdown, but this rule is included for those who want their documents to only include "pure" markdown, or for those who are rendering markdown documents in something other than HTML.
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2017 Google Inc.
- Exclude checks
Your code does not pass gofmt in 1 place. Go fmt your code! Open
// Copyright 2020 Google Inc.
- Exclude checks
Can't follow non-constant source. Use a directive to specify location. Open
[ -e "$CONFIG_DIR/barista/keys" ] && . "$CONFIG_DIR/barista/keys"
- Read upRead up
- Exclude checks
Can't follow non-constant source. Use a directive to specify location.
Problematic code:
. "$(find_install_dir)/lib.sh"
Correct code:
# shellcheck source=src/lib.sh
. "$(find_install_dir)/lib.sh"
Rationale:
ShellCheck is not able to include sourced files from paths that are determined at runtime. The file will not be read, potentially resulting in warnings about unassigned variables and similar.
Use a [[Directive]] to point shellcheck to a fixed location it can read instead.
Exceptions:
If you don't care that ShellCheck is unable to account for the file, specify # shellcheck source=/dev/null
.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line. Open
-race \
- Read upRead up
- Exclude checks
This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
Problematic code:
var='This is long \
piece of text'
Correct code:
var='This is a long '\
'piece of text'
Rationale:
You have a single quoted string containing a backslash followed by a linefeed (newline). Unlike double quotes or unquoted strings, this has no special meaning. The string will contain a literal backslash and a linefeed.
If you wanted to break the line but not add a linefeed to the string, stop the single quote, break the line, and reopen it. This is demonstrated in the correct code.
If you wanted to break the line and also include the linefeed as a literal, you don't need a backslash:
var='This is a multi-line string
with an embedded linefeed'
Exceptions:
If you do want a string containing a literal backslash+linefeed combo, such as with sed
, you can [[ignore]] this warning.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
var thingId should be thingID Open
thingName, thingId := nameAndId(thing)
- Exclude checks