Class: RubocopAutoCorrector::CopFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop_auto_corrector/cop_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cop_name) ⇒ CopFinder

Returns a new instance of CopFinder.

Parameters:

  • cop_name (String)

    e.g. Metrics/AbcSize



8
9
10
# File 'lib/rubocop_auto_corrector/cop_finder.rb', line 8

def initialize(cop_name)
  @cop_name = cop_name
end

Instance Attribute Details

#cop_nameObject (readonly)

Returns the value of attribute cop_name.



5
6
7
# File 'lib/rubocop_auto_corrector/cop_finder.rb', line 5

def cop_name
  @cop_name
end

Instance Method Details

#auto_correctable?Boolean

Whether this cop is auto correctable

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop_auto_corrector/cop_finder.rb', line 14

def auto_correctable?
  Object.new.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
    # begin
    #   require 'rubocop-rspec'
    # rescue LoadError
    # end
    #
    # return ::RuboCop::Cop::RSpec::AlignLeftLetBrace.support_autocorrect? if ::RuboCop::Cop::RSpec::AlignLeftLetBrace.respond_to?(:support_autocorrect?)
    # ::RuboCop::Cop::RSpec::AlignLeftLetBrace.new.respond_to?(:autocorrect)

    begin
      require '#{gem_name}'
    rescue LoadError
    end

    return #{cop_class_name}.support_autocorrect? if #{cop_class_name}.respond_to?(:support_autocorrect?)
    #{cop_class_name}.new.respond_to?(:autocorrect)
  RUBY
rescue NameError
  false
end

#cop_class_nameString

Returns:

  • (String)


43
44
45
46
# File 'lib/rubocop_auto_corrector/cop_finder.rb', line 43

def cop_class_name
  _, cop_class = rubocop_cop_info
  cop_class
end

#gem_nameString

Returns:

  • (String)


37
38
39
40
# File 'lib/rubocop_auto_corrector/cop_finder.rb', line 37

def gem_name
  gem_name, = rubocop_cop_info
  gem_name
end