Class: Rubomop::Mop
- Inherits:
-
Object
- Object
- Rubomop::Mop
- Defined in:
- lib/rubomop/mop.rb
Defined Under Namespace
Classes: DeleteOption
Instance Attribute Summary collapse
-
#autocorrect_only ⇒ Object
Returns the value of attribute autocorrect_only.
-
#block ⇒ Object
Returns the value of attribute block.
-
#except ⇒ Object
Returns the value of attribute except.
-
#number ⇒ Object
Returns the value of attribute number.
-
#only ⇒ Object
Returns the value of attribute only.
-
#run_rubocop ⇒ Object
Returns the value of attribute run_rubocop.
-
#todo_file ⇒ Object
Returns the value of attribute todo_file.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #accept?(delete_option) ⇒ Boolean
- #cops ⇒ Object
- #delete_options ⇒ Object
- #delete_options_for(cop) ⇒ Object
-
#initialize(todo_file, number, autocorrect_only, verbose, run_rubocop, only, except, blocklist) ⇒ Mop
constructor
A new instance of Mop.
- #log(message) ⇒ Object
- #mop! ⇒ Object
- #mop_once!(delete_option) ⇒ Object
Constructor Details
#initialize(todo_file, number, autocorrect_only, verbose, run_rubocop, only, except, blocklist) ⇒ Mop
Returns a new instance of Mop.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rubomop/mop.rb', line 6 def initialize(todo_file, number, autocorrect_only, verbose, run_rubocop, only, except, blocklist) @todo_file = todo_file @number = number @autocorrect_only = autocorrect_only @verbose = verbose @run_rubocop = run_rubocop @only = only @except = except @block = blocklist end |
Instance Attribute Details
#autocorrect_only ⇒ Object
Returns the value of attribute autocorrect_only.
3 4 5 |
# File 'lib/rubomop/mop.rb', line 3 def autocorrect_only @autocorrect_only end |
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'lib/rubomop/mop.rb', line 4 def block @block end |
#except ⇒ Object
Returns the value of attribute except.
4 5 6 |
# File 'lib/rubomop/mop.rb', line 4 def except @except end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/rubomop/mop.rb', line 3 def number @number end |
#only ⇒ Object
Returns the value of attribute only.
4 5 6 |
# File 'lib/rubomop/mop.rb', line 4 def only @only end |
#run_rubocop ⇒ Object
Returns the value of attribute run_rubocop.
3 4 5 |
# File 'lib/rubomop/mop.rb', line 3 def run_rubocop @run_rubocop end |
#todo_file ⇒ Object
Returns the value of attribute todo_file.
3 4 5 |
# File 'lib/rubomop/mop.rb', line 3 def todo_file @todo_file end |
#verbose ⇒ Object
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/rubomop/mop.rb', line 4 def verbose @verbose end |
Instance Method Details
#accept?(delete_option) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubomop/mop.rb', line 21 def accept?(delete_option) return false if autocorrect_only && !delete_option.cop.autocorrect unless except.empty? return except.none? { delete_option.cop.name.include?(_1) } end unless block.empty? return block.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 |
#cops ⇒ Object
17 18 19 |
# File 'lib/rubomop/mop.rb', line 17 def cops todo_file.cops end |
#delete_options ⇒ Object
37 38 39 40 |
# File 'lib/rubomop/mop.rb', line 37 def cops.flat_map { (_1) } .select { accept?(_1) } end |
#delete_options_for(cop) ⇒ Object
42 43 44 |
# File 'lib/rubomop/mop.rb', line 42 def (cop) cop.files.map { DeleteOption.new(cop, _1, verbose, run_rubocop) } end |
#log(message) ⇒ Object
46 47 48 49 |
# File 'lib/rubomop/mop.rb', line 46 def log() return unless verbose print end |
#mop! ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/rubomop/mop.rb', line 51 def mop! number.times do |i| = next if .empty? log("#{i + 1}:") mop_once!(.sample) log("\n") end end |
#mop_once!(delete_option) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/rubomop/mop.rb', line 61 def mop_once!(delete_option) delete_option. if verbose delete_option.delete! return unless run_rubocop todo_file.save! delete_option.rubocop_runner end |