Class: Rubomop::RandomMop

Inherits:
Literal::Object
  • Object
show all
Defined in:
lib/rubomop/random_mop.rb

Defined Under Namespace

Classes: DeleteOption

Instance Method Summary collapse

Instance Method Details

#accept?(delete_option) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubomop/random_mop.rb', line 16

def accept?(delete_option)
  return false if autocorrect_only && !delete_option.cop.any_autocorrect?
  unless except.empty?
    return except.none? { delete_option.cop.name.include?(_1) }
  end
  unless blocklist.empty?
    return blocklist.none? { delete_option.file.include?(_1) }
  end
  unless only.empty?
    return only.any? { delete_option.cop.name.include?(_1) }
  end
  true
  # return true unless autocorrect_only
  # cop.autocorrect
end

#copsObject



12
13
14
# File 'lib/rubomop/random_mop.rb', line 12

def cops
  todo_file.cops
end

#delete_optionsObject



32
33
34
35
# File 'lib/rubomop/random_mop.rb', line 32

def delete_options
  cops.flat_map { delete_options_for(_1) }
    .select { accept?(_1) }
end

#delete_options_for(cop) ⇒ Object



37
38
39
# File 'lib/rubomop/random_mop.rb', line 37

def delete_options_for(cop)
  cop.files.map { DeleteOption.new(cop, _1, verbose, run_rubocop) }
end

#log(message) ⇒ Object



41
42
43
44
# File 'lib/rubomop/random_mop.rb', line 41

def log(message)
  return unless verbose
  print message
end

#mop!Object



46
47
48
49
50
51
52
53
54
# File 'lib/rubomop/random_mop.rb', line 46

def mop!
  number.times do |i|
    options = delete_options
    next if options.empty?
    log("#{i + 1}:")
    mop_once!(options.sample)
    log("\n")
  end
end

#mop_once!(delete_option) ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/rubomop/random_mop.rb', line 56

def mop_once!(delete_option)
  delete_option.print_message if verbose
  delete_option.delete!
  return unless run_rubocop
  todo_file.save!
  offense_count = delete_option.rubocop_runner || 0
  delete_option.subtract!(offense_count)
end