3
3
var _ = require ( "lodash" ) ;
4
4
var cli = require ( "cli" ) ;
5
5
var path = require ( "path" ) ;
6
- var shjs = require ( "shelljs" ) ;
7
6
var minimatch = require ( "minimatch" ) ;
8
7
var htmlparser = require ( "htmlparser2" ) ;
9
8
var exit = require ( "exit" ) ;
10
9
var stripJsonComments = require ( "strip-json-comments" ) ;
11
10
var JSHINT = require ( "./jshint.js" ) . JSHINT ;
12
11
var defReporter = require ( "./reporters/default" ) . reporter ;
12
+ var fsUtils = require ( "./fs-utils" ) ;
13
13
14
14
var OPTIONS = {
15
15
"config" : [ "c" , "Custom configuration file" , "string" , false ] ,
@@ -89,7 +89,7 @@ function findConfig(file) {
89
89
else if ( envs ) {
90
90
home = path . normalize ( path . join ( envs , ".jshintrc" ) ) ;
91
91
92
- if ( shjs . test ( "-e" , home ) )
92
+ if ( fsUtils . exists ( home ) )
93
93
return home ;
94
94
}
95
95
@@ -108,7 +108,7 @@ function getHomeDir() {
108
108
109
109
while ( paths . length ) {
110
110
homePath = paths . shift ( ) ;
111
- if ( homePath && shjs . test ( "-e" , homePath ) ) {
111
+ if ( fsUtils . exists ( homePath ) ) {
112
112
return homePath ;
113
113
}
114
114
}
@@ -177,7 +177,7 @@ function findFile(name, cwd) {
177
177
178
178
var parent = path . resolve ( cwd , "../" ) ;
179
179
180
- if ( shjs . test ( "-e" , filename ) ) {
180
+ if ( fsUtils . exists ( filename ) ) {
181
181
findFileResults [ filename ] = filename ;
182
182
return filename ;
183
183
}
@@ -203,7 +203,7 @@ function loadIgnores(params) {
203
203
return [ ] ;
204
204
}
205
205
206
- var lines = ( file ? shjs . cat ( file ) : "" ) . split ( "\n" ) ;
206
+ var lines = ( file ? fsUtils . readFile ( file ) : "" ) . split ( "\n" ) ;
207
207
var exclude = params . exclude || "" ;
208
208
lines . unshift . apply ( lines , exclude . split ( "," ) ) ;
209
209
@@ -237,7 +237,7 @@ function isIgnored(fp, patterns) {
237
237
return true ;
238
238
}
239
239
240
- if ( shjs . test ( "-d" , fp ) && ip . match ( / ^ [ ^ \/ \\ ] * [ \/ \\ ] ? $ / ) &&
240
+ if ( fsUtils . isDirectory ( fp ) && ip . match ( / ^ [ ^ \/ \\ ] * [ \/ \\ ] ? $ / ) &&
241
241
fp . match ( new RegExp ( "^" + ip + ".*" ) ) ) {
242
242
return true ;
243
243
}
@@ -419,15 +419,15 @@ function collect(fp, files, ignores, ext) {
419
419
return ;
420
420
}
421
421
422
- if ( ! shjs . test ( "-e" , fp ) ) {
422
+ if ( ! fsUtils . exists ( fp ) ) {
423
423
cli . error ( "Can't open " + fp ) ;
424
424
return ;
425
425
}
426
426
427
- if ( shjs . test ( "-d" , fp ) ) {
428
- shjs . ls ( fp ) . forEach ( function ( item ) {
427
+ if ( fsUtils . isDirectory ( fp ) ) {
428
+ fsUtils . readDirectory ( fp ) . forEach ( function ( item ) {
429
429
var itempath = path . join ( fp , item ) ;
430
- if ( shjs . test ( "-d" , itempath ) || item . match ( ext ) ) {
430
+ if ( fsUtils . isDirectory ( itempath ) || item . match ( ext ) ) {
431
431
collect ( itempath , files , ignores , ext ) ;
432
432
}
433
433
} ) ;
@@ -458,8 +458,8 @@ function lint(code, results, config, data, file) {
458
458
if ( config . prereq ) {
459
459
config . prereq . forEach ( function ( fp ) {
460
460
fp = path . join ( config . dirname , fp ) ;
461
- if ( shjs . test ( "-e" , fp ) )
462
- buffer . push ( shjs . cat ( fp ) ) ;
461
+ if ( fsUtils . exists ( fp ) )
462
+ buffer . push ( fsUtils . readFile ( fp ) ) ;
463
463
} ) ;
464
464
delete config . prereq ;
465
465
}
@@ -529,13 +529,13 @@ var exports = {
529
529
return { } ;
530
530
}
531
531
532
- if ( ! shjs . test ( "-e" , fp ) ) {
532
+ if ( ! fsUtils . exists ( fp ) ) {
533
533
cli . error ( "Can't find config file: " + fp ) ;
534
534
exports . exit ( 1 ) ;
535
535
}
536
536
537
537
try {
538
- var config = JSON . parse ( stripJsonComments ( shjs . cat ( fp ) ) ) ;
538
+ var config = JSON . parse ( stripJsonComments ( fsUtils . readFile ( fp ) ) ) ;
539
539
config . dirname = path . dirname ( fp ) ;
540
540
541
541
if ( config [ 'extends' ] ) {
@@ -653,7 +653,7 @@ var exports = {
653
653
var errors = [ ] ;
654
654
655
655
try {
656
- code = shjs . cat ( file ) ;
656
+ code = fsUtils . readFile ( file ) ;
657
657
} catch ( err ) {
658
658
cli . error ( "Can't open " + file ) ;
659
659
exports . exit ( 1 ) ;
0 commit comments