TracksApp/tracks

View on GitHub
app/models/recurring_todos/weekly_recurring_todos_builder.rb

Summary

Maintainability
A
0 mins
Test Coverage

RecurringTodos::WeeklyRecurringTodosBuilder#map_day has 4 parameters
Open

    def map_day(mapping, key, source_key, index)

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.

RecurringTodos::WeeklyRecurringTodosBuilder#map_day calls 'mapping.get(key)' 3 times
Open

      mapping.set(key, mapping.get(key)[0, index] + mapping.get(source_key) + mapping.get(key)[index + 1, mapping.get(key).length])

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.

RecurringTodos::WeeklyRecurringTodosBuilder has no descriptive comment
Open

  class WeeklyRecurringTodosBuilder < AbstractRecurringTodosBuilder

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

RecurringTodos::WeeklyRecurringTodosBuilder#map_day doesn't depend on instance state (maybe move it to another class?)
Open

    def map_day(mapping, key, source_key, index)

A Utility Function is any instance method that has no dependency on the state of the instance.

RecurringTodos::WeeklyRecurringTodosBuilder#attributes_to_filter doesn't depend on instance state (maybe move it to another class?)
Open

    def attributes_to_filter

A Utility Function is any instance method that has no dependency on the state of the instance.

Complex method RecurringTodos::WeeklyRecurringTodosBuilder#map_day (20.1)
Open

    def map_day(mapping, key, source_key, index)
      mapping.set_if_nil(key, '       ')  # avoid nil
      mapping.set_if_nil(source_key, ' ') # avoid nil

      mapping.set(key, mapping.get(key)[0, index] + mapping.get(source_key) + mapping.get(key)[index + 1, mapping.get(key).length])

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

RecurringTodos::WeeklyRecurringTodosBuilder#valid_selector? has unused parameter 'key'
Open

    def valid_selector?(key)

Unused Parameter refers to methods with parameters that are unused in scope of the method.

Having unused parameters in a method is code smell because leaving dead code in a method can never improve the method and it makes the code confusing to read.

Example

Given:

class Klass
  def unused_parameters(x,y,z)
    puts x,y # but not z
  end
end

Reek would emit the following warning:

[2]:Klass#unused_parameters has unused parameter 'z' (UnusedParameters)

Do not use spaces inside percent literal delimiters.
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Checks for unnecessary additional spaces inside the delimiters of %i/%w/%x literals.

Example:

# good
%i(foo bar baz)

# bad
%w( foo bar baz )

# bad
%x(  ls -l )

Missing magic comment # frozen_string_literal: true.
Open

module RecurringTodos

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

Do not use spaces inside percent literal delimiters.
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Checks for unnecessary additional spaces inside the delimiters of %i/%w/%x literals.

Example:

# good
%i(foo bar baz)

# bad
%w( foo bar baz )

# bad
%x(  ls -l )

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
Open

      .each do |day, index|

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

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

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

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)

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

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

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)

Space missing to the left of {.
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Checks that block braces have or don't have a space before the opening brace depending on configuration.

Example:

# bad
foo.map{ |a|
  a.bar.to_s
}

# good
foo.map { |a|
  a.bar.to_s
}

Do not use spaces inside percent literal delimiters.
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Checks for unnecessary additional spaces inside the delimiters of %i/%w/%x literals.

Example:

# good
%i(foo bar baz)

# bad
%w( foo bar baz )

# bad
%x(  ls -l )

Unused method argument - key. If it's necessary, use _ or _key as an argument name to indicate that it won't be used. You can also write as valid_selector?(*) if you want the method to accept any arguments but don't care about them.
Open

    def valid_selector?(key)

This cop checks for unused method arguments.

Example:

# bad

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Example:

# good

def some_method(used, _unused, _unused_but_allowed)
  puts used
end

Line is too long. [148/120]
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Line is too long. [131/120]
Open

      mapping.set(key, mapping.get(key)[0, index] + mapping.get(source_key) + mapping.get(key)[index + 1, mapping.get(key).length])

Do not use spaces inside percent literal delimiters.
Open

      %w{ weekly_selector weekly_every_x_week } + %w{ monday tuesday wednesday thursday friday saturday sunday }.map{ |day| "weekly_return_#{day}" }

Checks for unnecessary additional spaces inside the delimiters of %i/%w/%x literals.

Example:

# good
%i(foo bar baz)

# bad
%w( foo bar baz )

# bad
%x(  ls -l )

There are no issues that match your filters.

Category
Status