rambler-digital-solutions/Generamba

View on GitHub
lib/generamba/code_generation/code_module.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Assignment Branch Condition size for initialize is too high. [66.9/15]
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username

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. [31/10]
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username

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.

Cyclomatic complexity for initialize is too high. [16/6]
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for initialize is too high. [16/7]
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

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 initialize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username
Severity: Minor
Found in lib/generamba/code_generation/code_module.rb - About 2 hrs 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

Cyclomatic complexity for setup_file_and_group_paths is too high. [9/6]
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for setup_file_and_group_paths is too high. [9/7]
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Assignment Branch Condition size for setup_file_and_group_paths is too high. [16.49/15]
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")

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 setup_file_and_group_paths has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def setup_file_and_group_paths(file_path, group_path, path_type)
      if file_path || group_path
        variable_name = "#{path_type}_file_path"

        if file_path || !instance_variable_get("@#{variable_name}")
Severity: Minor
Found in lib/generamba/code_generation/code_module.rb - About 1 hr 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 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def initialize(name, rambafile, options)
      # Base initialization
      @name = name
      @description = options[:description] ? options[:description] : "#{name} module"
      @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username
Severity: Minor
Found in lib/generamba/code_generation/code_module.rb - About 1 hr to fix

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

            if file_path || !instance_variable_get("@#{variable_name}")
              file_path = group_path unless file_path
    
              variable_value = file_path.gsub(SLASH_REGEX, '')
              variable_value = Pathname.new(variable_value).join(@name)
    Severity: Minor
    Found in lib/generamba/code_generation/code_module.rb and 1 other location - About 25 mins to fix
    lib/generamba/code_generation/code_module.rb on lines 99..105

    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 29.

    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

            if group_path || !instance_variable_get("@#{variable_name}")
              group_path = file_path unless group_path
    
              variable_value = group_path.gsub(SLASH_REGEX, '')
              variable_value = Pathname.new(variable_value).join(@name)
    Severity: Minor
    Found in lib/generamba/code_generation/code_module.rb and 1 other location - About 25 mins to fix
    lib/generamba/code_generation/code_module.rb on lines 89..95

    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 29.

    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

    Use 2 (not 4) spaces for indentation.
    Open

              @project_file_root = Pathname.new(rambafile[PROJECT_FILE_PATH_KEY])

    This cops checks for indentation that doesn't use the specified number of spaces.

    See also the IndentationConsistency cop which is the companion to this one.

    Example:

    # bad
    class A
     def test
      puts 'hello'
     end
    end
    
    # good
    class A
      def test
        puts 'hello'
      end
    end

    Example: IgnoredPatterns: ['^\s*module']

    # bad
    module A
    class B
      def test
      puts 'hello'
      end
    end
    end
    
    # good
    module A
    class B
      def test
        puts 'hello'
      end
    end
    end

    Tab detected.
    Open

                    :test_file_root,

    Trailing whitespace detected.
    Open

          

    Line is too long. [110/80]
    Open

          setup_file_and_group_paths(options[:project_file_path], options[:project_group_path], PATH_TYPE_PROJECT)

    Line is too long. [120/80]
    Open

          setup_file_and_group_paths(rambafile[PROJECT_FILE_PATH_KEY], rambafile[PROJECT_GROUP_PATH_KEY], PATH_TYPE_PROJECT)

    Line is too long. [90/80]
    Open

          setup_file_and_group_paths(options[:test_path], options[:test_path], PATH_TYPE_TEST)

    Trailing whitespace detected.
    Open

          

    Line is too long. [89/80]
    Open

          @project_targets = [rambafile[PROJECT_TARGET_KEY]] if rambafile[PROJECT_TARGET_KEY]

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

          if file_path || group_path

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Use the double pipe equals operator ||= instead.
    Open

              file_path = group_path unless file_path

    This cop checks for potential usage of the ||= operator.

    Example:

    # bad
    name = name ? name : 'Bozhidar'
    
    # bad
    name = if name
             name
           else
             'Bozhidar'
           end
    
    # bad
    unless name
      name = 'Bozhidar'
    end
    
    # bad
    name = 'Bozhidar' unless name
    
    # good - set name to 'Bozhidar', only if it's nil or false
    name ||= 'Bozhidar'

    Extra empty line detected at module body beginning.
    Open

    
      SLASH_REGEX = /^\/|\/$/

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

    Example: EnforcedStyle: empty_lines

    # good
    
    module Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    module Foo
      module Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    module Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    module Foo
      def bar
        # ...
      end
    end

    Line is too long. [111/80]
    Open

          setup_file_and_group_paths(rambafile[TEST_FILE_PATH_KEY], rambafile[TEST_GROUP_PATH_KEY], PATH_TYPE_TEST)

    Line is too long. [81/80]
    Open

          @test_targets = options[:test_targets].split(',') if options[:test_targets]

    Freeze mutable objects assigned to constants.
    Open

      PATH_TYPE_TEST = 'test'

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    Align the parameters of a method call if they span more than one line.
    Open

                    :test_file_root,

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Line is too long. [109/80]
    Open

          @product_module_name = @project_name.gsub(C99IDENTIFIER, '_') if !@product_module_name && @project_name

    Line is too long. [107/80]
    Open

          @create_logical_groups = rambafile[CREATE_LOGICAL_GROUPS_KEY] if rambafile[CREATE_LOGICAL_GROUPS_KEY]

    Line is too long. [101/80]
    Open

          setup_file_and_group_paths(options[:test_file_path], options[:test_group_path], PATH_TYPE_TEST)

    Tab detected.
    Open

                    :project_file_root,

    Line is too long. [83/80]
    Open

          @cartfile_path = rambafile[CARTFILE_PATH_KEY] if rambafile[CARTFILE_PATH_KEY]

    Use %r around regular expression.
    Open

      SLASH_REGEX = /^\/|\/$/

    This cop enforces using // or %r around regular expressions.

    Example: EnforcedStyle: slashes (default)

    # bad
    snake_case = %r{^[\dA-Z_]+$}
    
    # bad
    regex = %r{
      foo
      (bar)
      (baz)
    }x
    
    # good
    snake_case = /^[\dA-Z_]+$/
    
    # good
    regex = /
      foo
      (bar)
      (baz)
    /x

    Example: EnforcedStyle: percent_r

    # bad
    snake_case = /^[\dA-Z_]+$/
    
    # bad
    regex = /
      foo
      (bar)
      (baz)
    /x
    
    # good
    snake_case = %r{^[\dA-Z_]+$}
    
    # good
    regex = %r{
      foo
      (bar)
      (baz)
    }x

    Example: EnforcedStyle: mixed

    # bad
    snake_case = %r{^[\dA-Z_]+$}
    
    # bad
    regex = /
      foo
      (bar)
      (baz)
    /x
    
    # good
    snake_case = /^[\dA-Z_]+$/
    
    # good
    regex = %r{
      foo
      (bar)
      (baz)
    }x

    Example: AllowInnerSlashes: false (default)

    # If `false`, the cop will always recommend using `%r` if one or more
    # slashes are found in the regexp string.
    
    # bad
    x =~ /home\//
    
    # good
    x =~ %r{home/}

    Example: AllowInnerSlashes: true

    # good
    x =~ /home\//

    Line is too long. [97/80]
    Open

          setup_file_and_group_paths(options[:module_path], options[:module_path], PATH_TYPE_PROJECT)

    Freeze mutable objects assigned to constants.
    Open

      PATH_TYPE_PROJECT = 'project'

    This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

    Example:

    # bad
    CONST = [1, 2, 3]
    
    # good
    CONST = [1, 2, 3].freeze

    Line is too long. [89/80]
    Open

          @project_targets = rambafile[PROJECT_TARGETS_KEY] if rambafile[PROJECT_TARGETS_KEY]

    Use the double pipe equals operator ||= instead.
    Open

              group_path = file_path unless group_path

    This cop checks for potential usage of the ||= operator.

    Example:

    # bad
    name = name ? name : 'Bozhidar'
    
    # bad
    name = if name
             name
           else
             'Bozhidar'
           end
    
    # bad
    unless name
      name = 'Bozhidar'
    end
    
    # bad
    name = 'Bozhidar' unless name
    
    # good - set name to 'Bozhidar', only if it's nil or false
    name ||= 'Bozhidar'

    Align the parameters of a method call if they span more than one line.
    Open

                    :project_file_root,

    Here we check if the parameters on a multi-line method call or definition are aligned.

    Example: EnforcedStyle: withfirstparameter (default)

    # good
    
    foo :bar,
        :baz
    
    # bad
    
    foo :bar,
      :baz

    Example: EnforcedStyle: withfixedindentation

    # good
    
    foo :bar,
      :baz
    
    # bad
    
    foo :bar,
        :baz

    Line is too long. [85/80]
    Open

          @description = options[:description] ? options[:description] : "#{name} module"

    Line is too long. [90/80]
    Open

          @project_targets = options[:project_targets].split(',') if options[:project_targets]

    Line is too long. [105/80]
    Open

          @author = rambafile[AUTHOR_NAME_KEY] ? rambafile[AUTHOR_NAME_KEY] : UserPreferences.obtain_username

    There are no issues that match your filters.

    Category
    Status