Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::IndentationWidth

This cops checks for indentation that doesn't use two spaces.

@example

class A

def test
 puts 'hello'
end

end

Public Instance Methods

check(node, _method_name, _args, body) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 56
def check(node, _method_name, _args, body)
  check_indentation(node.loc.keyword, body) unless ignored_node?(node)
end
on_block(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 26
def on_block(node)
  _method, _args, body = *node
  # Check body against end/} indentation. Checking against variable
  # assignments, etc, would be more difficult. The end/} must be at the
  # beginning of its line.
  loc = node.loc
  check_indentation(loc.end, body) if begins_its_line?(loc.end)
end
on_case(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 75
def on_case(node)
  _condition, *branches = *node
  latest_when = nil
  branches.compact.each do |b|
    if b.type == :when
      _condition, body = *b
      # Check "when" body against "when" keyword indentation.
      check_indentation(b.loc.keyword, body)
      latest_when = b
    else
      # Since it's not easy to get the position of the "else" keyword,
      # we check "else" body against latest "when" keyword indentation.
      check_indentation(latest_when.loc.keyword, b)
    end
  end
end
on_class(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 40
def on_class(node)
  _class_name, _base_class, *members = *node
  members.each { |m| check_indentation(node.loc.keyword, m) }
end
on_for(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 60
def on_for(node)
  _variable, _collection, body = *node
  check_indentation(node.loc.keyword, body)
end
on_if(node, base = node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 92
def on_if(node, base = node)
  return if ignored_node?(node)
  return if ternary_op?(node)
  return if modifier_if?(node)

  case node.loc.keyword.source
  when 'if'     then _condition, body, else_clause = *node
  when 'unless' then _condition, else_clause, body = *node
  else               _condition, body = *node
  end

  check_if(node, body, else_clause, base.loc) if body
end
on_kwbegin(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 22
def on_kwbegin(node)
  check_indentation(node.loc.end, node.children.first)
end
on_module(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 35
def on_module(node)
  _module_name, *members = *node
  members.each { |m| check_indentation(node.loc.keyword, m) }
end
on_send(node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 45
def on_send(node)
  super
  receiver, method_name, *args = *node
  return unless visibility_and_def_on_same_line?(receiver, method_name,
                                                 args)

  _method_name, _args, body = *args.first
  check_indentation(node.loc.expression, body)
  ignore_node(args.first)
end
on_until(node, base = node) click to toggle source
Alias for: on_while
on_while(node, base = node) click to toggle source
# File lib/rubocop/cop/style/indentation_width.rb, line 65
def on_while(node, base = node)
  _condition, body = *node
  return unless node.loc.keyword.begin_pos ==
    node.loc.expression.begin_pos

  check_indentation(base.loc, body)
end
Also aliased as: on_until

[Validate]

Generated with the Darkfish Rdoc Generator 2.