123456789_123456789_123456789_123456789_123456789_

Module: RuboCop::Cop::ConfigurableEnforcedStyle

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Bundler::GemFilename, Bundler::GemVersion, ConfigurableFormatting, ConfigurableNaming, ConfigurableNumbering, EndKeywordAlignment, Gemspec::DependencyVersion, Gemspec::DevelopmentDependencies, Layout::AccessModifierIndentation, Layout::BeginEndAlignment, Layout::BlockAlignment, Layout::CaseIndentation, Layout::DefEndAlignment, Layout::DotPosition, Layout::ElseAlignment, Layout::EmptyLinesAroundAccessModifier, Layout::EmptyLinesAroundBeginBody, Layout::EmptyLinesAroundBlockBody, Layout::EmptyLinesAroundBody, Layout::EmptyLinesAroundClassBody, Layout::EmptyLinesAroundExceptionHandlingKeywords, Layout::EmptyLinesAroundMethodBody, Layout::EmptyLinesAroundModuleBody, Layout::EndAlignment, Layout::EndOfLine, Layout::FirstArgumentIndentation, Layout::FirstArrayElementIndentation, Layout::FirstHashElementIndentation, Layout::FirstParameterIndentation, Layout::IndentationConsistency, Layout::IndentationStyle, Layout::IndentationWidth, Layout::LineEndStringConcatenationIndentation, Layout::MultilineArrayBraceLayout, Layout::MultilineAssignmentLayout, Layout::MultilineHashBraceLayout, Layout::MultilineMethodCallBraceLayout, Layout::MultilineMethodCallIndentation, Layout::MultilineMethodDefinitionBraceLayout, Layout::MultilineOperationIndentation, Layout::RescueEnsureAlignment, Layout::SpaceAroundBlockParameters, Layout::SpaceAroundEqualsInParameterDefault, Layout::SpaceBeforeBlockBraces, Layout::SpaceInLambdaLiteral, Layout::SpaceInsideArrayLiteralBrackets, Layout::SpaceInsideBlockBraces, Layout::SpaceInsideHashLiteralBraces, Layout::SpaceInsideParens, Layout::SpaceInsideReferenceBrackets, Layout::SpaceInsideStringInterpolation, Layout::TrailingEmptyLines, Lint::InheritException, Lint::SymbolConversion, MultilineLiteralBraceCorrector, MultilineLiteralBraceLayout, Naming::BlockForwarding, Naming::HeredocDelimiterCase, Naming::MemoizedInstanceVariableName, Naming::MethodName, Naming::VariableName, Naming::VariableNumber, Style::AccessModifierDeclarations, Style::AccessorGrouping, Style::Alias, Style::AndOr, Style::BarePercentLiterals, Style::BlockDelimiters, Style::ClassAndModuleChildren, Style::ClassCheck, Style::ClassMethodsDefinitions, Style::CommandLiteral, Style::ConditionalAssignment, Style::DoubleNegation, Style::EmptyElse, Style::EmptyMethod, Style::EndlessMethod, Style::ExponentialNotation, Style::FloatDivision, Style::For, Style::FormatString, Style::FormatStringToken, Style::FrozenStringLiteralComment, Style::HashAsLastArrayItem, Style::HashSyntax, Style::Lambda, Style::LambdaCall, Style::MagicCommentFormat, Style::MethodCallWithArgsParentheses, Style::MethodDefParentheses, Style::MissingElse, Style::MixinGrouping, Style::ModuleFunction, Style::MultilineMemoization, Style::MutableConstant, Style::NegatedIf, Style::NegatedUnless, Style::Next, Style::NilComparison, Style::NumberedParameters, Style::NumericPredicate, Style::ObjectThen, Style::OneLineConditional, Style::PercentQLiterals, Style::PreferredHashMethods, Style::QuotedSymbols, Style::RaiseArgs, Style::RegexpLiteral, Style::RescueStandardError, Style::ReturnNil, Style::SignalException, Style::SpecialGlobalVars, Style::StabbyLambdaParentheses, Style::StringLiterals, Style::StringLiteralsInInterpolation, Style::SymbolArray, Style::TernaryParentheses, Style::TrailingCommaInArguments, Style::TrailingCommaInArrayLiteral, Style::TrailingCommaInHashLiteral, Style::UnlessLogicalOperators, Style::WordArray, Style::YodaCondition, TrailingComma
Defined in: lib/rubocop/cop/mixin/configurable_enforced_style.rb

Overview

Handles EnforcedStyle configuration parameters.

Constant Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#detected_style (rw)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 64

def detected_style
  Formatter::DisabledConfigFormatter.detected_styles[cop_name] ||= nil
end

#detected_style=(style) (rw)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 68

def detected_style=(style)
  Formatter::DisabledConfigFormatter.detected_styles[cop_name] = style
end

#no_acceptable_style?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 56

def no_acceptable_style?
  config_to_allow_offenses['Enabled'] == false
end

#style_configured?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 75

def style_configured?
  cop_config.key?(style_parameter_name)
end

Instance Method Details

#alternative_style

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 88

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

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 96

def alternative_styles
  (supported_styles - [style])
end

#ambiguous_style_detected(*possibilities)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 19

def ambiguous_style_detected(*possibilities)
  style_detected(possibilities)
end

#conflicting_styles_detected

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 72

alias conflicting_styles_detected no_acceptable_style!

#correct_style_detected

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 11

def correct_style_detected
  style_detected(style)
end

#no_acceptable_style! Also known as: #conflicting_styles_detected, #unrecognized_style_detected

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 60

def no_acceptable_style!
  self.config_to_allow_offenses = { 'Enabled' => false }
end

#opposite_style_detected

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 7

def opposite_style_detected
  style_detected(alternative_style)
end

#style

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 79

def style
  @style ||= begin
    s = cop_config[style_parameter_name].to_sym
    raise "Unknown style #{s} selected!" unless supported_styles.include?(s)

    s
  end
end

#style_detected(detected)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 29

def style_detected(detected)
  return if no_acceptable_style?

  # This logic is more complex than it needs to be
  # to avoid allocating Arrays in the hot code path.
  updated_list =
    if detected_style
      if detected_style.size == 1 && detected_style.include?(SYMBOL_TO_STRING_CACHE[detected])
        detected_style
      else
        detected_as_strings = SYMBOL_TO_STRING_CACHE.values_at(*detected)
        detected_style & detected_as_strings
      end
    else
      # We haven't observed any specific style yet.
      SYMBOL_TO_STRING_CACHE.values_at(*detected)
    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

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 107

def style_parameter_name
  'EnforcedStyle'
end

#supported_styles

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 100

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)

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 15

def unexpected_style_detected(unexpected)
  style_detected(unexpected)
end

#unrecognized_style_detected

[ GitHub ]

  
# File 'lib/rubocop/cop/mixin/configurable_enforced_style.rb', line 73

alias unrecognized_style_detected no_acceptable_style!