1
- var glob = require ( 'glob' ) ,
2
- spawn = require ( 'child_process' ) . spawn ,
3
- fs = require ( 'fs' ) ,
4
- path = require ( 'path' ) ,
5
- diff = require ( './diff' ) ,
6
- fileBuilder = require ( './file-builder' ) ;
7
-
8
- module . exports = FixMe ;
9
-
10
- function FixMe ( ) { }
11
-
12
- FixMe . prototype . runEngine = function ( ) {
13
- var analysisFiles = [ ] ,
14
- config = {
15
- include_paths : [ "./" ] ,
16
- strings : [ "FIXME" , "TODO" , "HACK" , "XXX" , "BUG" ]
17
- } ,
18
- self = this ;
1
+ var glob = require ( 'glob' ) ;
2
+ var spawn = require ( 'child_process' ) . spawn ;
3
+ var fs = require ( 'fs' ) ;
4
+ var path = require ( 'path' ) ;
5
+
6
+ function FixMe ( ) { }
7
+
8
+ FixMe . prototype . runEngine = function ( ) {
9
+ var analysisFiles = [ ] ;
10
+ var config = {
11
+ include_paths : [ './' ] ,
12
+ strings : [ 'FIXME' , 'TODO' , 'HACK' , 'XXX' , 'BUG' ]
13
+ } ;
19
14
20
15
if ( fs . existsSync ( '/config.json' ) ) {
21
16
var userConfig = JSON . parse ( fs . readFileSync ( '/config.json' ) ) ;
@@ -29,64 +24,50 @@ FixMe.prototype.runEngine = function(){
29
24
}
30
25
}
31
26
32
- analysisFiles = fileBuilder . withIncludes ( config . include_paths ) ;
33
- analysisFiles = fileBuilder . filterFiles ( analysisFiles ) ;
34
-
35
- self . find ( analysisFiles , config . strings ) ;
27
+ this . find ( config . include_paths , config . strings ) ;
36
28
}
37
29
38
- FixMe . prototype . find = function ( files , strings ) {
30
+ FixMe . prototype . find = function ( files , strings ) {
39
31
var fixmeStrings = '(' + strings . join ( '|' ) + ')' ;
40
32
var grep = spawn ( 'grep' , [ '-nHwoEr' , fixmeStrings ] . concat ( files ) ) ;
41
33
var self = this ;
42
34
43
35
grep . stdout . on ( 'data' , function ( data ) {
44
- var results = data . toString ( ) ;
45
-
46
- if ( results !== "" ) {
47
- // Parses grep output
48
- var lines = results . split ( "\n" ) ;
36
+ var lines = data . toString ( ) . split ( '\n' ) ;
49
37
50
- lines . forEach ( function ( line , index , array ) {
51
- // grep spits out an extra line that we can ignore
52
- if ( index < ( array . length - 1 ) ) {
53
- // Grep output is colon delimited
54
- var cols = line . split ( ":" ) ;
38
+ lines . forEach ( function ( line ) {
39
+ var cols = line . split ( ':' ) ;
40
+ var fileName = self . formatPath ( cols [ 0 ] ) ;
41
+ var lineNum = cols [ 1 ] ;
42
+ var matchedString = cols [ 2 ] ;
55
43
56
- // Remove remnants of container paths for external display
57
- var fileName = self . formatPath ( cols [ 0 ] ) ;
58
- var lineNum = cols [ 1 ] ;
59
- var matchedString = cols [ 2 ] ;
60
-
61
- if ( matchedString !== undefined ) {
62
- self . printIssue ( fileName , parseInt ( lineNum ) , matchedString ) ;
63
- }
64
- }
65
- } )
66
- }
44
+ if ( matchedString !== undefined ) {
45
+ self . printIssue ( fileName , parseInt ( lineNum ) , matchedString ) ;
46
+ }
47
+ } ) ;
67
48
} ) ;
68
49
}
69
50
70
51
FixMe . prototype . printIssue = function ( fileName , lineNum , matchedString ) {
71
- // Prints properly structured Issue data to STDOUT according to Code Climate Engine specification.
72
- var issue = {
73
- "type" : "issue" ,
74
- "check_name" : matchedString ,
75
- "description" : matchedString + " found" ,
76
- "categories" : [ "Bug Risk" ] ,
77
- "location" :{
78
- "path" : fileName ,
79
- "lines" : {
80
- "begin" : lineNum ,
81
- "end" : lineNum
52
+ var issue = JSON . stringify ( {
53
+ 'type' : 'issue' ,
54
+ 'check_name' : matchedString ,
55
+ 'description' : matchedString + ' found' ,
56
+ 'categories' : [ 'Bug Risk' ] ,
57
+ 'location' : {
58
+ 'path' : fileName ,
59
+ 'lines' : {
60
+ 'begin' : lineNum ,
61
+ 'end' : lineNum
82
62
}
83
63
}
84
- } ;
64
+ } ) ;
85
65
86
- var issueString = JSON . stringify ( issue ) + "\0" ;
87
- console . log ( issueString ) ;
66
+ console . log ( issue + '\0' ) ;
88
67
}
89
68
90
69
FixMe . prototype . formatPath = function ( path ) {
91
70
return path . replace ( / ^ \/ c o d e \/ / , '' ) ;
92
71
}
72
+
73
+ module . exports = FixMe ;
0 commit comments