Sha256: fb7b5dee659e08bc4d9d9be74e3d644720b9ea876eb8c7806280e8a6b7e329ac

Contents?: true

Size: 1.5 KB

Versions: 22

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    # Handles `EnforcedStyle` configuration parameters.
    module ConfigurableEnforcedStyle
      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

      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

      def both_styles_detected
        # Both correct and opposite styles exist.
        self.config_to_allow_offenses = { 'Enabled' => false }
      end

      def unrecognized_style_detected
        # All we can do is to disable.
        self.config_to_allow_offenses = { 'Enabled' => false }
      end

      def style
        s = cop_config[parameter_name]
        if cop_config['SupportedStyles'].include?(s)
          s.to_sym
        else
          fail "Unknown style #{s} selected!"
        end
      end

      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

      def parameter_name
        'EnforcedStyle'
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.34.2 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.34.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.32.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.32.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.31.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.30.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.30.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.29.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.29.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.28.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.27.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.27.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.25.0 lib/rubocop/cop/mixin/configurable_enforced_style.rb
rubocop-0.24.1 lib/rubocop/cop/mixin/configurable_enforced_style.rb