nisevi/primes_table

View on GitHub

Showing 23 of 30 total issues

Matrix#load_table contains iterators nested 2 deep
Open

      columns.each do |column|
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

A Nested Iterator occurs when a block contains another block.

Example

Given

class Duck
  class << self
    def duck_names
      %i!tick trick track!.each do |surname|
        %i!duck!.each do |last_name|
          puts "full name is #{surname} #{last_name}"
        end
      end
    end
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

Matrix#header has approx 6 statements
Open

  def header(max)
Severity: Minor
Found in lib/primes_table/matrix.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.)

Matrix#load_table has approx 6 statements
Open

  def load_table(rows, columns)
Severity: Minor
Found in lib/primes_table/matrix.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.)

Matrix#format_collection calls 'i.to_s' 2 times
Open

    list.collect { |i| ' ' * (distance - i.to_s.size) + i.to_s }.join('  ').to_s
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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.

Matrix has no descriptive comment
Open

class Matrix
Severity: Minor
Found in lib/primes_table/matrix.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

Matrix#format_rows calls 'rows_header[index]' 2 times
Open

    len_index = rows_header[index].to_s.length
    format_prime = "#{rows_header[index]}#{' ' * (distance - len_index)}"
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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.

Matrix#format_collection doesn't depend on instance state (maybe move it to another class?)
Open

  def format_collection(list, distance)
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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

Matrix#next_prime doesn't depend on instance state (maybe move it to another class?)
Open

  def next_prime(flags, prime)
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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

Matrix#process_flags doesn't depend on instance state (maybe move it to another class?)
Open

  def process_flags(flags)
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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

Matrix#table is a writable attribute
Open

  attr_accessor :rows_header, :columns_header, :table
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

The same holds to a lesser extent for getters, but Reek doesn't flag those.

Example

Given:

class Klass
  attr_accessor :dummy
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Klass declares the writable attribute dummy (Attribute)

Matrix#load_table doesn't depend on instance state (maybe move it to another class?)
Open

  def load_table(rows, columns)
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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

Matrix#cross_off doesn't depend on instance state (maybe move it to another class?)
Open

  def cross_off(flags, prime)
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

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

Matrix#rows_header is a writable attribute
Open

  attr_accessor :rows_header, :columns_header, :table
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

The same holds to a lesser extent for getters, but Reek doesn't flag those.

Example

Given:

class Klass
  attr_accessor :dummy
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Klass declares the writable attribute dummy (Attribute)

Matrix#columns_header is a writable attribute
Open

  attr_accessor :rows_header, :columns_header, :table
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

The same holds to a lesser extent for getters, but Reek doesn't flag those.

Example

Given:

class Klass
  attr_accessor :dummy
end

Reek would emit the following warning:

reek test.rb

test.rb -- 1 warning:
  [2]:Klass declares the writable attribute dummy (Attribute)

Matrix#cross_off has the variable name 'i'
Open

    (prime * prime..flags.length).step(prime).each do |i|
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

Matrix#format_collection has the variable name 'i'
Open

    list.collect { |i| ' ' * (distance - i.to_s.size) + i.to_s }.join('  ').to_s
Severity: Minor
Found in lib/primes_table/matrix.rb by reek

An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

Line is too long. [88/80]
Open

  spec.summary       = 'Prints out a multiplication table of the first N prime numbers.'
Severity: Minor
Found in primes_table.gemspec by rubocop

Line is too long. [112/80]
Open

  spec.description   = 'Command line tool for printing out a multiplication table of the first N prime numbers.'
Severity: Minor
Found in primes_table.gemspec by rubocop

Line is too long. [91/80]
Open

  on('-r ROWS', '--rows', 'Amount of rows in table. Must be integer. Default value is 10.')
Severity: Minor
Found in bin/primes_table by rubocop

Freeze mutable objects assigned to constants.
Open

  VERSION = '0.1.3'
Severity: Minor
Found in lib/primes_table/version.rb by rubocop

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
Severity
Category
Status
Source
Language