Dalphi/dalphi

View on GitHub
app/helpers/breadcrumb_bakery.rb

Summary

Maintainability
A
30 mins
Test Coverage

Class has too many lines. [106/100]
Open

class BreadcrumbBakery
  include Rails.application.routes.url_helpers

  def initialize(request)
    tokens = url_tokens(request.original_url)
Severity: Minor
Found in app/helpers/breadcrumb_bakery.rb by rubocop

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

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

  def initialize(request)
    tokens = url_tokens(request.original_url)
    @breadcrumbs = []
    subpath = ''
    predecessor_token = nil
Severity: Minor
Found in app/helpers/breadcrumb_bakery.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.

Avoid too many return statements within this method.
Open

    return action_label(token) if is_action?(token)
Severity: Major
Found in app/helpers/breadcrumb_bakery.rb - About 30 mins to fix

    Align .classify with predecessor_token on line 82.
    Open

                  .classify
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

    Rename is_class? to class?.
    Open

      def is_class?(klass)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Rename is_integer_and_action? to integer_and_action?.
    Open

      def is_integer_and_action?(integer_and_action)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Missing top-level class documentation comment.
    Open

    class BreadcrumbBakery
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Align .constantize with predecessor_token on line 82.
    Open

                  .constantize
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

    Avoid using rescue in its modifier form.
    Open

        model = predecessor_token
                  .singularize
                  .classify
                  .constantize
                  .find(integer)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Rename is_action? to action?.
    Open

      def is_action?(action)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Prefer to_s over string interpolation.
    Open

          subpath << "#{token}"
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Rename has_breadcrumb_exception? to breadcrumb_exception?.
    Open

      def has_breadcrumb_exception?(tokens)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Avoid using rescue in its modifier form.
    Open

        I18n.t("breadcrumb-exceptions.#{path}", raise: true) rescue false
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Avoid using rescue in its modifier form.
    Open

        klass.classify.constantize rescue false
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Use 2 spaces for indentation in a hash, relative to the start of the line where the left curly brace is.
    Open

                            label: label,
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

    By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

    Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

    This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

    Example: EnforcedStyle: specialinsideparentheses (default)

    # The `special_inside_parentheses` style enforces that the first key
    # in a hash literal where the opening brace and the first key are on
    # separate lines is indented one step (two spaces) more than the
    # position inside the opening parentheses.
    
    # bad
    hash = {
      key: :value
    }
    and_in_a_method_call({
      no: :difference
                         })
    
    # good
    special_inside_parentheses
    hash = {
      key: :value
    }
    but_in_a_method_call({
                           its_like: :this
                         })

    Example: EnforcedStyle: consistent

    # The `consistent` style enforces that the first key in a hash
    # literal where the opening brace and the first key are on
    # seprate lines is indented the same as a hash literal which is not
    # defined inside a method call.
    
    # bad
    hash = {
      key: :value
    }
    but_in_a_method_call({
                           its_like: :this
                          })
    
    # good
    hash = {
      key: :value
    }
    and_in_a_method_call({
      no: :difference
    })

    Example: EnforcedStyle: align_braces

    # The `align_brackets` style enforces that the opening and closing
    # braces are indented to the same position.
    
    # bad
    and_now_for_something = {
                              completely: :different
    }
    
    # good
    and_now_for_something = {
                              completely: :different
                            }

    %w-literals should be delimited by [ and ].
    Open

        return action if %w(edit new).include?(action)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop enforces the consistent usage of %-literal delimiters.

    Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

    Example:

    # Style/PercentLiteralDelimiters:
    #   PreferredDelimiters:
    #     default: '[]'
    #     '%i':    '()'
    
    # good
    %w[alpha beta] + %i(gamma delta)
    
    # bad
    %W(alpha #{beta})
    
    # bad
    %I(alpha beta)

    Use %r around regular expression.
    Open

        return integer_and_action if integer_and_action =~ /[0-9]+\/\S+/
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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\//

    Rename is_integer? to integer?.
    Open

      def is_integer?(object)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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

    Indent the right brace the same as the start of the line where the left brace is.
    Open

                          } unless label.empty?
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cops checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the AlignHash cop.

    By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

    Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

    This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

    Example: EnforcedStyle: specialinsideparentheses (default)

    # The `special_inside_parentheses` style enforces that the first key
    # in a hash literal where the opening brace and the first key are on
    # separate lines is indented one step (two spaces) more than the
    # position inside the opening parentheses.
    
    # bad
    hash = {
      key: :value
    }
    and_in_a_method_call({
      no: :difference
                         })
    
    # good
    special_inside_parentheses
    hash = {
      key: :value
    }
    but_in_a_method_call({
                           its_like: :this
                         })

    Example: EnforcedStyle: consistent

    # The `consistent` style enforces that the first key in a hash
    # literal where the opening brace and the first key are on
    # seprate lines is indented the same as a hash literal which is not
    # defined inside a method call.
    
    # bad
    hash = {
      key: :value
    }
    but_in_a_method_call({
                           its_like: :this
                          })
    
    # good
    hash = {
      key: :value
    }
    and_in_a_method_call({
      no: :difference
    })

    Example: EnforcedStyle: align_braces

    # The `align_brackets` style enforces that the opening and closing
    # braces are indented to the same position.
    
    # bad
    and_now_for_something = {
                              completely: :different
    }
    
    # good
    and_now_for_something = {
                              completely: :different
                            }

    Favor a normal unless-statement over a modifier clause in a multiline statement.
    Open

          @breadcrumbs << {
                            label: label,
                            path: subpath.clone
                          } unless label.empty?
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    Checks for uses of if/unless modifiers with multiple-lines bodies.

    Example:

    # bad
    {
      result: 'this should not happen'
    } unless cond
    
    # good
    { result: 'ok' } if cond

    Avoid using rescue in its modifier form.
    Open

        Integer(object) rescue false
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Align .find with predecessor_token on line 82.
    Open

                  .find(integer)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

    Avoid using rescue in its modifier form.
    Open

        Rails.application.routes.recognize_path(path) rescue false
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Align .label with predecessor_token on line 82.
    Open

                  .label rescue integer
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

    Align .singularize with predecessor_token on line 82.
    Open

                  .singularize
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks the indentation of the method name part in method calls that span more than one line.

    Example: EnforcedStyle: aligned

    # bad
    while myvariable
    .b
      # do something
    end
    
    # good
    while myvariable
          .b
      # do something
    end
    
    # good
    Thing.a
         .b
         .c

    Example: EnforcedStyle: indented

    # good
    while myvariable
      .b
    
      # do something
    end

    Example: EnforcedStyle: indentedrelativeto_receiver

    # good
    while myvariable
            .a
            .b
    
      # do something
    end
    
    # good
    myvariable = Thing
                   .a
                   .b
                   .c

    Avoid using rescue in its modifier form.
    Open

        predecessor_token
          .singularize
          .classify
          .constantize
          .find(integer)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop checks for uses of rescue in its modifier form.

    Example:

    # bad
    some_method rescue handle_error
    
    # good
    begin
      some_method
    rescue
      handle_error
    end

    Use %r around regular expression.
    Open

          .gsub(/^http(|s):\/\/[^\/]+(|:[0-9]+)/, '') # remove protocol, domain and port
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    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. [84/80]
    Open

          .gsub(/^http(|s):\/\/[^\/]+(|:[0-9]+)/, '') # remove protocol, domain and port
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    Line is too long. [94/80]
    Open

        return integer_and_action_label(token, predecessor_token) if is_integer_and_action?(token)
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    Use attr_reader to define trivial reader methods.
    Open

      def breadcrumbs
    Severity: Minor
    Found in app/helpers/breadcrumb_bakery.rb by rubocop

    This cop looks for trivial reader/writer methods, that could have been created with the attr_* family of functions automatically.

    Example:

    # bad
    def foo
      @foo
    end
    
    def bar=(val)
      @bar = val
    end
    
    def self.baz
      @baz
    end
    
    # good
    attr_reader :foo
    attr_writer :bar
    
    class << self
      attr_reader :baz
    end

    There are no issues that match your filters.

    Category
    Status