acook/config_module

View on GitHub

Showing 19 of 19 total issues

Assignment Branch Condition size for load_namespaces_from is too high. [22.36/15]
Open

    def load_namespaces_from tree
      namespaces.inject(ConfigOption.wrap(tree)) do |subtree, ns|
        if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns)
          ConfigOption.wrap subtree[ns]
        else
Severity: Minor
Found in lib/config_module/config_helper.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [15/10]
Open

    def load_namespaces_from tree
      namespaces.inject(ConfigOption.wrap(tree)) do |subtree, ns|
        if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns)
          ConfigOption.wrap subtree[ns]
        else
Severity: Minor
Found in lib/config_module/config_helper.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [14/10]
Open

    def method_missing name, *args, &block
      result = super

      if result || @table.has_key?(name)
        self.class.wrap result
Severity: Minor
Found in lib/config_module/config_option.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

ConfigModule::ConfigHelper#load_namespaces_from calls 'namespaces.first' 2 times
Open

        InvalidNamespaceError.new(namespaces.first, self, caller),
        "Namespace must be a string or symbol, instead it was: #{namespaces.first.class}", caller(6)
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

ConfigModule::ConfigHelper has no descriptive comment
Open

  class ConfigHelper
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ConfigModule::ConfigError#object_info calls 'object.class' 2 times
Open

        "instance of `#{object.class} < #{object.class.superclass}'"
Severity: Minor
Found in lib/config_module/exceptions.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

ConfigModule::InvalidNamespaceError has no descriptive comment
Open

  class InvalidNamespaceError < ConfigError
Severity: Minor
Found in lib/config_module/exceptions.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ConfigModule::ConfigOption assumes too much for instance variable '@table'
Open

  class ConfigOption < OpenStruct
Severity: Minor
Found in lib/config_module/config_option.rb by reek

Classes should not assume that instance variables are set or present outside of the current class definition.

Good:

class Foo
  def initialize
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Good as well:

class Foo
  def foo?
    bar == :foo
  end

  def bar
    @bar ||= :foo
  end
end

Bad:

class Foo
  def go_foo!
    @bar = :foo
  end

  def foo?
    @bar == :foo
  end
end

Example

Running Reek on:

class Dummy
  def test
    @ivar
  end
end

would report:

[1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

Note that this example would trigger this smell warning as well:

class Parent
  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    @omg
  end
end

The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

class Parent
  attr_reader :omg

  def initialize(omg)
    @omg = omg
  end
end

class Child < Parent
  def foo
    omg
  end
end

Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

If you don't want to expose those methods as public API just make them private like this:

class Parent
  def initialize(omg)
    @omg = omg
  end

  private
  attr_reader :omg
end

class Child < Parent
  def foo
    omg
  end
end

Current Support in Reek

An instance variable must:

  • be set in the constructor
  • or be accessed through a method with lazy initialization / memoization.

If not, Instance Variable Assumption will be reported.

ConfigModule::ConfigOption has no descriptive comment
Open

  class ConfigOption < OpenStruct
Severity: Minor
Found in lib/config_module/config_option.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ConfigModule::ConfigOption#method_missing calls 'caller(3)' 2 times
Open

          "Key not found: #{name}", caller(3)
        )
      end
    rescue NoMethodError => error
      raise(
Severity: Minor
Found in lib/config_module/config_option.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

ConfigModule::ConfigOption::NotFoundError has no descriptive comment
Open

    class NotFoundError < ::ConfigModule::ConfigError
Severity: Minor
Found in lib/config_module/config_option.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ConfigModule has no descriptive comment
Open

module ConfigModule
Severity: Minor
Found in lib/config_module.rb by reek

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

ConfigModule::ConfigHelper#load_namespaces_from manually dispatches method call
Open

        if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns)
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

Example

class MyManualDispatcher
  attr_reader :foo

  def initialize(foo)
    @foo = foo
  end

  def call
    foo.bar if foo.respond_to?(:bar)
  end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

ConfigModule::ConfigOption#new_ostruct_member manually dispatches method call
Open

        unless respond_to? name
Severity: Minor
Found in lib/config_module/config_option.rb by reek

Reek reports a Manual Dispatch smell if it finds source code that manually checks whether an object responds to a method before that method is called. Manual dispatch is a type of Simulated Polymorphism which leads to code that is harder to reason about, debug, and refactor.

Example

class MyManualDispatcher
  attr_reader :foo

  def initialize(foo)
    @foo = foo
  end

  def call
    foo.bar if foo.respond_to?(:bar)
  end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [9]: MyManualDispatcher manually dispatches method call (ManualDispatch)

ConfigModule::ConfigHelper#load_namespaces_from calls 'caller(6)' 2 times
Open

            "No subkey with name: #{ns.inspect}", caller(6)
          )
        end
      end
    rescue TypeError
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

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

    def load_namespaces_from tree
      namespaces.inject(ConfigOption.wrap(tree)) do |subtree, ns|
        if ConfigOption === subtree && ns.respond_to?(:to_sym) && subtree.has_key?(ns)
          ConfigOption.wrap subtree[ns]
        else
Severity: Minor
Found in lib/config_module/config_helper.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

ConfigModule::ConfigHelper#config_file is a writable attribute
Open

    attr_accessor :config_file
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

The same holds to a lesser extent for getters, but Reek doesn't flag those.

Example

Given:

class Klass
  attr_accessor :dummy
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Klass declares the writable attribute dummy (Attribute)

ConfigModule::ConfigHelper#namespaces is a writable attribute
Open

    attr_writer :namespaces
Severity: Minor
Found in lib/config_module/config_helper.rb by reek

A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

The same holds to a lesser extent for getters, but Reek doesn't flag those.

Example

Given:

class Klass
  attr_accessor :dummy
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Klass declares the writable attribute dummy (Attribute)

Prefer $INPUT_RECORD_SEPARATOR or $RS from the stdlib 'English' module (don't forget to require it) over $/.
Open

  gem.files = `git ls-files`.split($/)
Severity: Minor
Found in config_module.gemspec by rubocop
Severity
Category
Status
Source
Language