class RuboCop::Cop::Layout::AccessModifierIndentation

Bare access modifiers (those not applying to specific methods) should be indented as deep as method definitions, or as deep as the class/module keyword, depending on configuration.

@example EnforcedStyle: indent (default)

# bad
class Plumbus
private
  def smooth; end
end

# good
class Plumbus
  private
  def smooth; end
end

@example EnforcedStyle: outdent

# bad
class Plumbus
  private
  def smooth; end
end

# good
class Plumbus
private
  def smooth; end
end

Constants

MSG

Public Instance Methods

on_block(node)
Alias for: on_class
on_class(node) click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 43
def on_class(node)
  return unless node.body&.begin_type?

  check_body(node.body, node)
end
Also aliased as: on_sclass, on_module, on_block
on_module(node)
Alias for: on_class
on_sclass(node)
Alias for: on_class

Private Instance Methods

autocorrect(corrector, node) click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 54
def autocorrect(corrector, node)
  AlignmentCorrector.correct(corrector, processed_source, node, @column_delta)
end
check_body(body, node) click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 58
def check_body(body, node)
  modifiers = body.each_child_node(:send).select(&:bare_access_modifier?)
  end_range = node.loc.end

  modifiers.each { |modifier| check_modifier(modifier, end_range) }
end
check_modifier(send_node, end_range) click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 65
def check_modifier(send_node, end_range)
  offset = column_offset_between(send_node.source_range, end_range)

  @column_delta = expected_indent_offset - offset
  if @column_delta.zero?
    correct_style_detected
  else
    add_offense(send_node) do |corrector|
      if offset == unexpected_indent_offset
        opposite_style_detected
      else
        unrecognized_style_detected
      end

      autocorrect(corrector, send_node)
    end
  end
end
expected_indent_offset() click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 88
def expected_indent_offset
  style == :outdent ? 0 : configured_indentation_width
end
message(range) click to toggle source
# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 84
def message(range)
  format(MSG, style: style.capitalize, node: range.source)
end
unexpected_indent_offset() click to toggle source

An offset that is not expected, but correct if the configuration is changed.

# File lib/rubocop/cop/layout/access_modifier_indentation.rb, line 94
def unexpected_indent_offset
  configured_indentation_width - expected_indent_offset
end