newtheatre/history-project

View on GitHub

Showing 115 of 117 total issues

Literal """Method called for every year""" used in void context.
Open

      """Method called for every year"""
Severity: Minor
Found in _plugins/year.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Literal """Returns a hash of shows by year""" used in void context.
Open

      """Returns a hash of shows by year"""
Severity: Minor
Found in _plugins/show.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Use tr instead of gsub.
Open

        I18n.transliterate(input).gsub(" ", "-").gsub(/[^\\dA-Za-z\-]/,"").downcase
Severity: Minor
Found in _plugins/anchor_filter.rb by rubocop

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Unused method argument - context. If it's necessary, use _ or _context as an argument name to indicate that it won't be used. You can also write as render(*) if you want the method to accept any arguments but don't care about them.
Open

    def render(context)
Severity: Minor
Found in _plugins/static.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Literal """Method called for each show, runs asset generators on each""" used in void context.
Open

      """Method called for each show, runs asset generators on each"""
Severity: Minor
Found in _plugins/assets.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Shadowing outer local variable - venue.
Open

      @collection.docs.each do |venue|
Severity: Minor
Found in _plugins/venue.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Use tr instead of gsub.
Open

      venue_name.downcase.gsub(/[^a-z0-9 -]/, '').gsub(/ /, '-').gsub('---', '-')
Severity: Minor
Found in _plugins/venue.rb by rubocop

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Literal """Send a person_list to the reverse index""" used in void context.
Open

      """Send a person_list to the reverse index"""
Severity: Minor
Found in _plugins/show.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Double quote to prevent globbing and word splitting.
Open

  echo "DEPLOY_NAME=${PR_NUM}" >> $GITHUB_OUTPUT
Severity: Minor
Found in _bin/deploy_vars.sh by shellcheck

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.

Double quote to prevent globbing and word splitting.
Open

  echo "DEPLOY_NAME=${REF_NAME}" >> $GITHUB_OUTPUT
Severity: Minor
Found in _bin/deploy_vars.sh by shellcheck

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.

Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
Open

    if [[ $? != 0 ]]; then
Severity: Minor
Found in _bin/yamllint.sh by shellcheck

Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

Problematic code:

make mytarget

if [ $? -ne 0 ]
then
  echo "Build failed"
fi

Correct code:

if ! make mytarget
then
  echo "Build failed"
fi

Rationale:

Running a command and then checking its exit status $? against 0 is redundant.

Instead of just checking the exit code of a command, it checks the exit code of a command (e.g. [) that checks the exit code of a command.

Apart from the redundancy, there are other reasons to avoid this pattern:

  • Since the command and its status test are decoupled, inserting an innocent command like echo "make finished" after make will cause the if statement to silently start comparing echo's status instead.
  • Scripts that run or are called with set -e aka errexit will exit immediately if the command fails, even though they're followed by a clause that handles failure.
  • The value of $? is overwritten by [/[[, so you can't get the original value in the relevant then/else block (e.g. if mycmd; then echo "Success"; else echo "Failed with $?"; fi).

To check that a command returns success, use if mycommand; then ....

To check that a command returns failure, use if ! mycommand; then ....

To additionally capture output with command substitution: if output=$(mycommand); then ...

This also applies to while/until loops.

Exceptions:

The default Solaris 10 bourne shell does not support '!' outside of the test command (if ! mycommand; then ... returns !: not found)

Notice

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

Line exceeds maximum allowed length
Open

      # From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Sorting_with_map
Severity: Minor
Found in _coffee/app/archive_sort.coffee by coffeelint

Unused method argument - context. If it's necessary, use _ or _context as an argument name to indicate that it won't be used. You can also write as render(*) if you want the method to accept any arguments but don't care about them.
Open

    def render(context)
Severity: Minor
Found in _plugins/git.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Literal """Add additional data to a person_list""" used in void context.
Open

  """Add additional data to a person_list"""
Severity: Minor
Found in _plugins/person_list.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Unused block argument - site. You can omit the argument if you don't care about it.
Open

Jekyll::Hooks.register :site, :after_init do |site|
Severity: Minor
Found in _plugins/hooks.rb by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Unused block argument - site. You can omit the argument if you don't care about it.
Open

Jekyll::Hooks.register :site, :post_write do |site|
Severity: Minor
Found in _plugins/hooks.rb by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Literal """Return the two character representation of the year span as a list""" used in void context.
Open

      """Return the two character representation of the year span as a list"""
Severity: Minor
Found in _plugins/year.rb by rubocop

This cop checks for operators, variables and literals used in void context.

Example:

# bad

def some_method
  some_num * 10
  do_something
end

Example:

# bad

def some_method(some_var)
  some_var
  do_something
end

Example:

# good

def some_method
  do_something
  some_num * 10
end

Example:

# good

def some_method(some_var)
  do_something
  some_var
end

Unused block argument - city. If it's necessary, use _ or _city as an argument name to indicate that it won't be used.
Open

      site.data['venues_by_city'].each do |city, venues|
Severity: Minor
Found in _plugins/venue.rb by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Useless assignment to variable - show_crew_count.
Open

      show_crew_count = show.data["crew"] ? show.data["crew"].length : 0
Severity: Minor
Found in _plugins/show.rb by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Line exceeds maximum allowed length
Open

    ret += "<tr class=\"album-row\" data-key=\"#{ album["AlbumKey"] }\"><td><a href=\"#{ album['WebUri'] }\" class=\"usage-link\">#{ album["Name"] }</a></td><td>#{ album["AlbumKey"] }</td><td>#{ album["ImageCount"] }</td><td class=\"usage\">?</td></tr>\n"
Severity: Minor
Found in _coffee/scripts/utility.coffee by coffeelint
Severity
Category
Status
Source
Language