cloudfoundry/cloud_controller_ng

View on GitHub

Showing 2,662 of 2,662 total issues

Each selector in a comma sequence should be on its own single line
Open

  h1:first-child, div:first-child + h1 {

Properties should be ordered border-bottom, font-size, padding, vertical-align
Open

      padding: 5px 10px;

Begin pseudo elements with double colons: ::
Open

  aside.warning:before {

Avoid qualifying class selectors with an element.
Open

  aside.warning:before {

Color literals like #fff should only be used in variable declarations; they should be referred to via variable everywhere else.
Open

    color: #fff;

Color literals like #909090 should only be used in variable declarations; they should be referred to via variable everywhere else.
Open

  color: #909090;

Don't use variables in the printf format string. Use printf "..%s.." "$foo".
Open

  printf "\n${CLEAR_LINE}${RED}💀 Rubocop found some issues. Let's see if it can autocorrect the files you're trying to commit...${NO_COLOR}\n"
Severity: Minor
Found in scripts/rubocop-pre-commit by shellcheck

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.

SCRIPT_DIR appears unused. Verify it or export it.
Open

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

foo appears unused. Verify it or export it.

Problematic code:

foo=42
echo "$FOO"

Correct code:

foo=42
echo "$foo"

Rationale:

Variables not used for anything are often associated with bugs, so ShellCheck warns about them.

Also note that something like local let foo=42 does not make a let statement local -- it instead declares an additional local variable named let.

Exceptions

ShellCheck may not always realize that the variable is in use (especially with indirection), and may not realize you don't care (with throwaway variables or unimplemented features).

For throwaway variables, consider using _ as a dummy:

read _ last _ zip _ _ <<< "$str"
echo "$last, $zip"

or use a directive to disable the warning:

# shellcheck disable=SC2034
read first last email zip lat lng <<< "$str"
echo "$last, $zip"

For indirection, there's not much you can do without rewriting to use arrays or similar:

bar=42  # will always appear unused
foo=bar
echo "${!foo}"

This is expected behavior, and not a bug. There is no good way to statically analyze indirection in shell scripts, just like static C analyzers have a hard time preventing segfaults.

As always, there are ways to [[ignore]] this and other messages if they frequently get in your way.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

Color literals like #ccc should only be used in variable declarations; they should be referred to via variable everywhere else.
Open

      border-bottom: 1px solid #ccc;

Selector should have depth of applicability no greater than 3, but was 4
Open

    tr:nth-child(even) > td {

Color literals like #000 should only be used in variable declarations; they should be referred to via variable everywhere else.
Open

      border-top: 1px solid #000;

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Open

if ! cat /etc/hosts | grep "uaa.service.cf.internal" > /dev/null; then

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

Problematic code:

cat file | tr ' ' _ | nl
cat file | while IFS= read -r i; do echo "${i%?}"; done

Correct code:

< file tr ' ' _ | nl  
while IFS= read -r i; do echo "${i%?}"; done < file

Rationale:

cat is a tool for con"cat"enating files. Reading a single file as input to a program is considered a Useless Use Of Cat (UUOC).

It's more efficient and less roundabout to simply use redirection. This is especially true for programs that can benefit from seekable input, like tail or tar.

Many tools also accept optional filenames, e.g. grep -q foo file instead of cat file | grep -q foo.

Exceptions

Pointing out UUOC is a long standing shell programming tradition, and removing them from a short-lived pipeline in a loop can speed it up by 2x. However, it's not necessarily a good use of time in practice, and rarely affects correctness. [[Ignore]] as you see fit.

Notice

Original content from the ShellCheck https://github.com/koalaman/shellcheck/wiki.

0.5 should be written without a leading zero as .5
Open

    padding-bottom: 0.5em;

0.05 should be written without a leading zero as .05
Open

    background-color: rgba(0, 0, 0, 0.05);

Begin pseudo elements with double colons: ::
Open

  aside:before {

Properties should be ordered background-color, border-bottom, border-radius, border-top, color, padding
Open

      border-radius: 5px;

Quote this to prevent word splitting.
Open

  wait $(jobs -p)
Severity: Minor
Found in devenv.sh by shellcheck

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.

Each selector in a comma sequence should be on its own single line
Open

  & > ul, & > ol {

Properties should be ordered border-top, clear, margin-bottom, margin-top, padding-bottom, padding-top
Open

    margin-top: 4em;

Properties should be ordered background-color, border-radius, color
Open

      border-radius: 0;
Severity
Category
Status
Source
Language