Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4968a34

Browse files
author
Will Fleming
committed
compact impl
1 parent 32cfe66 commit 4968a34

File tree

2 files changed

+6
-34
lines changed

2 files changed

+6
-34
lines changed

lib/cc/engine/csslint.rb

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
require "json"
22
require "nokogiri"
3+
require "ostruct"
34
require "shellwords"
45

56
module CC
67
module Engine
78
MissingAttributesError = Class.new(StandardError)
89

10+
DEFAULT_IDENTIFIER = OpenStruct.new(value: "parse-error")
11+
912
class CSSlint
1013
autoload :CheckDetails, "cc/engine/csslint/check_details"
1114

@@ -21,12 +24,7 @@ def run
2124
path = file['name'].sub(/\A#{@directory}\//, '')
2225
file.children.each do |node|
2326
next unless node.name == "error"
24-
issue =
25-
if node.attributes.key?("identifier")
26-
create_issue(node, path)
27-
else
28-
create_error(node, path)
29-
end
27+
issue = create_issue(node, path)
3028
puts("#{issue.to_json}\0")
3129
end
3230
end
@@ -37,7 +35,7 @@ def run
3735

3836
# rubocop:disable Metrics/MethodLength
3937
def create_issue(node, path)
40-
check_name = node.attributes.fetch("identifier").value
38+
check_name = node.attributes.fetch("identifier", DEFAULT_IDENTIFIER).value
4139
check_details = CheckDetails.fetch(check_name)
4240

4341
{
@@ -65,33 +63,6 @@ def create_issue(node, path)
6563
end
6664
# rubocop:enable Metrics/MethodLength
6765

68-
# rubocop:disable Metrics/MethodLength
69-
def create_error(node, path)
70-
{
71-
type: "issue",
72-
check_name: "parse-error",
73-
description: node.attributes.fetch("message").value,
74-
categories: ["Bug Risk"],
75-
remediation_points: 5_000,
76-
location: {
77-
path: path,
78-
positions: {
79-
begin: {
80-
line: node.attributes.fetch("line").value.to_i,
81-
column: node.attributes.fetch("column").value.to_i
82-
},
83-
end: {
84-
line: node.attributes.fetch("line").value.to_i,
85-
column: node.attributes.fetch("column").value.to_i
86-
}
87-
}
88-
}
89-
}
90-
rescue KeyError => ex
91-
raise MissingAttributesError, "#{ex.message} on XML error '#{node}' when analyzing file '#{path}'"
92-
end
93-
# rubocop:enable Metrics/MethodLength
94-
9566
def results
9667
@results ||= Nokogiri::XML(csslint_xml)
9768
end

lib/cc/engine/csslint/check_details.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class CheckDetails
1919
"import" => { categories: "Bug Risk" },
2020
"known-properties" => { categories: "Bug Risk" },
2121
"overqualified-elements" => { categories: "Bug Risk" },
22+
"parse-error" => { categories: "Bug Risk" },
2223
"regex-selectors" => { categories: "Bug Risk" },
2324
"shorthand" => { categories: "Bug Risk" },
2425
"star-property-hack" => { categories: "Compatibility" },

0 commit comments

Comments
 (0)