CLOSER-Cohorts/archivist

View on GitHub

Showing 2,591 of 2,591 total issues

Use Kernel#loop with break rather than begin/end/until(or while).
Open

    end while iterator.to_i != 0
Severity: Minor
Found in app/models/identifier.rb by rubocop

This cop checks for uses of begin...end while/until something.

Example:

# bad

# using while
begin
  do_something
end while some_condition

Example:

# bad

# using until
begin
  do_something
end until some_condition

Example:

# good

# using while
while some_condition
  do_something
end

Example:

# good

# using until
until some_condition
  do_something
end

Useless protected access modifier.
Open

  protected # Protected methods
Severity: Minor
Found in app/controllers/basic_controller.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

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
Open

      study.reject! &:blank?
Severity: Minor
Found in app/models/user_group.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)

Do not suppress exceptions.
Open

    rescue Exception
Severity: Minor
Found in lib/tasks/util.rake by rubocop

This cop checks for rescue blocks with no body.

Example:

# bad

def some_method
  do_something
rescue
  # do nothing
end

Example:

# bad

begin
  do_something
rescue
  # do nothing
end

Example:

# good

def some_method
  do_something
rescue
  handle_exception
end

Example:

# good

begin
  do_something
rescue
  handle_exception
end

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
Open

    to_ary.each &block
Severity: Minor
Found in app/models/children.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)

Useless assignment to variable - top_sequence.
Open

      top_sequence = collection.create!(parent: collection.first, label: @instrument.prefix)

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
Open

      f.write(@doc.to_xml &:no_empty_tags)

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)

Useless assignment to variable - qis.
Open

    qis = i.question_items
Severity: Minor
Found in lib/tasks/time.rake by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
Open

    rds_qs.order(:rd_order).includes(:response_domain).map &:response_domain
Severity: Minor
Found in app/models/question_item.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)

Useless assignment to variable - qis.
Open

    qis = JSON.parse($redis.get('instruments/' + i.id.to_s + '/question_items'))
Severity: Minor
Found in lib/tasks/time.rake by rubocop

This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

assigned but unused variable - foo

Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

Example:

# bad

def some_method
  some_var = 1
  do_something
end

Example:

# good

def some_method
  some_var = 1
  do_something(some_var)
end

(...) interpreted as grouped expression.
Open

    RdsQs.find_by_sql ([sql, self.id])
Severity: Minor
Found in app/models/question_grid.rb by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Method BasicController.params_list is defined at both app/controllers/basic_controller.rb:15 and app/controllers/basic_controller.rb:104.
Open

  def self.params_list
Severity: Minor
Found in app/controllers/basic_controller.rb by rubocop

This cop checks for duplicated instance (or singleton) method definitions.

Example:

# bad

def duplicated
  1
end

def duplicated
  2
end

Example:

# bad

def duplicated
  1
end

alias duplicated other_duplicated

Example:

# good

def duplicated
  1
end

def other_duplicated
  2
end

Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
Open

      f.write(@doc.to_xml &:no_empty_tags)
Severity: Minor
Found in lib/exporters/xml/ddi/instrument.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)

(...) interpreted as grouped expression.
Open

      map = self.maps.build ({
Severity: Minor
Found in app/models/variable.rb by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
Open

  if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
Severity: Minor
Found in bin/spring by rubocop

This cop checks for assignments in the conditions of if/while/until.

Example:

# bad

if some_var = true
  do_something
end

Example:

# good

if some_var == true
  do_something
end

(...) interpreted as grouped expression.
Open

  json.errors (@circular_cc_questions && @circular_cc_questions.include?(cc_question.id) && cc_question.valid?) ? nil : cc_question.errors.full_messages.to_sentence

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)

Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
Open

            return

This cop checks for non-local exits from iterators without a return value. It registers an offense under these conditions:

  • No value is returned,
  • the block is preceded by a method chain,
  • the block has arguments,
  • the method which receives the block is not define_method or define_singleton_method,
  • the return is not contained in an inner scope, e.g. a lambda or a method definition.

Example:

class ItemApi
  rescue_from ValidationError do |e| # non-iteration block with arg
    return { message: 'validation error' } unless e.errors # allowed
    error_array = e.errors.map do |error| # block with method chain
      return if error.suppress? # warned
      return "#{error.param}: invalid" unless error.message # allowed
      "#{error.param}: #{error.message}"
    end
    { message: 'validation error', errors: error_array }
  end

  def update_items
    transaction do # block without arguments
      return unless update_necessary? # allowed
      find_each do |item| # block without method chain
        return if item.stock == 0 # false-negative...
        item.update!(foobar: true)
      end
    end
  end
end

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

  def import(options = {})
Severity: Minor
Found in lib/importers/txt/mapper/mapping.rb by rubocop

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

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

  def import(options = {})
Severity: Minor
Found in lib/importers/txt/mapper/dv.rb by rubocop

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

(...) interpreted as grouped expression.
Open

          co = ::Code.new ({
Severity: Minor
Found in lib/importers/xml/ddi/code_list.rb by rubocop

Checks for space between the name of a called method and a left parenthesis.

Example:

# bad

puts (x + y)

Example:

# good

puts(x + y)
Severity
Category
Status
Source
Language