lib/rubocop/cop/base.rb in rubocop-1.60.2 vs lib/rubocop/cop/base.rb in rubocop-1.61.0

- old
+ new

@@ -303,10 +303,21 @@ # because `processed_source` here may be an embedded code in it. @current_offset = offset @current_original = original end + # @api private + def always_autocorrect? + # `true` is the same as `'always'` for backward compatibility. + ['always', true].include?(cop_config.fetch('AutoCorrect', 'always')) + end + + # @api private + def contextual_autocorrect? + cop_config.fetch('AutoCorrect', 'always') == 'contextual' + end + def inspect # :nodoc: "#<#{self.class.name}:#{object_id} @config=#{@config} @options=#{@options}>" end private @@ -387,11 +398,11 @@ # @return [Symbol] offense status def use_corrector(range, corrector) if autocorrect? attempt_correction(range, corrector) - elsif corrector && cop_config.fetch('AutoCorrect', true) + elsif corrector && (always_autocorrect? || (contextual_autocorrect? && !LSP.enabled?)) :uncorrected else :unsupported end end @@ -478,15 +489,9 @@ ::Parser::Source::Range.new( @current_original.buffer, range.begin_pos + @current_offset, range.end_pos + @current_offset ) - end - - # This experimental feature has been under consideration for a while. - # @api private - def lsp_mode? - ARGV.include?('--lsp') end end end end