metaminded/tabulatr2

View on GitHub
lib/tabulatr/params_builder.rb

Summary

Maintainability
A
0 mins
Test Coverage

Redundant self detected.
Open

          self.public_send("#{k}=", v)
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Freeze mutable objects assigned to constants.
Open

    DEPRECATED_PARAMS = []
Severity: Minor
Found in lib/tabulatr/params_builder.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

Redundant self detected.
Open

          self.public_send(k)
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

This cop checks for redundant uses of self.

The usage of self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

  • Calling an attribute writer to prevent an local variable assignment.

Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

Note we allow uses of self with operators because it would be awkward otherwise.

Example:

# bad
def foo(bar)
  self.baz
end

# good
def foo(bar)
  self.bar  # Resolves name clash with the argument.
end

def foo
  bar = 1
  self.bar  # Resolves name clash with the local variable.
end

def foo
  %w[x y z].select do |bar|
    self.bar == bar  # Resolves name clash with argument of the block.
  end
end

Closing array brace must be on the same line as the last array element when opening brace is on the same line as the first array element.
Open

                        ]
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

This cop checks that the closing brace in an array literal is either on the same line as the last array element, or a new line.

When using the symmetrical (default) style:

If an array's opening brace is on the same line as the first element of the array, then the closing brace should be on the same line as the last element of the array.

If an array's opening brace is on the line above the first element of the array, then the closing brace should be on the line below the last element of the array.

When using the new_line style:

The closing brace of a multi-line array literal must be on the line after the last element of the array.

When using the same_line style:

The closing brace of a multi-line array literal must be on the same line as the last element of the array.

Example: EnforcedStyle: symmetrical (default)

# bad
  [ :a,
    :b
  ]

  # bad
  [
    :a,
    :b ]

  # good
  [ :a,
    :b ]

  # good
  [
    :a,
    :b
  ]

Example: EnforcedStyle: new_line

# bad
  [
    :a,
    :b ]

  # bad
  [ :a,
    :b ]

  # good
  [ :a,
    :b
  ]

  # good
  [
    :a,
    :b
  ]

Example: EnforcedStyle: same_line

# bad
  [ :a,
    :b
  ]

  # bad
  [
    :a,
    :b
  ]

  # good
  [
    :a,
    :b ]

  # good
  [ :a,
    :b ]

Freeze mutable objects assigned to constants.
Open

    ALLOWED_PARAMS    = [:header, :filter, :sortable, :data_html,
                         :header_html, :filter_sql, :sort_sql, :sql, :width,
                         :align, :wrap, :format, :filter_label, :name, :classes,
                         :default_filter
                        ]
Severity: Minor
Found in lib/tabulatr/params_builder.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

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

      if value.present?
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Missing top-level class documentation comment.
Open

  class ParamsBuilder
Severity: Minor
Found in lib/tabulatr/params_builder.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

Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
Open

    attr_accessor *ALLOWED_PARAMS
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

Example:

# bad

# The `*` is interpreted as a splat operator but it could possibly be
# a `*` method invocation (i.e. `do_something.*(some_array)`).
do_something *some_array

Example:

# good

# With parentheses, there's no ambiguity.
do_something(*some_array)

Use %i or %I for an array of symbols.
Open

    ALLOWED_PARAMS    = [:header, :filter, :sortable, :data_html,
                         :header_html, :filter_sql, :sort_sql, :sql, :width,
                         :align, :wrap, :format, :filter_label, :name, :classes,
                         :default_filter
                        ]
Severity: Minor
Found in lib/tabulatr/params_builder.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

There are no issues that match your filters.

Category
Status