@@ -17,6 +17,7 @@ function cli(api){
1717 "warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
1818 "ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
1919 "exclude-list" : { "format" : "<file|dir[,file|dir]+>" , "description" : "Indicate which files/directories to exclude from being linted." } ,
20+ "config" : { "format" : "<file>" , "description" : "Reads csslint options from specified file." } ,
2021 "version" : { "format" : "" , "description" : "Outputs the current version number." }
2122 } ;
2223
@@ -251,8 +252,9 @@ function cli(api){
251252 }
252253
253254
254- function processArguments ( args , options ) {
255+ function processArguments ( args , extend ) {
255256 var arg = args . shift ( ) ,
257+ options = extend || { } ,
256258 argName ,
257259 parts ,
258260 files = [ ] ;
@@ -294,9 +296,16 @@ function cli(api){
294296 }
295297 }
296298
297- function readConfigFile ( options ) {
298- var data = api . readFile ( api . getFullPath ( ".csslintrc" ) ) ,
299- json ;
299+ function readConfigFile ( config ) {
300+ var csslintrc = config || ".csslintrc" ,
301+ data = api . readFile ( api . getFullPath ( csslintrc ) ) ;
302+ return data ;
303+ }
304+
305+ function readConfigData ( config ) {
306+ var data = readConfigFile ( config ) ,
307+ json ,
308+ options = { } ;
300309 if ( data ) {
301310 if ( data . charAt ( 0 ) === "{" ) {
302311 try {
@@ -309,45 +318,52 @@ function cli(api){
309318 }
310319 } catch ( e ) { }
311320 }
312- options = processArguments ( data . split ( / [ \s \n \r ] + / m) , options ) ;
321+ options = processArguments ( data . split ( / [ \s \n \r ] + / m) ) ;
313322 }
314323
315324 return options ;
316325 }
317326
318-
319-
320327 //-----------------------------------------------------------------------------
321328 // Process command line
322329 //-----------------------------------------------------------------------------
323330
324331 var args = api . args ,
325332 argCount = args . length ,
326- options = { } ;
333+ options ,
334+ rcOptions ,
335+ cliOptions ;
327336
328- // first look for config file .csslintrc
329- options = readConfigFile ( options ) ;
337+ // Preprocess command line arguments
338+ cliOptions = processArguments ( args ) ;
330339
331- // Command line arguments override config file
332- options = processArguments ( args , options ) ;
333-
334- if ( options . help || argCount === 0 ) {
340+ if ( cliOptions . help || argCount === 0 ) {
335341 outputHelp ( ) ;
336342 api . quit ( 0 ) ;
337343 }
338344
339- // Validate options
340- validateOptions ( options ) ;
341-
342- if ( options . version ) {
345+ if ( cliOptions . version ) {
343346 api . print ( "v" + CSSLint . version ) ;
344347 api . quit ( 0 ) ;
345348 }
346349
347- if ( options [ "list-rules" ] ) {
350+ if ( cliOptions [ "list-rules" ] ) {
348351 printRules ( ) ;
349352 api . quit ( 0 ) ;
350353 }
351354
355+ // Look for config file
356+ rcOptions = readConfigData ( cliOptions . config ) ;
357+
358+ // Command line arguments override config file
359+ options = CSSLint . Util . mix ( rcOptions , cliOptions ) ;
360+
361+ // hot fix for CSSLint.Util.mix current behavior
362+ // https://github.com/CSSLint/csslint/issues/501
363+ options = rcOptions ;
364+
365+ // Validate options
366+ validateOptions ( options ) ;
367+
352368 api . quit ( processFiles ( options . files , options ) ) ;
353369}
0 commit comments