Module: Rubocop::Cop::Style::ConfigurableEnforcedStyle
- Included in:
- AccessModifierIndentation, BracesAroundHashParameters, ConfigurableNaming, For, HashSyntax, LambdaCall, MethodDefParentheses, RaiseArgs, SignalException, SpaceAroundBlockBraces, SpaceInsideHashLiteralBraces, StringLiterals
- Defined in:
- lib/rubocop/cop/style/configurable_enforced_style.rb
Overview
Handles EnforcedStyle configuration parameters.
Instance Method Summary collapse
- #alternative_style ⇒ Object
- #both_styles_detected ⇒ Object
- #correct_style_detected ⇒ Object
- #opposite_style_detected ⇒ Object
- #style ⇒ Object
- #unrecognized_style_detected ⇒ Object
Instance Method Details
#alternative_style ⇒ Object
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_detected ⇒ Object
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_detected ⇒ Object
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_detected ⇒ Object
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 |
#style ⇒ Object
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_detected ⇒ Object
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 |