Module: Rubocop::Cop::Style::ConfigurableEnforcedStyle

Overview

Handles EnforcedStyle configuration parameters.

Instance Method Summary collapse

Instance Method Details

#alternative_styleObject



40
41
42
43
44
45
46
47
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 40

def alternative_style
  a = cop_config['SupportedStyles'].map(&:to_sym)
  if a.size != 2
    fail 'alternative_style can only be used when there are exactly ' +
      '2 SupportedStyles'
  end
  style == a.first ? a.last : a.first
end

#both_styles_detectedObject



21
22
23
24
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 21

def both_styles_detected
  # Both correct and opposite styles exist.
  self.config_to_allow_offences = { 'Enabled' => false }
end

#correct_style_detectedObject



14
15
16
17
18
19
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 14

def correct_style_detected
  # Enabled:true indicates, later when the opposite style is detected,
  # that the correct style is used somewhere.
  self.config_to_allow_offences ||= { 'Enabled' => true }
  both_styles_detected if config_to_allow_offences['EnforcedStyle']
end

#opposite_style_detectedObject



8
9
10
11
12
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 8

def opposite_style_detected
  self.config_to_allow_offences ||=
    { 'EnforcedStyle' => alternative_style.to_s }
  both_styles_detected if config_to_allow_offences['Enabled']
end

#styleObject



31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 31

def style
  s = cop_config['EnforcedStyle']
  if cop_config['SupportedStyles'].include?(s)
    s.to_sym
  else
    fail "Unknown style #{s} selected!"
  end
end

#unrecognized_style_detectedObject



26
27
28
29
# File 'lib/rubocop/cop/style/configurable_enforced_style.rb', line 26

def unrecognized_style_detected
  # All we can do is to disable.
  self.config_to_allow_offences = { 'Enabled' => false }
end