Module: RuboCop::Cop::ConfigurableEnforcedStyle
- Included in:
- ConfigurableNaming, EndKeywordAlignment, Rails::ActionFilter, Style::AccessModifierIndentation, Style::AndOr, Style::BarePercentLiterals, Style::BracesAroundHashParameters, Style::CaseIndentation, Style::ClassAndModuleChildren, Style::ClassCheck, Style::DotPosition, Style::EmptyLinesAroundBody, Style::Encoding, Style::For, Style::FormatString, Style::GuardClause, Style::HashSyntax, Style::IndentHash, Style::LambdaCall, Style::MethodDefParentheses, Style::MultilineOperationIndentation, Style::Next, Style::PercentQLiterals, Style::RaiseArgs, Style::SignalException, Style::SpaceAroundEqualsInParameterDefault, Style::SpaceBeforeBlockBraces, Style::SpaceInsideBlockBraces, Style::SpaceInsideHashLiteralBraces, Style::StringLiterals, Style::StringLiteralsInInterpolation, Style::TrailingBlankLines, Style::TrailingComma
- Defined in:
- lib/rubocop/cop/mixin/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
- #parameter_name ⇒ Object
- #style ⇒ Object
- #unrecognized_style_detected ⇒ Object
Instance Method Details
#alternative_style ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 39 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
20 21 22 23 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 20 def both_styles_detected # Both correct and opposite styles exist. self.config_to_allow_offenses = { 'Enabled' => false } end |
#correct_style_detected ⇒ Object
13 14 15 16 17 18 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 13 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_offenses ||= { 'Enabled' => true } both_styles_detected if config_to_allow_offenses[parameter_name] end |
#opposite_style_detected ⇒ Object
7 8 9 10 11 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 7 def opposite_style_detected self.config_to_allow_offenses ||= { parameter_name => alternative_style.to_s } both_styles_detected if config_to_allow_offenses['Enabled'] end |
#parameter_name ⇒ Object
48 49 50 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 48 def parameter_name 'EnforcedStyle' end |
#style ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 30 def style s = cop_config[parameter_name] if cop_config['SupportedStyles'].include?(s) s.to_sym else fail "Unknown style #{s} selected!" end end |
#unrecognized_style_detected ⇒ Object
25 26 27 28 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 25 def unrecognized_style_detected # All we can do is to disable. self.config_to_allow_offenses = { 'Enabled' => false } end |