1
1
#!/usr/bin/env node
2
2
/*!
3
- CSSLint
4
- Copyright (c) 2014 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
3
+ CSSLint v0.10.0
4
+ Copyright (c) 2015 Nicole Sullivan and Nicholas C. Zakas. All rights reserved.
5
5
6
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
of this software and associated documentation files (the 'Software'), to deal
@@ -22,14 +22,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
THE SOFTWARE.
23
23
24
24
*/
25
- /* Build: v0.10.0 11-April-2014 12:11:52 */ /*
25
+ /*
26
26
* Encapsulates all of the CLI functionality. The api argument simply
27
27
* provides environment-specific functionality.
28
28
*/
29
29
30
+ /* global JSON */
30
31
/* exported cli */
31
32
32
33
function cli ( api ) {
34
+ "use strict" ;
33
35
34
36
var globalOptions = {
35
37
"help" : { "format" : "" , "description" : "Displays this information." } ,
@@ -40,6 +42,7 @@ function cli(api){
40
42
"warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
41
43
"ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
42
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." } ,
43
46
"version" : { "format" : "" , "description" : "Outputs the current version number." }
44
47
} ;
45
48
@@ -274,8 +277,9 @@ function cli(api){
274
277
}
275
278
276
279
277
- function processArguments ( args , options ) {
280
+ function processArguments ( args , extend ) {
278
281
var arg = args . shift ( ) ,
282
+ options = extend || { } ,
279
283
argName ,
280
284
parts ,
281
285
files = [ ] ;
@@ -317,9 +321,16 @@ function cli(api){
317
321
}
318
322
}
319
323
320
- function readConfigFile ( options ) {
321
- var data = api . readFile ( api . getFullPath ( ".csslintrc" ) ) ,
322
- json ;
324
+ function readConfigFile ( config ) {
325
+ var csslintrc = config || ".csslintrc" ,
326
+ data = api . readFile ( api . getFullPath ( csslintrc ) ) ;
327
+ return data ;
328
+ }
329
+
330
+ function readConfigData ( config ) {
331
+ var data = readConfigFile ( config ) ,
332
+ json ,
333
+ options = { } ;
323
334
if ( data ) {
324
335
if ( data . charAt ( 0 ) === "{" ) {
325
336
try {
@@ -332,46 +343,53 @@ function cli(api){
332
343
}
333
344
} catch ( e ) { }
334
345
}
335
- options = processArguments ( data . split ( / [ \s \n \r ] + / m) , options ) ;
346
+ options = processArguments ( data . split ( / [ \s \n \r ] + / m) ) ;
336
347
}
337
348
338
349
return options ;
339
350
}
340
351
341
-
342
-
343
352
//-----------------------------------------------------------------------------
344
353
// Process command line
345
354
//-----------------------------------------------------------------------------
346
355
347
356
var args = api . args ,
348
357
argCount = args . length ,
349
- options = { } ;
358
+ options ,
359
+ rcOptions ,
360
+ cliOptions ;
350
361
351
- // first look for config file .csslintrc
352
- options = readConfigFile ( options ) ;
362
+ // Preprocess command line arguments
363
+ cliOptions = processArguments ( args ) ;
353
364
354
- // Command line arguments override config file
355
- options = processArguments ( args , options ) ;
356
-
357
- if ( options . help || argCount === 0 ) {
365
+ if ( cliOptions . help || argCount === 0 ) {
358
366
outputHelp ( ) ;
359
367
api . quit ( 0 ) ;
360
368
}
361
369
362
- // Validate options
363
- validateOptions ( options ) ;
364
-
365
- if ( options . version ) {
370
+ if ( cliOptions . version ) {
366
371
api . print ( "v" + CSSLint . version ) ;
367
372
api . quit ( 0 ) ;
368
373
}
369
374
370
- if ( options [ "list-rules" ] ) {
375
+ if ( cliOptions [ "list-rules" ] ) {
371
376
printRules ( ) ;
372
377
api . quit ( 0 ) ;
373
378
}
374
379
380
+ // Look for config file
381
+ rcOptions = readConfigData ( cliOptions . config ) ;
382
+
383
+ // Command line arguments override config file
384
+ options = CSSLint . Util . mix ( rcOptions , cliOptions ) ;
385
+
386
+ // hot fix for CSSLint.Util.mix current behavior
387
+ // https://github.com/CSSLint/csslint/issues/501
388
+ options = rcOptions ;
389
+
390
+ // Validate options
391
+ validateOptions ( options ) ;
392
+
375
393
api . quit ( processFiles ( options . files , options ) ) ;
376
394
}
377
395
@@ -382,6 +400,7 @@ function cli(api){
382
400
/* jshint node:true */
383
401
/* global cli */
384
402
/* exported CSSLint */
403
+ "use strict" ;
385
404
386
405
var fs = require ( "fs" ) ,
387
406
path = require ( "path" ) ,
@@ -421,7 +440,7 @@ cli({
421
440
var path = stack . concat ( [ file ] ) . join ( "/" ) ,
422
441
stat = fs . statSync ( path ) ;
423
442
424
- if ( file [ 0 ] == "." ) {
443
+ if ( file [ 0 ] === "." ) {
425
444
return ;
426
445
} else if ( stat . isFile ( ) && / \. c s s $ / . test ( file ) ) {
427
446
files . push ( path ) ;
@@ -453,4 +472,3 @@ cli({
453
472
}
454
473
}
455
474
} ) ;
456
-
0 commit comments