Class: RokuBuilder::LineInspector
- Inherits:
-
Object
- Object
- RokuBuilder::LineInspector
- Defined in:
- lib/roku_builder/plugins/line_inspector.rb
Instance Method Summary collapse
-
#initialize(inspector_config:, indent_config:) ⇒ LineInspector
constructor
A new instance of LineInspector.
- #run(file_path) ⇒ Object
Constructor Details
#initialize(inspector_config:, indent_config:) ⇒ LineInspector
Returns a new instance of LineInspector.
6 7 8 9 |
# File 'lib/roku_builder/plugins/line_inspector.rb', line 6 def initialize(inspector_config:, indent_config:) @inspector_config = inspector_config @indent_config = indent_config end |
Instance Method Details
#run(file_path) ⇒ Object
11 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 50 |
# File 'lib/roku_builder/plugins/line_inspector.rb', line 11 def run(file_path) @warnings = [] File.open(file_path) do |file| in_xml_comment = false indent_inspector = IndentationInspector.new(rules: @indent_config, path: file_path) if @indent_config file.readlines.each_with_index do |line, line_number| indent_inspector.check_line(line: line, number: line_number) if indent_inspector 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| line_to_check = line line_to_check = full_line if line_inspector[:include_comments] match = nil if line_inspector[:case_sensitive] match = /#{line_inspector[:regex]}/.match(line_to_check) else match = /#{line_inspector[:regex]}/i.match(line_to_check) 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 end @warnings += indent_inspector.warnings if indent_inspector end @warnings end |