Module: RuboCop::Cop::AutocorrectLogic

Included in:
Cop
Defined in:
lib/rubocop/cop/autocorrect_logic.rb

Overview

This module encapsulates the logic for autocorrect behavior for a cop.

Instance Method Summary collapse

Instance Method Details

#autocorrect?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 7

def autocorrect?
  autocorrect_requested? && support_autocorrect? && autocorrect_enabled?
end

#autocorrect_enabled?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 19

def autocorrect_enabled?
  # allow turning off autocorrect on a cop by cop basis
  return true unless cop_config

  return false if cop_config['AutoCorrect'] == false

  if @options.fetch(:safe_auto_correct, false)
    return cop_config.fetch('SafeAutoCorrect', true)
  end

  true
end

#autocorrect_requested?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 11

def autocorrect_requested?
  @options.fetch(:auto_correct, false)
end

#support_autocorrect?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 15

def support_autocorrect?
  respond_to?(:autocorrect)
end