ripta/drydock

View on GitHub
lib/drydock/ignorefile_definition.rb

Summary

Maintainability
A
45 mins
Test Coverage

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

    def initialize(file_or_filename, dotfiles: false)
      @dotfiles = dotfiles

      if file_or_filename.respond_to?(:readlines)
        patterns = Array(file_or_filename.readlines)
Severity: Minor
Found in lib/drydock/ignorefile_definition.rb - About 45 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

Use alias instead of alias_method in a class body.
Open

      alias_method :exclude?, :exclude

This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

Example: EnforcedStyle: prefer_alias (default)

# bad
alias_method :bar, :foo
alias :bar :foo

# good
alias bar foo

Example: EnforcedStyle: preferaliasmethod

# bad
alias :bar :foo
alias bar foo

# good
alias_method :bar, :foo

Empty line missing at class body beginning.
Open

      alias_method :exclude?, :exclude

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Missing top-level class documentation comment.
Open

    class Rule < Struct.new(:pattern, :exclude)

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Pass &:exclude? as an argument to select instead of a block.
Open

      @rules.select { |rule| rule.exclude? }.any? do |rule|

Use symbols as procs when possible.

Example:

# bad
something.map { |s| s.upcase }

# good
something.map(&:upcase)

Use the return of the conditional for variable assignment and comparison.
Open

      if file_or_filename.respond_to?(:readlines)
        patterns = Array(file_or_filename.readlines)
      else
        patterns = File.exist?(file_or_filename) ? File.readlines(file_or_filename) : []
      end

Empty line missing at class body beginning.
Open

    class Rule < Struct.new(:pattern, :exclude)

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Missing top-level class documentation comment.
Open

  class IgnorefileDefinition

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Don't extend an instance initialized by Struct.new.
Open

    class Rule < Struct.new(:pattern, :exclude)

This cop checks for inheritance from Struct.new.

Example:

# bad
class Person < Struct.new(:first_name, :last_name)
end

# good
Person = Struct.new(:first_name, :last_name)

Redundant return detected.
Open

      return false

This cop checks for redundant return expressions.

Example:

def test
  return something
end

def test
  one
  two
  three
  return something
end

It should be extended to handle methods whose body is if/else or a case expression with a default branch.

Empty line missing at class body end.
Open

    end

This cops checks if empty lines around the bodies of classes match the configuration.

Example: EnforcedStyle: empty_lines

# good

class Foo

  def bar
    # ...
  end

end

Example: EnforcedStyle: emptylinesexcept_namespace

# good

class Foo
  class Bar

    # ...

  end
end

Example: EnforcedStyle: emptylinesspecial

# good
class Foo

  def bar; end

end

Example: EnforcedStyle: noemptylines (default)

# good

class Foo
  def bar
    # ...
  end
end

Rename is_dotfile? to dotfile?.
Open

    def is_dotfile?(filename)

This cop makes sure that predicates are named properly.

Example:

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

There are no issues that match your filters.

Category
Status