66/* global JSON */
77/* exported cli */
88
9- function cli ( api ) {
9+ function cli ( api ) {
1010 "use strict" ;
1111
1212 var globalOptions = {
13- "help" : { "format" : "" , "description" : "Displays this information." } ,
14- "format" : { "format" : "<format>" , "description" : "Indicate which format to use for output." } ,
15- "list-rules" : { "format" : "" , "description" : "Outputs all of the rules available." } ,
16- "quiet" : { "format" : "" , "description" : "Only output when errors are present." } ,
17- "errors" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as errors." } ,
18- "warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
19- "ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
20- "exclude-list" : { "format" : "<file|dir[,file|dir]+>" , "description" : "Indicate which files/directories to exclude from being linted." } ,
21- "config" : { "format" : "<file>" , "description" : "Reads csslint options from specified file." } ,
22- "version" : { "format" : "" , "description" : "Outputs the current version number." }
13+ "help" : { "format" : "" , "description" : "Displays this information." } ,
14+ "format" : { "format" : "<format>" , "description" : "Indicate which format to use for output." } ,
15+ "list-rules" : { "format" : "" , "description" : "Outputs all of the rules available." } ,
16+ "quiet" : { "format" : "" , "description" : "Only output when errors are present." } ,
17+ "errors" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as errors." } ,
18+ "warnings" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to include as warnings." } ,
19+ "ignore" : { "format" : "<rule[,rule]+>" , "description" : "Indicate which rules to ignore completely." } ,
20+ "exclude-list" : { "format" : "<file|dir[,file|dir]+>" , "description" : "Indicate which files/directories to exclude from being linted." } ,
21+ "config" : { "format" : "<file>" , "description" : "Reads csslint options from specified file." } ,
22+ "version" : { "format" : "" , "description" : "Outputs the current version number." }
2323 } ;
2424
2525 //-------------------------------------------------------------------------
@@ -32,7 +32,7 @@ function cli(api){
3232 * @param type {String} The type of message to filter on.
3333 * @return {Array } An array of matching messages.
3434 */
35- function pluckByType ( messages , type ) {
35+ function pluckByType ( messages , type ) {
3636 return messages . filter ( function ( message ) {
3737 return message . type === type ;
3838 } ) ;
@@ -43,20 +43,20 @@ function cli(api){
4343 * @param options {Object} The CLI options.
4444 * @return {Object } A ruleset object.
4545 */
46- function gatherRules ( options , ruleset ) {
46+ function gatherRules ( options , ruleset ) {
4747 var warnings = options . rules || options . warnings ,
4848 errors = options . errors ;
4949
50- if ( warnings ) {
50+ if ( warnings ) {
5151 ruleset = ruleset || { } ;
52- warnings . split ( "," ) . forEach ( function ( value ) {
52+ warnings . split ( "," ) . forEach ( function ( value ) {
5353 ruleset [ value ] = 1 ;
5454 } ) ;
5555 }
5656
57- if ( errors ) {
57+ if ( errors ) {
5858 ruleset = ruleset || { } ;
59- errors . split ( "," ) . forEach ( function ( value ) {
59+ errors . split ( "," ) . forEach ( function ( value ) {
6060 ruleset [ value ] = 2 ;
6161 } ) ;
6262 }
@@ -75,7 +75,7 @@ function cli(api){
7575
7676 if ( ignore ) {
7777 ruleset = CSSLint . getRuleset ( ) ;
78- ignore . split ( "," ) . forEach ( function ( value ) {
78+ ignore . split ( "," ) . forEach ( function ( value ) {
7979 ruleset [ value ] = 0 ;
8080 } ) ;
8181 }
@@ -99,7 +99,7 @@ function cli(api){
9999
100100 if ( excludeList ) {
101101 // Build up the exclude list, expanding any directory exclusions that were passed in
102- excludeList . split ( "," ) . forEach ( function ( value ) {
102+ excludeList . split ( "," ) . forEach ( function ( value ) {
103103 if ( api . isDirectory ( value ) ) {
104104 excludeFiles = excludeFiles . concat ( api . getFiles ( value ) ) ;
105105 } else {
@@ -108,10 +108,10 @@ function cli(api){
108108 } ) ;
109109
110110 // Remove the excluded files from the list of files to lint
111- excludeFiles . forEach ( function ( value ) {
111+ excludeFiles . forEach ( function ( value ) {
112112 fullPath = api . getFullPath ( value ) ;
113113 if ( filesToLint . indexOf ( fullPath ) > - 1 ) {
114- filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
114+ filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
115115 }
116116 } ) ;
117117 }
@@ -123,10 +123,10 @@ function cli(api){
123123 * Outputs all available rules to the CLI.
124124 * @return {void }
125125 */
126- function printRules ( ) {
126+ function printRules ( ) {
127127 api . print ( "" ) ;
128128 var rules = CSSLint . getRules ( ) ;
129- rules . forEach ( function ( rule ) {
129+ rules . forEach ( function ( rule ) {
130130 api . print ( rule . id + "\n " + rule . desc + "\n" ) ;
131131 } ) ;
132132 }
@@ -157,7 +157,7 @@ function cli(api){
157157 //var relativeFilePath = getRelativePath(api.getWorkingDirectory(), fullFilePath);
158158 options . fullPath = api . getFullPath ( relativeFilePath ) ;
159159 output = formatter . formatResults ( result , relativeFilePath , options ) ;
160- if ( output ) {
160+ if ( output ) {
161161 api . print ( output ) ;
162162 }
163163
@@ -174,7 +174,7 @@ function cli(api){
174174 * Outputs the help screen to the CLI.
175175 * @return {void }
176176 */
177- function outputHelp ( ) {
177+ function outputHelp ( ) {
178178 var lenToPad = 40 ,
179179 toPrint = "" ,
180180 formatString = "" ;
@@ -212,39 +212,39 @@ function cli(api){
212212 * @param options {Object} options object
213213 * @return {Number } exit code
214214 */
215- function processFiles ( fileArray , options ) {
215+ function processFiles ( fileArray , options ) {
216216 var exitCode = 0 ,
217217 formatId = options . format || "text" ,
218218 formatter ,
219- files = filterFiles ( fileArray , options ) ,
219+ files = filterFiles ( fileArray , options ) ,
220220 output ;
221221
222222 if ( ! files . length ) {
223223 api . print ( "csslint: No files specified." ) ;
224224 exitCode = 1 ;
225225 } else {
226- if ( ! CSSLint . hasFormat ( formatId ) ) {
226+ if ( ! CSSLint . hasFormat ( formatId ) ) {
227227 api . print ( "csslint: Unknown format '" + formatId + "'. Cannot proceed." ) ;
228228 exitCode = 1 ;
229229 } else {
230230 formatter = CSSLint . getFormatter ( formatId ) ;
231231
232232 output = formatter . startFormat ( ) ;
233- if ( output ) {
233+ if ( output ) {
234234 api . print ( output ) ;
235235 }
236236
237237
238- files . forEach ( function ( file ) {
238+ files . forEach ( function ( file ) {
239239 if ( exitCode === 0 ) {
240- exitCode = processFile ( file , options ) ;
240+ exitCode = processFile ( file , options ) ;
241241 } else {
242- processFile ( file , options ) ;
242+ processFile ( file , options ) ;
243243 }
244244 } ) ;
245245
246246 output = formatter . endFormat ( ) ;
247- if ( output ) {
247+ if ( output ) {
248248 api . print ( output ) ;
249249 }
250250 }
@@ -260,11 +260,11 @@ function cli(api){
260260 parts ,
261261 files = [ ] ;
262262
263- while ( arg ) {
264- if ( arg . indexOf ( "--" ) === 0 ) {
263+ while ( arg ) {
264+ if ( arg . indexOf ( "--" ) === 0 ) {
265265 argName = arg . substring ( 2 ) ;
266266
267- if ( argName . indexOf ( "=" ) > - 1 ) {
267+ if ( argName . indexOf ( "=" ) > - 1 ) {
268268 parts = argName . split ( "=" ) ;
269269 options [ parts [ 0 ] ] = parts [ 1 ] ;
270270 } else {
@@ -274,7 +274,7 @@ function cli(api){
274274 } else {
275275
276276 //see if it's a directory or a file
277- if ( api . isDirectory ( arg ) ) {
277+ if ( api . isDirectory ( arg ) ) {
278278 files = files . concat ( api . getFiles ( arg ) ) ;
279279 } else {
280280 files . push ( arg ) ;
@@ -317,7 +317,7 @@ function cli(api){
317317 data += "--" + optionName + "=" + json [ optionName ] . join ( ) ;
318318 }
319319 }
320- } catch ( e ) { }
320+ } catch ( e ) { }
321321 }
322322 options = processArguments ( data . split ( / [ \s \n \r ] + / m) ) ;
323323 }
@@ -338,17 +338,17 @@ function cli(api){
338338 // Preprocess command line arguments
339339 cliOptions = processArguments ( args ) ;
340340
341- if ( cliOptions . help || argCount === 0 ) {
341+ if ( cliOptions . help || argCount === 0 ) {
342342 outputHelp ( ) ;
343343 api . quit ( 0 ) ;
344344 }
345345
346- if ( cliOptions . version ) {
346+ if ( cliOptions . version ) {
347347 api . print ( "v" + CSSLint . version ) ;
348348 api . quit ( 0 ) ;
349349 }
350350
351- if ( cliOptions [ "list-rules" ] ) {
351+ if ( cliOptions [ "list-rules" ] ) {
352352 printRules ( ) ;
353353 api . quit ( 0 ) ;
354354 }
@@ -366,5 +366,5 @@ function cli(api){
366366 // Validate options
367367 validateOptions ( options ) ;
368368
369- api . quit ( processFiles ( options . files , options ) ) ;
369+ api . quit ( processFiles ( options . files , options ) ) ;
370370}
0 commit comments