decko-commons/decko

View on GitHub
card/lib/card/lexicon.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

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

        lex.map { |side_id| name side_id or return }.join(Card::Name.joint).to_name
Severity: Minor
Found in card/lib/card/lexicon.rb by rubocop

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

Use || instead of or.
Open

        lex.map { |side_id| name side_id or return }.join(Card::Name.joint).to_name
Severity: Minor
Found in card/lib/card/lexicon.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

There are no issues that match your filters.

Category
Status