Showing 2,662 of 2,662 total issues
0.5
should be written without a leading zero as .5
Open
padding-top: 0.5em;
- Exclude checks
Don't use variables in the printf format string. Use printf "..%s.." "$foo". Open
printf "\n${CLEAR_LINE}${RED}💀 Rubocop couldn't autocorrect everything! 😠${NO_COLOR}\n"
- Read upRead up
- Exclude checks
Don't use variables in the printf format string. Use printf "..%s.." "$foo".
Problematic code:
printf "Hello, $NAME\n"
Correct code:
printf "Hello, %s\n" "$NAME"
Rationale:
printf
interprets escape sequences and format specifiers in the format string. If variables are included, any escape sequences or format specifiers in the data will be interpreted too, when you most likely wanted to treat it as data. Example:
coverage='96%'
printf "Unit test coverage: %s\n" "$coverage"
printf "Unit test coverage: $coverage\n"
The first printf writes Unit test coverage: 96%
.
The second writes bash: printf: `\': invalid format character
Exceptions
Sometimes you may actually want to interpret data as a format string, like in:
hexToAscii() { printf "\x$1"; }
hexToAscii 21
or when you have a pattern in a variable:
filepattern="file-%d.jpg"
printf -v filename "$filepattern" "$number"
These are valid use cases with no useful rewrites. Please [[ignore]] the warnings with a [[directive]].
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Quote this to prevent word splitting. Open
wait $(jobs -p)
- Read upRead up
- Exclude checks
Quote this to prevent word splitting
Problematic code:
ls -l $(getfilename)
Correct code:
# getfilename outputs 1 file
ls -l "$(getfilename)"
# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
ls -l "$line"
done
Rationale:
When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.
Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.
If the command substitution outputs multiple pieces of data, use a loop instead.
Exceptions
In rare cases you actually want word splitting, such as in
gcc $(pkg-config --libs openssl) client.c
This is because pkg-config
outputs -lssl -lcrypto
, which you want to break up by spaces into -lssl
and -lcrypto
. An alternative is to put the variables to an array and expand it:
args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c
The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:
compile () {
args=( $(pkg-config --libs openssl) "${@}" )
gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Quote this to prevent word splitting. Open
rbenv global $(cat /tmp/.ruby-version)
- Read upRead up
- Exclude checks
Quote this to prevent word splitting
Problematic code:
ls -l $(getfilename)
Correct code:
# getfilename outputs 1 file
ls -l "$(getfilename)"
# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
ls -l "$line"
done
Rationale:
When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.
Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.
If the command substitution outputs multiple pieces of data, use a loop instead.
Exceptions
In rare cases you actually want word splitting, such as in
gcc $(pkg-config --libs openssl) client.c
This is because pkg-config
outputs -lssl -lcrypto
, which you want to break up by spaces into -lssl
and -lcrypto
. An alternative is to put the variables to an array and expand it:
args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c
The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:
compile () {
args=( $(pkg-config --libs openssl) "${@}" )
gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Unnecessary parent selector (&) Open
& > h1, & > h2, & > h3, & > h4, & > h5, & > h6, & > p, & > table, & > ul, & > ol, & > aside, & > dl {
- Exclude checks
Unnecessary parent selector (&) Open
& > ul, & > ol {
- Exclude checks
Each selector in a comma sequence should be on its own single line Open
p, li, dt, dd {
- Exclude checks
0.05
should be written without a leading zero as .05
Open
background-color: rgba(0, 0, 0, 0.05);
- Exclude checks
Expected item on line 498 to appear before line 488. Rule sets should be ordered as follows: @extends
, @includes
without @content
, properties, @includes
with @content
, nested rule sets Open
@extend %right-col;
- Exclude checks
Color literals like #fff
should only be used in variable declarations; they should be referred to via variable everywhere else. Open
color: #fff;
- Exclude checks
Color literals like #ccc
should only be used in variable declarations; they should be referred to via variable everywhere else. Open
border-bottom: dashed 1px #ccc;
- Exclude checks
egrep is non-standard and deprecated. Use grep -E instead. Open
dirs=$(ls -l version | egrep '^d' | awk '{print $9}' | grep -v alpha | sort --version-sort -r)
- Read upRead up
- Exclude checks
egrep is non-standard and deprecated. Use grep -E instead.
Problematic code:
egrep 'foo|bar' file
Correct code:
grep -E 'foo|bar' file
Rationale:
egrep
is a non-standard command. Its functionality is provided in POSIX by grep -E
. POSIX grep says:
This grep has been enhanced in an upwards-compatible way to provide the exact functionality of the historical egrep and fgrep commands as well. It was the clear intention of the standard developers to consolidate the three greps into a single command.
man grep for GNU says:
Direct invocation as either egrep or fgrep is deprecated
Exceptions:
ShellCheck will fail to recognize when functions override egrep
. Consider giving it a different name or [[ignore]] this error.
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Quote this to prevent word splitting. Open
wait $(jobs -p)
- Read upRead up
- Exclude checks
Quote this to prevent word splitting
Problematic code:
ls -l $(getfilename)
Correct code:
# getfilename outputs 1 file
ls -l "$(getfilename)"
# getfilename outputs multiple files, linefeed separated
getfilename | while IFS='' read -r line
do
ls -l "$line"
done
Rationale:
When command expansions are unquoted, word splitting and globbing will occur. This often manifests itself by breaking when filenames contain spaces.
Trying to fix it by adding quotes or escapes to the data will not work. Instead, quote the command substitution itself.
If the command substitution outputs multiple pieces of data, use a loop instead.
Exceptions
In rare cases you actually want word splitting, such as in
gcc $(pkg-config --libs openssl) client.c
This is because pkg-config
outputs -lssl -lcrypto
, which you want to break up by spaces into -lssl
and -lcrypto
. An alternative is to put the variables to an array and expand it:
args=( $(pkg-config --libs openssl) )
gcc "${args[@]}" client.c
The power of using an array becomes evident when you want to combine, for example, the command result with user-provided arguments:
compile () {
args=( $(pkg-config --libs openssl) "${@}" )
gcc "${args[@]}" client.c
}
compile -DDEBUG
+ gcc -lssl -lcrypto -DDEBUG client.c
Notice
Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.
Unnecessary parent selector (&) Open
& > h1, & > h2, & > h3, & > h4, & > h5, & > h6, & > p, & > table, & > ul, & > ol, & > aside, & > dl {
- Exclude checks
Each selector in a comma sequence should be on its own single line Open
p, li, dt, dd {
- Exclude checks
0.5
should be written without a leading zero as .5
Open
padding-right: 0.5em;
- Exclude checks
Merge rule aside.warning:before
with rule on line 445 Open
aside.warning:before {
- Exclude checks
Properties should be ordered float, width Open
width: auto;
- Exclude checks
Unnecessary parent selector (&) Open
& > h1, & > h2, & > h3, & > h4, & > h5, & > h6, & > p, & > table, & > ul, & > ol, & > aside, & > dl {
- Exclude checks
Expected item on line 317 to appear before line 313. Rule sets should be ordered as follows: @extends
, @includes
without @content
, properties, @includes
with @content
, nested rule sets Open
@extend %left-col;
- Exclude checks