@@ -30,20 +30,20 @@ THE SOFTWARE.
30
30
/* global JSON */
31
31
/* exported cli */
32
32
33
- function cli ( api ) {
33
+ function cli ( api ) {
34
34
"use strict" ;
35
35
36
36
var globalOptions = {
37
- "help" : { "format" : "" , "description" : "Displays this information." } ,
38
- "format" : { "format" : "<format>" , "description" : "Indicate which format to use for output." } ,
39
- "list-rules" : { "format" : "" , "description" : "Outputs all of the rules available." } ,
40
- "quiet" : { "format" : "" , "description" : "Only output when errors are present." } ,
41
- "errors" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as errors." } ,
42
- "warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
43
- "ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
44
- "exclude-list" : { "format" : "<file|dir[,file|dir]+>" , "description" : "Indicate which files/directories to exclude from being linted." } ,
45
- "config" : { "format" : "<file>" , "description" : "Reads csslint options from specified file." } ,
46
- "version" : { "format" : "" , "description" : "Outputs the current version number." }
37
+ "help" : { "format" : "" , "description" : "Displays this information." } ,
38
+ "format" : { "format" : "<format>" , "description" : "Indicate which format to use for output." } ,
39
+ "list-rules" : { "format" : "" , "description" : "Outputs all of the rules available." } ,
40
+ "quiet" : { "format" : "" , "description" : "Only output when errors are present." } ,
41
+ "errors" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as errors." } ,
42
+ "warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
43
+ "ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
44
+ "exclude-list" : { "format" : "<file|dir[,file|dir]+>" , "description" : "Indicate which files/directories to exclude from being linted." } ,
45
+ "config" : { "format" : "<file>" , "description" : "Reads csslint options from specified file." } ,
46
+ "version" : { "format" : "" , "description" : "Outputs the current version number." }
47
47
} ;
48
48
49
49
//-------------------------------------------------------------------------
@@ -56,7 +56,7 @@ function cli(api){
56
56
* @param type {String} The type of message to filter on.
57
57
* @return {Array } An array of matching messages.
58
58
*/
59
- function pluckByType ( messages , type ) {
59
+ function pluckByType ( messages , type ) {
60
60
return messages . filter ( function ( message ) {
61
61
return message . type === type ;
62
62
} ) ;
@@ -67,20 +67,20 @@ function cli(api){
67
67
* @param options {Object} The CLI options.
68
68
* @return {Object } A ruleset object.
69
69
*/
70
- function gatherRules ( options , ruleset ) {
70
+ function gatherRules ( options , ruleset ) {
71
71
var warnings = options . rules || options . warnings ,
72
72
errors = options . errors ;
73
73
74
- if ( warnings ) {
74
+ if ( warnings ) {
75
75
ruleset = ruleset || { } ;
76
- warnings . split ( "," ) . forEach ( function ( value ) {
76
+ warnings . split ( "," ) . forEach ( function ( value ) {
77
77
ruleset [ value ] = 1 ;
78
78
} ) ;
79
79
}
80
80
81
- if ( errors ) {
81
+ if ( errors ) {
82
82
ruleset = ruleset || { } ;
83
- errors . split ( "," ) . forEach ( function ( value ) {
83
+ errors . split ( "," ) . forEach ( function ( value ) {
84
84
ruleset [ value ] = 2 ;
85
85
} ) ;
86
86
}
@@ -99,7 +99,7 @@ function cli(api){
99
99
100
100
if ( ignore ) {
101
101
ruleset = CSSLint . getRuleset ( ) ;
102
- ignore . split ( "," ) . forEach ( function ( value ) {
102
+ ignore . split ( "," ) . forEach ( function ( value ) {
103
103
ruleset [ value ] = 0 ;
104
104
} ) ;
105
105
}
@@ -123,7 +123,7 @@ function cli(api){
123
123
124
124
if ( excludeList ) {
125
125
// Build up the exclude list, expanding any directory exclusions that were passed in
126
- excludeList . split ( "," ) . forEach ( function ( value ) {
126
+ excludeList . split ( "," ) . forEach ( function ( value ) {
127
127
if ( api . isDirectory ( value ) ) {
128
128
excludeFiles = excludeFiles . concat ( api . getFiles ( value ) ) ;
129
129
} else {
@@ -132,10 +132,10 @@ function cli(api){
132
132
} ) ;
133
133
134
134
// Remove the excluded files from the list of files to lint
135
- excludeFiles . forEach ( function ( value ) {
135
+ excludeFiles . forEach ( function ( value ) {
136
136
fullPath = api . getFullPath ( value ) ;
137
137
if ( filesToLint . indexOf ( fullPath ) > - 1 ) {
138
- filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
138
+ filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
139
139
}
140
140
} ) ;
141
141
}
@@ -147,10 +147,10 @@ function cli(api){
147
147
* Outputs all available rules to the CLI.
148
148
* @return {void }
149
149
*/
150
- function printRules ( ) {
150
+ function printRules ( ) {
151
151
api . print ( "" ) ;
152
152
var rules = CSSLint . getRules ( ) ;
153
- rules . forEach ( function ( rule ) {
153
+ rules . forEach ( function ( rule ) {
154
154
api . print ( rule . id + "\n " + rule . desc + "\n" ) ;
155
155
} ) ;
156
156
}
@@ -181,7 +181,7 @@ function cli(api){
181
181
//var relativeFilePath = getRelativePath(api.getWorkingDirectory(), fullFilePath);
182
182
options . fullPath = api . getFullPath ( relativeFilePath ) ;
183
183
output = formatter . formatResults ( result , relativeFilePath , options ) ;
184
- if ( output ) {
184
+ if ( output ) {
185
185
api . print ( output ) ;
186
186
}
187
187
@@ -198,7 +198,7 @@ function cli(api){
198
198
* Outputs the help screen to the CLI.
199
199
* @return {void }
200
200
*/
201
- function outputHelp ( ) {
201
+ function outputHelp ( ) {
202
202
var lenToPad = 40 ,
203
203
toPrint = "" ,
204
204
formatString = "" ;
@@ -236,39 +236,39 @@ function cli(api){
236
236
* @param options {Object} options object
237
237
* @return {Number } exit code
238
238
*/
239
- function processFiles ( fileArray , options ) {
239
+ function processFiles ( fileArray , options ) {
240
240
var exitCode = 0 ,
241
241
formatId = options . format || "text" ,
242
242
formatter ,
243
- files = filterFiles ( fileArray , options ) ,
243
+ files = filterFiles ( fileArray , options ) ,
244
244
output ;
245
245
246
246
if ( ! files . length ) {
247
247
api . print ( "csslint: No files specified." ) ;
248
248
exitCode = 1 ;
249
249
} else {
250
- if ( ! CSSLint . hasFormat ( formatId ) ) {
250
+ if ( ! CSSLint . hasFormat ( formatId ) ) {
251
251
api . print ( "csslint: Unknown format '" + formatId + "'. Cannot proceed." ) ;
252
252
exitCode = 1 ;
253
253
} else {
254
254
formatter = CSSLint . getFormatter ( formatId ) ;
255
255
256
256
output = formatter . startFormat ( ) ;
257
- if ( output ) {
257
+ if ( output ) {
258
258
api . print ( output ) ;
259
259
}
260
260
261
261
262
- files . forEach ( function ( file ) {
262
+ files . forEach ( function ( file ) {
263
263
if ( exitCode === 0 ) {
264
- exitCode = processFile ( file , options ) ;
264
+ exitCode = processFile ( file , options ) ;
265
265
} else {
266
- processFile ( file , options ) ;
266
+ processFile ( file , options ) ;
267
267
}
268
268
} ) ;
269
269
270
270
output = formatter . endFormat ( ) ;
271
- if ( output ) {
271
+ if ( output ) {
272
272
api . print ( output ) ;
273
273
}
274
274
}
@@ -284,11 +284,11 @@ function cli(api){
284
284
parts ,
285
285
files = [ ] ;
286
286
287
- while ( arg ) {
288
- if ( arg . indexOf ( "--" ) === 0 ) {
287
+ while ( arg ) {
288
+ if ( arg . indexOf ( "--" ) === 0 ) {
289
289
argName = arg . substring ( 2 ) ;
290
290
291
- if ( argName . indexOf ( "=" ) > - 1 ) {
291
+ if ( argName . indexOf ( "=" ) > - 1 ) {
292
292
parts = argName . split ( "=" ) ;
293
293
options [ parts [ 0 ] ] = parts [ 1 ] ;
294
294
} else {
@@ -298,7 +298,7 @@ function cli(api){
298
298
} else {
299
299
300
300
//see if it's a directory or a file
301
- if ( api . isDirectory ( arg ) ) {
301
+ if ( api . isDirectory ( arg ) ) {
302
302
files = files . concat ( api . getFiles ( arg ) ) ;
303
303
} else {
304
304
files . push ( arg ) ;
@@ -341,7 +341,7 @@ function cli(api){
341
341
data += "--" + optionName + "=" + json [ optionName ] . join ( ) ;
342
342
}
343
343
}
344
- } catch ( e ) { }
344
+ } catch ( e ) { }
345
345
}
346
346
options = processArguments ( data . split ( / [ \s \n \r ] + / m) ) ;
347
347
}
@@ -362,17 +362,17 @@ function cli(api){
362
362
// Preprocess command line arguments
363
363
cliOptions = processArguments ( args ) ;
364
364
365
- if ( cliOptions . help || argCount === 0 ) {
365
+ if ( cliOptions . help || argCount === 0 ) {
366
366
outputHelp ( ) ;
367
367
api . quit ( 0 ) ;
368
368
}
369
369
370
- if ( cliOptions . version ) {
370
+ if ( cliOptions . version ) {
371
371
api . print ( "v" + CSSLint . version ) ;
372
372
api . quit ( 0 ) ;
373
373
}
374
374
375
- if ( cliOptions [ "list-rules" ] ) {
375
+ if ( cliOptions [ "list-rules" ] ) {
376
376
printRules ( ) ;
377
377
api . quit ( 0 ) ;
378
378
}
@@ -390,7 +390,7 @@ function cli(api){
390
390
// Validate options
391
391
validateOptions ( options ) ;
392
392
393
- api . quit ( processFiles ( options . files , options ) ) ;
393
+ api . quit ( processFiles ( options . files , options ) ) ;
394
394
}
395
395
396
396
/*
@@ -409,42 +409,42 @@ var fs = require("fs"),
409
409
cli ( {
410
410
args : process . argv . slice ( 2 ) ,
411
411
412
- print : function ( message ) {
412
+ print : function ( message ) {
413
413
fs . writeSync ( 1 , message + "\n" ) ;
414
414
} ,
415
415
416
- quit : function ( code ) {
416
+ quit : function ( code ) {
417
417
process . exit ( code || 0 ) ;
418
418
} ,
419
419
420
- isDirectory : function ( name ) {
420
+ isDirectory : function ( name ) {
421
421
try {
422
422
return fs . statSync ( name ) . isDirectory ( ) ;
423
423
} catch ( ex ) {
424
424
return false ;
425
425
}
426
426
} ,
427
427
428
- getFiles : function ( dir ) {
428
+ getFiles : function ( dir ) {
429
429
var files = [ ] ;
430
430
431
431
try {
432
432
fs . statSync ( dir ) ;
433
- } catch ( ex ) {
433
+ } catch ( ex ) {
434
434
return [ ] ;
435
435
}
436
436
437
- function traverse ( dir , stack ) {
437
+ function traverse ( dir , stack ) {
438
438
stack . push ( dir ) ;
439
- fs . readdirSync ( stack . join ( "/" ) ) . forEach ( function ( file ) {
439
+ fs . readdirSync ( stack . join ( "/" ) ) . forEach ( function ( file ) {
440
440
var path = stack . concat ( [ file ] ) . join ( "/" ) ,
441
441
stat = fs . statSync ( path ) ;
442
442
443
443
if ( file [ 0 ] === "." ) {
444
444
return ;
445
- } else if ( stat . isFile ( ) && / \. c s s $ / . test ( file ) ) {
445
+ } else if ( stat . isFile ( ) && / \. c s s $ / . test ( file ) ) {
446
446
files . push ( path ) ;
447
- } else if ( stat . isDirectory ( ) ) {
447
+ } else if ( stat . isDirectory ( ) ) {
448
448
traverse ( file , stack ) ;
449
449
}
450
450
} ) ;
@@ -460,11 +460,11 @@ cli({
460
460
return process . cwd ( ) ;
461
461
} ,
462
462
463
- getFullPath : function ( filename ) {
463
+ getFullPath : function ( filename ) {
464
464
return path . resolve ( process . cwd ( ) , filename ) ;
465
465
} ,
466
466
467
- readFile : function ( filename ) {
467
+ readFile : function ( filename ) {
468
468
try {
469
469
return fs . readFileSync ( filename , "utf-8" ) ;
470
470
} catch ( ex ) {
0 commit comments