module RuboCop::Cop::ConfigurableEnforcedStyle
def alternative_style
def alternative_style if supported_styles.size != 2 raise 'alternative_style can only be used when there are exactly ' \ '2 SupportedStyles' end (supported_styles - [style]).first end
def ambiguous_style_detected(*possibilities)
def ambiguous_style_detected(*possibilities) style_detected(possibilities) end
def correct_style_detected
def correct_style_detected style_detected(style) end
def detected_style
def detected_style Formatter::DisabledConfigFormatter.detected_styles[cop_name] ||= nil end
def detected_style=(style)
def detected_style=(style) Formatter::DisabledConfigFormatter.detected_styles[cop_name] = style if style.nil? no_acceptable_style! elsif style.is_a?(Array) if style.empty? no_acceptable_style! else config_to_allow_offenses[parameter_name] = style[0] end else config_to_allow_offenses[parameter_name] = style end end
def no_acceptable_style!
def no_acceptable_style! self.config_to_allow_offenses = { 'Enabled' => false } Formatter::DisabledConfigFormatter.detected_styles[cop_name] = [] end
def no_acceptable_style?
def no_acceptable_style? config_to_allow_offenses['Enabled'] == false end
def opposite_style_detected
def opposite_style_detected style_detected(alternative_style) end
def parameter_name
def parameter_name 'EnforcedStyle' end
def style
def style @enforced_style ||= begin s = cop_config[parameter_name].to_sym unless supported_styles.include?(s) raise "Unknown style #{s} selected!" end s end end
def style_detected(detected)
def style_detected(detected) # `detected` can be a single style, or an Array of possible styles # (if there is more than one which matches the observed code) return if no_acceptable_style? if detected.is_a?(Array) detected.map!(&:to_s) else detected = detected.to_s end if !detected_style # we haven't observed any specific style yet self.detected_style = detected elsif detected_style.is_a?(Array) self.detected_style &= [*detected] elsif detected.is_a?(Array) no_acceptable_style! unless detected.include?(detected_style) else no_acceptable_style! unless detected_style == detected end end
def supported_styles
def supported_styles @supported_styles ||= cop_config['SupportedStyles'].map(&:to_sym) end
def unexpected_style_detected(unexpected)
def unexpected_style_detected(unexpected) style_detected(unexpected) end