Class: RokuBuilder::LineInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/roku_builder/plugins/line_inspector.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:, raf:, inspector_config:) ⇒ LineInspector

Returns a new instance of LineInspector.



6
7
8
9
10
# File 'lib/roku_builder/plugins/line_inspector.rb', line 6

def initialize(config:, raf:, inspector_config:)
  @config = config
  @raf_inspector = raf
  @inspector_config = inspector_config
end

Instance Method Details

#run(file_path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/roku_builder/plugins/line_inspector.rb', line 12

def run(file_path)
  @warnings = []
  File.open(file_path) do |file|
    line_number = 0
    in_xml_comment = false
    file.readlines.each do |line|
      full_line = line.dup
      line = line.partition("'").first if file_path.end_with?(".brs")
      if file_path.end_with?(".xml")
        if in_xml_comment
          if line.gsub!(/.*-->/, "")
            in_xml_comment = false
          else
            line = ""
          end
        end
        line.gsub!(/<!--.*-->/, "")
        in_xml_comment = true if line.gsub!(/<!--.*/, "")
      end
      @inspector_config.each do |line_inspector|
        match  = nil
        if line_inspector[:case_sensitive]
          match = /#{line_inspector[:regex]}/.match(line)
        else
          match = /#{line_inspector[:regex]}/i.match(line)
        end
        if match
          unless /'.*ignore-warning/i.match(full_line)
            add_warning(inspector: line_inspector, file: file_path, line: line_number, match: match)
          end
        end
      end
      @raf_inspector.inspect_line(line: line, file: file_path, line_number: line_number)
      line_number += 1
    end
  end
  @warnings
end