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)

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

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

#autocorrect_enabled?Boolean

Returns:

  • (Boolean)

20
21
22
23
24
# File 'lib/rubocop/cop/autocorrect_logic.rb', line 20

def autocorrect_enabled?
  # allow turning off autocorrect on a cop by cop basis
  return true unless cop_config
  cop_config['AutoCorrect'] != false
end

#autocorrect_requested?Boolean

Returns:

  • (Boolean)

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

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

#support_autocorrect?Boolean

Returns:

  • (Boolean)

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

def support_autocorrect?
  respond_to?(:autocorrect, true)
end