drapergem/draper

View on GitHub

Showing 213 of 213 total issues

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

  class Decorator
    include Draper::ViewHelpers
    include Draper::Compatibility::GlobalID if defined?(GlobalID)
    extend Draper::Delegation

Severity: Minor
Found in lib/draper/decorator.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.

Block has too many lines. [76/25]
Open

m = Module.new do
  module_function

  def invoked_as_script?
    File.expand_path($0) == File.expand_path(__FILE__)
Severity: Minor
Found in bin/bundle by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Class Decorator has 27 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Decorator
    include Draper::ViewHelpers
    include Draper::Compatibility::GlobalID if defined?(GlobalID)
    extend Draper::Delegation

Severity: Minor
Found in lib/draper/decorator.rb - About 3 hrs to fix

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

      def cli_arg_version
        return unless invoked_as_script? # don't want to hijack other binstubs
        return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
        bundler_version = nil
        update_index = nil
    Severity: Minor
    Found in bin/bundle 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.

    Cyclomatic complexity for cli_arg_version is too high. [8/6]
    Open

      def cli_arg_version
        return unless invoked_as_script? # don't want to hijack other binstubs
        return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
        bundler_version = nil
        update_index = nil
    Severity: Minor
    Found in bin/bundle by rubocop

    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 cli_arg_version is too high. [8/7]
    Open

      def cli_arg_version
        return unless invoked_as_script? # don't want to hijack other binstubs
        return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
        bundler_version = nil
        update_index = nil
    Severity: Minor
    Found in bin/bundle by rubocop

    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 activate_bundler is too high. [16.4/15]
    Open

      def activate_bundler
        gem_error = activation_error_handling do
          gem "bundler", bundler_requirement
        end
        return if gem_error.nil?
    Severity: Minor
    Found in bin/bundle 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

    Block has too many lines. [30/25]
    Open

    namespace "spec" do
      task "all" => ["draper", "generators", "integration"]
    
      def spec_task(name)
        desc "Run #{name} specs"
    Severity: Minor
    Found in Rakefile by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Block has too many lines. [26/25]
    Open

    Gem::Specification.new do |s|
      s.name        = "draper"
      s.version     = Draper::VERSION
      s.authors     = ["Jeff Casimir", "Steve Klabnik"]
      s.email       = ["jeff@casimircreative.com", "steve@steveklabnik.com"]
    Severity: Minor
    Found in draper.gemspec by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

          def decorator_class(called_on = self)
            prefix = respond_to?(:model_name) ? model_name : name
            decorator_name = "#{prefix}Decorator"
            decorator_name_constant = decorator_name.safe_constantize
            return decorator_name_constant unless decorator_name_constant.nil?
    Severity: Minor
    Found in lib/draper/decoratable.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

    Space inside { missing.
    Open

    rspec_guard spec_paths: 'spec/integration', env: {'RAILS_ENV' => 'development'} do
    Severity: Minor
    Found in Guardfile by rubocop

    Checks that braces used for hash literals have or don't have surrounding space depending on configuration.

    Example: EnforcedStyle: space

    # The `space` style enforces that hash literals have
    # surrounding space.
    
    # bad
    h = {a: 1, b: 2}
    
    # good
    h = { a: 1, b: 2 }

    Example: EnforcedStyle: no_space

    # The `no_space` style enforces that hash literals have
    # no surrounding space.
    
    # bad
    h = { a: 1, b: 2 }
    
    # good
    h = {a: 1, b: 2}

    Example: EnforcedStyle: compact

    # The `compact` style normally requires a space inside
    # hash braces, with the exception that successive left
    # braces or right braces are collapsed together in nested hashes.
    
    # bad
    h = { a: { b: 2 } }
    
    # good
    h = { a: { b: 2 }}

    Missing magic comment # frozen_string_literal: true.
    Open

    module Draper

    This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

    Example: EnforcedStyle: when_needed (default)

    # The `when_needed` style will add the frozen string literal comment
    # to files only when the `TargetRubyVersion` is set to 2.3+.
    # bad
    module Foo
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Foo
      # ...
    end

    Example: EnforcedStyle: always

    # The `always` style will always add the frozen string literal comment
    # to a file, regardless of the Ruby version or if `freeze` or `<

    Example: EnforcedStyle: never

    # The `never` will enforce that the frozen string literal comment does
    # not exist in a file.
    # bad
    # frozen_string_literal: true
    
    module Baz
      # ...
    end
    
    # good
    module Baz
      # ...
    end

    Rename is_above_rails_5_1 to above_rails_5_1?.
    Open

            def is_above_rails_5_1

    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 module documentation comment.
    Open

        module LoadStrategy

    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

    Use alias l localize instead of alias :l :localize.
    Open

        alias :l :localize
    Severity: Minor
    Found in lib/draper/view_helpers.rb by rubocop

    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

    Replace class var @@default_query_methods_strategy with a class instance var.
    Open

          @@default_query_methods_strategy ||= :active_record
    Severity: Minor
    Found in lib/draper/configuration.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Line is too long. [108/100]
    Open

            decorated_associations[association] ||= Draper::DecoratedAssociation.new(self, association, options)
    Severity: Minor
    Found in lib/draper/decorator.rb by rubocop

    Missing top-level class documentation comment.
    Open

      class Decorator
    Severity: Minor
    Found in lib/draper/decorator.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

    Indent access modifiers like module_function.
    Open

      module_function
    Severity: Minor
    Found in bin/bundle by rubocop

    Modifiers should be indented as deep as method definitions, or as deep as the class/module keyword, depending on configuration.

    Example: EnforcedStyle: indent (default)

    # bad
    class Plumbus
    private
      def smooth; end
    end
    
    # good
    class Plumbus
      private
      def smooth; end
    end

    Example: EnforcedStyle: outdent

    # bad
    class Plumbus
      private
      def smooth; end
    end
    
    # good
    class Plumbus
    private
      def smooth; end
    end

    Missing top-level class documentation comment.
    Open

      class UninferrableDecoratorError < NameError
    Severity: Minor
    Found in lib/draper.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
    Severity
    Category
    Status
    Source
    Language