Skip to content

Commit

Permalink
Add line numbers to warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Sep 20, 2018
1 parent f77cbd0 commit fb857c3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/roku_builder/plugins/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@ def initialize(config:, dir:)
def run(inspector_config)
@warnings = []
@attributes = {}
@line_numbers = {}
@inspector_config = inspector_config
File.open(File.join(@config.root_dir, "manifest")) do |file|
current_line = 0
file.readlines.each do |line|
current_line += 1
parts = line.split("=")
key = parts.shift.to_sym
if @attributes[key]
add_warning(warning: :manifestDuplicateAttribute, key: key)
add_warning(warning: :manifestDuplicateAttribute, key: key, line: current_line)
else
value = parts.join("=").chomp
if !value or value == ""
add_warning(warning: :manifestEmptyValue, key: key)
add_warning(warning: :manifestEmptyValue, key: key, line: current_line)
else
@attributes[key] = value
@line_numbers[key] = current_line
end
end
end
Expand Down Expand Up @@ -151,8 +155,14 @@ def manifest_attributes
file = File.join(File.dirname(__FILE__), "manifest_attributes.json")
JSON.parse(File.open(file).read, {symbolize_names: true})
end
def add_warning(warning:, key:, mapping: nil)
def add_warning(warning:, key:, mapping: nil, line: nil)
@warnings.push(@inspector_config[warning].deep_dup)
@warnings.last[:path] = "manifest"
if line
@warnings.last[:line] = line
elsif @line_numbers[key]
@warnings.last[:line] = @line_numbers[key]
end
if mapping
mapping.each_pair do |map, value|
@warnings.last[:message].gsub!(map.to_s, value.to_s)
Expand Down
26 changes: 26 additions & 0 deletions test/roku_builder/plugins/test_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,70 +41,94 @@ def test_manifest_duplicate_attribute
warnings = test_manifest("manifest_duplicate_attribute")
assert_equal 1, warnings.count
assert_match(/title/, warnings[0][:message])
assert_equal 2, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_depricated_attribute
warnings = test_manifest("manifest_depricated_attribute")
assert_equal 1, warnings.count
assert_match(/subtitle/, warnings[0][:message])
assert_equal 2, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_empty_value
warnings = test_manifest("manifest_empty_value")
assert_equal 1, warnings.count
assert_match(/empty/, warnings[0][:message])
assert_equal 9, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_integer
warnings = test_manifest("manifest_invalid_value_integer")
assert_equal 1, warnings.count
assert_match(/major_version/, warnings[0][:message])
assert_match(/bad/, warnings[0][:message])
assert_equal 2, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_float
warnings = test_manifest("manifest_invalid_value_float")
assert_equal 1, warnings.count
assert_match(/rsg_version/, warnings[0][:message])
assert_match(/1/, warnings[0][:message])
assert_equal 9, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_negative
warnings = test_manifest("manifest_invalid_value_negative")
assert_equal 1, warnings.count
assert_match(/major_version/, warnings[0][:message])
assert_match(/-1/, warnings[0][:message])
assert_equal 2, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_not_equal
warnings = test_manifest("manifest_invalid_value_not_equal")
assert_equal 1, warnings.count
assert_match(/build_version/, warnings[0][:message])
assert_match(/0/, warnings[0][:message])
assert_equal 4, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_equals
warnings = test_manifest("manifest_invalid_value_equals")
assert_equal 1, warnings.count
assert_match(/screensaver_private/, warnings[0][:message])
assert_match(/2/, warnings[0][:message])
assert_equal 9, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_invalid_value_starts_with
warnings = test_manifest("manifest_invalid_value_starts_with")
refute_equal 0, warnings.count
assert_match(/mm_icon_focus_hd/, warnings[0][:message])
assert_match(/bad/, warnings[0][:message])
assert_match(/invalid value/, warnings[0][:message])
assert_equal 5, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_has_value
warnings = test_manifest("manifest_has_value")
assert_equal 1, warnings.count
assert_match(/rsg_version/, warnings[0][:message])
assert_match(/1.0/, warnings[0][:message])
assert_equal 9, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_missing_file
warnings = test_manifest("manifest_missing_file")
assert_equal 1, warnings.count
assert_match(/mm_icon_focus_hd/, warnings[0][:message])
assert_match(/missing.png/, warnings[0][:message])
assert_equal 5, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end
def test_manifest_missing_attribute
warnings = test_manifest("manifest_missing_attribute")
assert_equal 1, warnings.count
assert_match(/title/, warnings[0][:message])
assert_equal "manifest", warnings[0][:path]
refute warnings[0][:line]
end
def test_manifest_incorrect_image_resolution
warnings = test_manifest("manifest_incorrect_image_resolution")
Expand All @@ -113,6 +137,8 @@ def test_manifest_incorrect_image_resolution
assert_match(/too_small.png/, warnings[0][:message])
assert_match(/336x210/, warnings[0][:message])
assert_match(/1x1/, warnings[0][:message])
assert_equal 5, warnings[0][:line]
assert_equal "manifest", warnings[0][:path]
end


Expand Down

0 comments on commit fb857c3

Please sign in to comment.