Module: RuboCop::Cop::ConfigurableEnforcedStyle
- Included in:
- Bundler::OrderedGems, ConfigurableFormatting, EndKeywordAlignment, Gemspec::OrderedDependencies, Layout::AccessModifierIndentation, Layout::BlockAlignment, Layout::CaseIndentation, Layout::DotPosition, Layout::EmptyLinesAroundBody, Layout::EndOfLine, Layout::FirstParameterIndentation, Layout::IndentArray, Layout::IndentHash, Layout::IndentHeredoc, Layout::IndentationConsistency, Layout::MultilineAssignmentLayout, Layout::MultilineMethodCallIndentation, Layout::MultilineOperationIndentation, Layout::SpaceAroundBlockParameters, Layout::SpaceAroundEqualsInParameterDefault, Layout::SpaceBeforeBlockBraces, Layout::SpaceInLambdaLiteral, Layout::SpaceInsideArrayLiteralBrackets, Layout::SpaceInsideBlockBraces, Layout::SpaceInsideHashLiteralBraces, Layout::SpaceInsideParens, Layout::SpaceInsideReferenceBrackets, Layout::SpaceInsideStringInterpolation, Layout::TrailingBlankLines, Lint::InheritException, MultilineLiteralBraceLayout, Naming::HeredocDelimiterCase, Naming::MemoizedInstanceVariableName, Rails::ActionFilter, Rails::Date, Rails::Exit, Rails::FilePath, Rails::HttpStatus, Rails::RequestReferer, Rails::TimeZone, Rails::UniqBeforePluck, Style::AccessModifierDeclarations, Style::Alias, Style::AndOr, Style::BarePercentLiterals, Style::BlockDelimiters, Style::BracesAroundHashParameters, Style::ClassAndModuleChildren, Style::ClassCheck, Style::CommandLiteral, Style::ConditionalAssignment, Style::EmptyElse, Style::EmptyMethod, Style::For, Style::FormatString, Style::FormatStringToken, Style::FrozenStringLiteralComment, Style::HashSyntax, Style::Lambda, Style::LambdaCall, Style::MethodDefParentheses, Style::MissingElse, Style::MixinGrouping, Style::ModuleFunction, Style::MultilineMemoization, Style::NegatedIf, Style::Next, Style::NumericPredicate, Style::PercentQLiterals, Style::PreferredHashMethods, Style::RaiseArgs, Style::RegexpLiteral, Style::RescueStandardError, Style::ReturnNil, Style::SignalException, Style::SpecialGlobalVars, Style::StabbyLambdaParentheses, Style::StringLiterals, Style::StringLiteralsInInterpolation, Style::SymbolArray, Style::TernaryParentheses, Style::WordArray, Style::YodaCondition, TrailingComma
- Defined in:
- lib/rubocop/cop/mixin/configurable_enforced_style.rb
Overview
Handles ‘EnforcedStyle` configuration parameters.
Instance Method Summary collapse
- #alternative_style ⇒ Object
- #alternative_styles ⇒ Object
- #ambiguous_style_detected(*possibilities) ⇒ Object
- #correct_style_detected ⇒ Object
- #detected_style ⇒ Object
- #detected_style=(style) ⇒ Object
- #no_acceptable_style! ⇒ Object (also: #conflicting_styles_detected, #unrecognized_style_detected)
- #no_acceptable_style? ⇒ Boolean
- #opposite_style_detected ⇒ Object
- #style ⇒ Object
- #style_detected(detected) ⇒ Object
- #style_parameter_name ⇒ Object
- #supported_styles ⇒ Object
- #unexpected_style_detected(unexpected) ⇒ Object
Instance Method Details
#alternative_style ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 73 def alternative_style if supported_styles.size != 2 raise 'alternative_style can only be used when there are exactly ' \ '2 SupportedStyles' end alternative_styles.first end |
#alternative_styles ⇒ Object
81 82 83 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 81 def alternative_styles (supported_styles - [style]) end |
#ambiguous_style_detected(*possibilities) ⇒ Object
19 20 21 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 19 def ambiguous_style_detected(*possibilities) style_detected(possibilities) end |
#correct_style_detected ⇒ Object
11 12 13 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 11 def correct_style_detected style_detected(style) end |
#detected_style ⇒ Object
52 53 54 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 52 def detected_style Formatter::DisabledConfigFormatter.detected_styles[cop_name] ||= nil end |
#detected_style=(style) ⇒ Object
56 57 58 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 56 def detected_style=(style) Formatter::DisabledConfigFormatter.detected_styles[cop_name] = style end |
#no_acceptable_style! ⇒ Object Also known as: conflicting_styles_detected, unrecognized_style_detected
48 49 50 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 48 def no_acceptable_style! self.config_to_allow_offenses = { 'Enabled' => false } end |
#no_acceptable_style? ⇒ Boolean
44 45 46 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 44 def no_acceptable_style? config_to_allow_offenses['Enabled'] == false end |
#opposite_style_detected ⇒ Object
7 8 9 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 7 def opposite_style_detected style_detected(alternative_style) end |
#style ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 63 def style @style ||= begin s = cop_config[style_parameter_name].to_sym unless supported_styles.include?(s) raise "Unknown style #{s} selected!" end s end end |
#style_detected(detected) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 23 def style_detected(detected) return if no_acceptable_style? # `detected` can be a single style, or an Array of possible styles # (if there is more than one which matches the observed code) detected_as_strings = Array(detected).map(&:to_s) updated_list = if detected_style detected_style & detected_as_strings else # We haven't observed any specific style yet. detected_as_strings end if updated_list.empty? no_acceptable_style! else self.detected_style = updated_list config_to_allow_offenses[style_parameter_name] = updated_list.first end end |
#style_parameter_name ⇒ Object
92 93 94 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 92 def style_parameter_name 'EnforcedStyle' end |
#supported_styles ⇒ Object
85 86 87 88 89 90 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 85 def supported_styles @supported_styles ||= begin supported_styles = Util.to_supported_styles(style_parameter_name) cop_config[supported_styles].map(&:to_sym) end end |
#unexpected_style_detected(unexpected) ⇒ Object
15 16 17 |
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 15 def unexpected_style_detected(unexpected) style_detected(unexpected) end |