soumya92/barista

View on GitHub

Showing 105 of 105 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if remainingSegments == 1 {
            if !isSet(s.HasSeparator()) && g.attrSet&sgaOuterSeparator != 0 {
                s.Separator(g.outerSeparator)
            }
            if !isSet(s.GetPadding()) && g.attrSet&sgaOuterPadding != 0 {
Severity: Minor
Found in outputs/group.go and 1 other location - About 30 mins to fix
outputs/group.go on lines 193..200

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 100.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  method_and_btn.each do |method, btn|
    out.write(<<~METHOD)

      // #{method} creates a click handler that invokes the given function
      // when a #{btn} event is received.
Severity: Minor
Found in base/click/buttons.rb and 1 other location - About 25 mins to fix
base/click/buttons.rb on lines 46..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 31.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  method_and_btn.each do |method, btn|
    out.write(<<~METHOD)

      // #{method} invokes the given function on #{btn} events.
      func (m Map) #{method}(do func()) Map {
Severity: Minor
Found in base/click/buttons.rb and 1 other location - About 25 mins to fix
base/click/buttons.rb on lines 30..41

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 31.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method from_c_type has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

def from_c_type(type)
  type = type.gsub('__extension__', '')
             .gsub('__restrict', '')
             .gsub('__BEGIN_DECLS', '')
             .gsub(/\bconst\b/, '')
Severity: Minor
Found in testing/capi/types.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def initialize(sig, idx)
    type, _, name = sig.rpartition ' '
    if type.empty? || (name == '*')
      type = "#{type} #{name}".strip
      name = "unnamed_#{idx}"
Severity: Minor
Found in testing/capi/funcs.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

// Copyright 2018 Google Inc.
Severity: Minor
Found in logging/nop.go by gofmt

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

// Copyright 2017 Google Inc.
Severity: Minor
Found in pango/pango.go by gofmt

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

// Copyright 2018 Google Inc.
Severity: Minor
Found in logging/id.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

// Copyright 2018 Google Inc.
Severity: Minor
Found in logging/logging.go by gofmt

This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
Open

        -timeout 90s \
Severity: Minor
Found in test.sh by shellcheck

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.

func nameAndId should be nameAndID
Open

func nameAndId(thing interface{}) (name string, id ident) {
Severity: Minor
Found in logging/id.go by golint

Emphasis used instead of a header
Open

**This is not an official Google product**
Severity: Info
Found in README.md by markdownlint

MD036 - Emphasis used instead of a header

Tags: headers, emphasis

Parameters: punctuation (string; default ".,;:!?")

Aliases: no-emphasis-as-header

This check looks for instances where emphasized (i.e. bold or italic) text is used to separate sections, where a header should be used instead:

**My document**

Lorem ipsum dolor sit amet...

_Another section_

Consectetur adipiscing elit, sed do eiusmod.

To fix this, use markdown headers instead of emphasized text to denote sections:

# My document

Lorem ipsum dolor sit amet...

## Another section

Consectetur adipiscing elit, sed do eiusmod.

Note: this rule looks for single line paragraphs that consist entirely of emphasized text. It won't fire on emphasis used within regular text, multi-line emphasized paragraphs, and paragraphs ending in punctuation. Similarly to rule MD026, you can configure what characters are recognized as punctuation.

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=
Severity: Minor
Found in testing/flakes.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 array expansions to avoid re-splitting elements.
Open

for KEY in ${KEYS[@]}; do
Severity: Minor
Found in build.sh by shellcheck

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.

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

// Copyright 2017 Google Inc.
Severity: Minor
Found in outputs/outputs.go by gofmt

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

// Copyright 2020 Google Inc.
Severity: Minor
Found in timing/timerfd_scheduler_fallback.go by gofmt

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

// Copyright 2017 Google Inc.
Severity: Minor
Found in pango/icons/icons.go by gofmt

var parentId should be parentID
Open

    if parentId := nodes[childId].parent; !parentId.zero() {
Severity: Minor
Found in logging/id.go by golint

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

// Copyright 2018 Google Inc.
Severity: Minor
Found in testing/output/output.go by gofmt

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

// Copyright 2020 Google Inc.
Severity: Minor
Found in timing/timerfd_scheduler.go by gofmt
Severity
Category
Status
Source
Language