soumya92/barista

View on GitHub

Showing 99 of 99 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} 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

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

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 1 place. Go fmt your code!
Open

// Copyright 2017 Google Inc.
Severity: Minor
Found in samples/sample-bar/cachehttp.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

First header should be a top level header
Open

## Contributor License Agreement
Severity: Info
Found in CONTRIBUTING.md by markdownlint

MD002 - First header should be a top level header

Tags: headers

Aliases: first-header-h1

Parameters: level (number; default 1)

This rule is triggered when the first header in the document isn't a h1 header:

## This isn't a H1 header

### Another header

The first header in the document should be a h1 header:

# Start with a H1 header

## Then use a H2 for subsections

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

// Copyright 2018 Google Inc.
Severity: Minor
Found in logging/nop.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

var childId should be childID
Open

        oldName, childId := nameAndId(child)
Severity: Minor
Found in logging/id.go by golint

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

    go test \
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

Line length
Open

<img src="https://raw.githubusercontent.com/soumya92/barista/gh-pages/logo/128.png" height="128" width="128" alt="Logo" />
Severity: Info
Found in README.md by markdownlint

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.

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

Your code does not pass gofmt in 1 place. 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 1 place. Go fmt your code!
Open

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

Expressions don't expand in single quotes, use double quotes for that.
Open

'for try in `seq 1 3`; do 
Severity: Minor
Found in test.sh by shellcheck

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.

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

        -coverprofile=profiles/$(echo "PKG" | sed -e "s|./||" -e "s|/|_|g").out \
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.

Can't follow non-constant source. Use a directive to specify location.
Open

[ -e "$CONFIG_DIR/barista/keys" ] && . "$CONFIG_DIR/barista/keys"
Severity: Minor
Found in build.sh by shellcheck

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.

Severity
Category
Status
Source
Language