Module: Rubocop::SafeTodoSearcher

Defined in:
lib/rubocop/safe_todo_searcher.rb,
lib/rubocop/safe_todo_searcher/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.parseObject



16
17
18
19
20
21
22
# File 'lib/rubocop/safe_todo_searcher.rb', line 16

def self.parse
  res = +""
  File.open(".rubocop_todo.yml", "r") { |f| YAML.safe_load(f) }.each_key do |key|
    res << "#{key}\n" if support_autocorrect?(key)
  end
  res
end

.searchObject



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

def self.search
  File.exist?(".rubocop_todo.yml") ? parse : "rubocop_todo.yml does not exist"
end

.support_autocorrect?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/rubocop/safe_todo_searcher.rb', line 24

def self.support_autocorrect?(key)
  cop = Object.const_get "RuboCop::Cop::#{key.gsub(%r{/}, "::")}"
  cop.support_autocorrect? && cop.new(RuboCop::ConfigLoader.default_configuration).safe_autocorrect?
rescue NameError
  false
end