Class: Rubomop::TodoFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:) ⇒ TodoFile

Returns a new instance of TodoFile.



6
7
8
# File 'lib/rubomop/todo_file.rb', line 6

def initialize(filename:)
  @filename = filename
end

Instance Attribute Details

#copsObject

Returns the value of attribute cops.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def cops
  @cops
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/rubomop/todo_file.rb', line 3

def filename
  @filename
end

#headerObject

Returns the value of attribute header.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def header
  @header
end

#raw_linesObject

Returns the value of attribute raw_lines.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def raw_lines
  @raw_lines
end

Instance Method Details

#delete!(delete_option) ⇒ Object



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

def delete!(delete_option)
  delete_option[:cop].delete!(delete_option[:file])
end

#delete_options(autocorrect_only: true) ⇒ Object



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

def delete_options(autocorrect_only: true)
  result = cops.flat_map(&:delete_options)
  result = result.select { _1[:cop].autocorrect } if autocorrect_only
  result
end

#outputObject



27
28
29
# File 'lib/rubomop/todo_file.rb', line 27

def output
  output_lines.join("\n") + "\n"
end

#output_linesObject



17
18
19
20
21
22
23
24
25
# File 'lib/rubomop/todo_file.rb', line 17

def output_lines
  result = header.map(&:chomp)
  result << ""
  cops.each do |cop|
    result += cop.output_lines
    result << ""
  end
  result[0..-2]
end

#parseObject



10
11
12
13
14
15
# File 'lib/rubomop/todo_file.rb', line 10

def parse
  self.raw_lines = File.readlines(filename)
  self.header, *raw_tasks = raw_lines.split("\n")
  self.cops = raw_tasks.map { Cop.create_and_parse(_1) }
  self
end