3
3
4
4
module CC
5
5
module Engine
6
+ MissingAttributesError = Class . new ( StandardError )
7
+
6
8
class CSSlint
7
9
autoload :CheckDetails , "cc/engine/csslint/check_details"
8
10
@@ -18,32 +20,7 @@ def run
18
20
path = file [ 'name' ] . sub ( /\A #{ @directory } \/ / , '' )
19
21
file . children . each do |node |
20
22
next unless node . name == "error"
21
-
22
- lint = node . attributes
23
- check_name = lint [ "identifier" ] . value
24
- check_details = CheckDetails . fetch ( check_name )
25
-
26
- issue = {
27
- type : "issue" ,
28
- check_name : check_name ,
29
- description : lint [ "message" ] . value ,
30
- categories : check_details . categories ,
31
- remediation_points : check_details . remediation_points ,
32
- location : {
33
- path : path ,
34
- positions : {
35
- begin : {
36
- line : lint [ "line" ] . value . to_i ,
37
- column : lint [ "column" ] . value . to_i
38
- } ,
39
- end : {
40
- line : lint [ "line" ] . value . to_i ,
41
- column : lint [ "column" ] . value . to_i
42
- }
43
- }
44
- }
45
- }
46
-
23
+ issue = create_issue ( node , path )
47
24
puts ( "#{ issue . to_json } \0 " )
48
25
end
49
26
end
@@ -52,6 +29,34 @@ def run
52
29
53
30
private
54
31
32
+ def create_issue ( node , path )
33
+ check_name = node . attributes . fetch ( "identifier" ) . value
34
+ check_details = CheckDetails . fetch ( check_name )
35
+
36
+ {
37
+ type : "issue" ,
38
+ check_name : check_name ,
39
+ description : node . attributes . fetch ( "message" ) . value ,
40
+ categories : check_details . categories ,
41
+ remediation_points : check_details . remediation_points ,
42
+ location : {
43
+ path : path ,
44
+ positions : {
45
+ begin : {
46
+ line : node . attributes . fetch ( "line" ) . value . to_i ,
47
+ column : node . attributes . fetch ( "column" ) . value . to_i
48
+ } ,
49
+ end : {
50
+ line : node . attributes . fetch ( "line" ) . value . to_i ,
51
+ column : node . attributes . fetch ( "column" ) . value . to_i
52
+ }
53
+ }
54
+ }
55
+ }
56
+ rescue KeyError => ex
57
+ raise MissingAttributesError , "#{ ex . message } on XML '#{ node } ' when analyzing file '#{ path } '"
58
+ end
59
+
55
60
def results
56
61
@results ||= Nokogiri ::XML ( csslint_xml )
57
62
end
0 commit comments