1
1
require "json"
2
2
require "nokogiri"
3
+ require "ostruct"
3
4
require "shellwords"
4
5
5
6
module CC
6
7
module Engine
7
8
MissingAttributesError = Class . new ( StandardError )
8
9
10
+ DEFAULT_IDENTIFIER = OpenStruct . new ( value : "parse-error" )
11
+
9
12
class CSSlint
10
13
autoload :CheckDetails , "cc/engine/csslint/check_details"
11
14
@@ -21,12 +24,7 @@ def run
21
24
path = file [ 'name' ] . sub ( /\A #{ @directory } \/ / , '' )
22
25
file . children . each do |node |
23
26
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 )
30
28
puts ( "#{ issue . to_json } \0 " )
31
29
end
32
30
end
@@ -37,7 +35,7 @@ def run
37
35
38
36
# rubocop:disable Metrics/MethodLength
39
37
def create_issue ( node , path )
40
- check_name = node . attributes . fetch ( "identifier" ) . value
38
+ check_name = node . attributes . fetch ( "identifier" , DEFAULT_IDENTIFIER ) . value
41
39
check_details = CheckDetails . fetch ( check_name )
42
40
43
41
{
@@ -65,33 +63,6 @@ def create_issue(node, path)
65
63
end
66
64
# rubocop:enable Metrics/MethodLength
67
65
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
-
95
66
def results
96
67
@results ||= Nokogiri ::XML ( csslint_xml )
97
68
end
0 commit comments