TracksApp/tracks

View on GitHub
lib/done_todos.rb

Summary

Maintainability
A
1 hr
Test Coverage

DoneTodos#self.done_between has 4 parameters
Open

  def self.done_between(todos, includes, start_date, end_date)
Severity: Minor
Found in lib/done_todos.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

DoneTodos#self.completed_period has approx 6 statements
Open

  def self.completed_period(date)
Severity: Minor
Found in lib/done_todos.rb by reek

A method with Too Many Statements is any method that has a large number of lines.

Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

So the following method would score +6 in Reek's statement-counting algorithm:

def parse(arg, argv, &error)
  if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
    return nil, block, nil                                         # +1
  end
  opt = (val = parse_arg(val, &error))[1]                          # +2
  val = conv_arg(*val)                                             # +3
  if opt and !arg
    argv.shift                                                     # +4
  else
    val[0] = nil                                                   # +5
  end
  val                                                              # +6
end

(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

DoneTodos has no descriptive comment
Open

class DoneTodos
Severity: Minor
Found in lib/done_todos.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

Avoid too many return statements within this method.
Open

    return nil
Severity: Major
Found in lib/done_todos.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

        return "rest_of_month" if date >= beginning_of_month
    Severity: Major
    Found in lib/done_todos.rb - About 30 mins to fix

      DoneTodos#self.remaining_in_container performs a nil-check
      Open

          return nil if period.nil?
      Severity: Minor
      Found in lib/done_todos.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      DoneTodos#self.completed_period performs a nil-check
      Open

          return nil if date.nil?
      Severity: Minor
      Found in lib/done_todos.rb by reek

      A NilCheck is a type check. Failures of NilCheck violate the "tell, don't ask" principle.

      Additionally, type checks often mask bigger problems in your source code like not using OOP and / or polymorphism when you should.

      Example

      Given

      class Klass
        def nil_checker(argument)
          if argument.nil?
            puts "argument isn't nil!"
          end
        end
      end

      Reek would emit the following warning:

      test.rb -- 1 warning:
        [3]:Klass#nil_checker performs a nil-check. (NilCheck)

      TODO found
      Open

          # TODO: refactor to remove outer hash from includes param
      Severity: Minor
      Found in lib/done_todos.rb by fixme

      TODO found
      Open

          # TODO: refactor to remove outer hash from includes param
      Severity: Minor
      Found in lib/done_todos.rb by fixme

      private (on line 36) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
      Open

        def self.beginning_of_month
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

      Example:

      # bad
      
      class C
        private
      
        def self.method
          puts 'hi'
        end
      end

      Example:

      # good
      
      class C
        def self.method
          puts 'hi'
        end
      
        private_class_method :method
      end

      Example:

      # good
      
      class C
        class << self
          private
      
          def method
            puts 'hi'
          end
        end
      end

      Missing magic comment # frozen_string_literal: true.
      Open

      class DoneTodos
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      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 `<<` are
      # called on a string literal.
      # bad
      module Bar
        # ...
      end
      
      # good
      # frozen_string_literal: true
      
      module Bar
        # ...
      end

      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

      Redundant return detected. To return multiple values, use an array.
      Open

          return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      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.

      Line is too long. [123/120]
      Open

          return "today"         if date >= end_of_day # Treat todos with completed_at in future as done today (happens in tests)
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      Redundant return detected.
      Open

          return count
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      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.

      private (on line 36) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
      Open

        def self.done_between(todos, includes, start_date, end_date)
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

      Example:

      # bad
      
      class C
        private
      
        def self.method
          puts 'hi'
        end
      end

      Example:

      # good
      
      class C
        def self.method
          puts 'hi'
        end
      
        private_class_method :method
      end

      Example:

      # good
      
      class C
        class << self
          private
      
          def method
            puts 'hi'
          end
        end
      end

      Redundant return detected.
      Open

          return nil
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      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.

      private (on line 36) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
      Open

        def self.beginning_of_week
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

      Example:

      # bad
      
      class C
        private
      
        def self.method
          puts 'hi'
        end
      end

      Example:

      # good
      
      class C
        def self.method
          puts 'hi'
        end
      
        private_class_method :method
      end

      Example:

      # good
      
      class C
        class << self
          private
      
          def method
            puts 'hi'
          end
        end
      end

      private (on line 36) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
      Open

        def self.beginning_of_day
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

      Example:

      # bad
      
      class C
        private
      
        def self.method
          puts 'hi'
        end
      end

      Example:

      # good
      
      class C
        def self.method
          puts 'hi'
        end
      
        private_class_method :method
      end

      Example:

      # good
      
      class C
        class << self
          private
      
          def method
            puts 'hi'
          end
        end
      end

      private (on line 36) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
      Open

        def self.end_of_day
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

      Example:

      # bad
      
      class C
        private
      
        def self.method
          puts 'hi'
        end
      end

      Example:

      # good
      
      class C
        def self.method
          puts 'hi'
        end
      
        private_class_method :method
      end

      Example:

      # good
      
      class C
        class << self
          private
      
          def method
            puts 'hi'
          end
        end
      end

      Useless private access modifier.
      Open

        private
      Severity: Minor
      Found in lib/done_todos.rb by rubocop

      This cop checks for redundant access modifiers, including those with no code, those which are repeated, and leading public modifiers in a class or module body. Conditionally-defined methods are considered as always being defined, and thus access modifiers guarding such methods are not redundant.

      Example:

      class Foo
        public # this is redundant (default access is public)
      
        def method
        end
      
        private # this is not redundant (a method is defined)
        def method2
        end
      
        private # this is redundant (no following methods are defined)
      end

      Example:

      class Foo
        # The following is not redundant (conditionally defined methods are
        # considered as always defining a method)
        private
      
        if condition?
          def method
          end
        end
      
        protected # this is not redundant (method is defined)
      
        define_method(:method2) do
        end
      
        protected # this is redundant (repeated from previous modifier)
      
        [1,2,3].each do |i|
          define_method("foo#{i}") do
          end
        end
      
        # The following is redundant (methods defined on the class'
        # singleton class are not affected by the public modifier)
        public
      
        def self.method3
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   ContextCreatingMethods:
      #     - concerning
      require 'active_support/concern'
      class Foo
        concerning :Bar do
          def some_public_method
          end
      
          private
      
          def some_private_method
          end
        end
      
        # this is not redundant because `concerning` created its own context
        private
      
        def some_other_private_method
        end
      end

      Example:

      # Lint/UselessAccessModifier:
      #   MethodCreatingMethods:
      #     - delegate
      require 'active_support/core_ext/module/delegation'
      class Foo
        # this is not redundant because `delegate` creates methods
        private
      
        delegate :method_a, to: :method_b
      end

      There are no issues that match your filters.

      Category
      Status