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 51 52 53 54 55 56 57 58 59 60 61 |
# 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 full_file = [] file_no_comments = [] lines_to_ignore = [] file.readlines.each_with_index do |line, line_number| full_line = line.dup line.gsub!(/'.*/, "") 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 = "\n" end end line.gsub!(/<!--.*-->/, "") in_xml_comment = true if line.gsub!(/<!--.*/, "") end indent_inspector.check_line(line: full_line, number: line_number, comment: in_xml_comment) if indent_inspector if /'.*ignore-warning/i.match(full_line) lines_to_ignore.push line_number end full_file.push(full_line) file_no_comments.push(line) end @warnings += indent_inspector.warnings if indent_inspector no_comments = file_no_comments.join("") file = full_file.join("") @inspector_config.each do |line_inspector| to_check = no_comments to_check = file if line_inspector[:include_comments] match = nil if line_inspector[:case_sensitive] match = /#{line_inspector[:regex]}/.match(to_check) else match = /#{line_inspector[:regex]}/i.match(to_check) end if match line_number = to_check[0..match.begin(0)].split("\n", -1).count - 1 unless lines_to_ignore.include?(line_number) add_warning(inspector: line_inspector, file: file_path, line: line_number, match: match) end end end end @warnings end |