6
6
/* global JSON */
7
7
/* exported cli */
8
8
9
- function cli ( api ) {
9
+ function cli ( api ) {
10
10
"use strict" ;
11
11
12
12
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." }
23
23
} ;
24
24
25
25
//-------------------------------------------------------------------------
@@ -32,7 +32,7 @@ function cli(api){
32
32
* @param type {String} The type of message to filter on.
33
33
* @return {Array } An array of matching messages.
34
34
*/
35
- function pluckByType ( messages , type ) {
35
+ function pluckByType ( messages , type ) {
36
36
return messages . filter ( function ( message ) {
37
37
return message . type === type ;
38
38
} ) ;
@@ -43,20 +43,20 @@ function cli(api){
43
43
* @param options {Object} The CLI options.
44
44
* @return {Object } A ruleset object.
45
45
*/
46
- function gatherRules ( options , ruleset ) {
46
+ function gatherRules ( options , ruleset ) {
47
47
var warnings = options . rules || options . warnings ,
48
48
errors = options . errors ;
49
49
50
- if ( warnings ) {
50
+ if ( warnings ) {
51
51
ruleset = ruleset || { } ;
52
- warnings . split ( "," ) . forEach ( function ( value ) {
52
+ warnings . split ( "," ) . forEach ( function ( value ) {
53
53
ruleset [ value ] = 1 ;
54
54
} ) ;
55
55
}
56
56
57
- if ( errors ) {
57
+ if ( errors ) {
58
58
ruleset = ruleset || { } ;
59
- errors . split ( "," ) . forEach ( function ( value ) {
59
+ errors . split ( "," ) . forEach ( function ( value ) {
60
60
ruleset [ value ] = 2 ;
61
61
} ) ;
62
62
}
@@ -75,7 +75,7 @@ function cli(api){
75
75
76
76
if ( ignore ) {
77
77
ruleset = CSSLint . getRuleset ( ) ;
78
- ignore . split ( "," ) . forEach ( function ( value ) {
78
+ ignore . split ( "," ) . forEach ( function ( value ) {
79
79
ruleset [ value ] = 0 ;
80
80
} ) ;
81
81
}
@@ -99,7 +99,7 @@ function cli(api){
99
99
100
100
if ( excludeList ) {
101
101
// 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 ) {
103
103
if ( api . isDirectory ( value ) ) {
104
104
excludeFiles = excludeFiles . concat ( api . getFiles ( value ) ) ;
105
105
} else {
@@ -108,10 +108,10 @@ function cli(api){
108
108
} ) ;
109
109
110
110
// Remove the excluded files from the list of files to lint
111
- excludeFiles . forEach ( function ( value ) {
111
+ excludeFiles . forEach ( function ( value ) {
112
112
fullPath = api . getFullPath ( value ) ;
113
113
if ( filesToLint . indexOf ( fullPath ) > - 1 ) {
114
- filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
114
+ filesToLint . splice ( filesToLint . indexOf ( fullPath ) , 1 ) ;
115
115
}
116
116
} ) ;
117
117
}
@@ -123,10 +123,10 @@ function cli(api){
123
123
* Outputs all available rules to the CLI.
124
124
* @return {void }
125
125
*/
126
- function printRules ( ) {
126
+ function printRules ( ) {
127
127
api . print ( "" ) ;
128
128
var rules = CSSLint . getRules ( ) ;
129
- rules . forEach ( function ( rule ) {
129
+ rules . forEach ( function ( rule ) {
130
130
api . print ( rule . id + "\n " + rule . desc + "\n" ) ;
131
131
} ) ;
132
132
}
@@ -157,7 +157,7 @@ function cli(api){
157
157
//var relativeFilePath = getRelativePath(api.getWorkingDirectory(), fullFilePath);
158
158
options . fullPath = api . getFullPath ( relativeFilePath ) ;
159
159
output = formatter . formatResults ( result , relativeFilePath , options ) ;
160
- if ( output ) {
160
+ if ( output ) {
161
161
api . print ( output ) ;
162
162
}
163
163
@@ -174,7 +174,7 @@ function cli(api){
174
174
* Outputs the help screen to the CLI.
175
175
* @return {void }
176
176
*/
177
- function outputHelp ( ) {
177
+ function outputHelp ( ) {
178
178
var lenToPad = 40 ,
179
179
toPrint = "" ,
180
180
formatString = "" ;
@@ -212,39 +212,39 @@ function cli(api){
212
212
* @param options {Object} options object
213
213
* @return {Number } exit code
214
214
*/
215
- function processFiles ( fileArray , options ) {
215
+ function processFiles ( fileArray , options ) {
216
216
var exitCode = 0 ,
217
217
formatId = options . format || "text" ,
218
218
formatter ,
219
- files = filterFiles ( fileArray , options ) ,
219
+ files = filterFiles ( fileArray , options ) ,
220
220
output ;
221
221
222
222
if ( ! files . length ) {
223
223
api . print ( "csslint: No files specified." ) ;
224
224
exitCode = 1 ;
225
225
} else {
226
- if ( ! CSSLint . hasFormat ( formatId ) ) {
226
+ if ( ! CSSLint . hasFormat ( formatId ) ) {
227
227
api . print ( "csslint: Unknown format '" + formatId + "'. Cannot proceed." ) ;
228
228
exitCode = 1 ;
229
229
} else {
230
230
formatter = CSSLint . getFormatter ( formatId ) ;
231
231
232
232
output = formatter . startFormat ( ) ;
233
- if ( output ) {
233
+ if ( output ) {
234
234
api . print ( output ) ;
235
235
}
236
236
237
237
238
- files . forEach ( function ( file ) {
238
+ files . forEach ( function ( file ) {
239
239
if ( exitCode === 0 ) {
240
- exitCode = processFile ( file , options ) ;
240
+ exitCode = processFile ( file , options ) ;
241
241
} else {
242
- processFile ( file , options ) ;
242
+ processFile ( file , options ) ;
243
243
}
244
244
} ) ;
245
245
246
246
output = formatter . endFormat ( ) ;
247
- if ( output ) {
247
+ if ( output ) {
248
248
api . print ( output ) ;
249
249
}
250
250
}
@@ -260,11 +260,11 @@ function cli(api){
260
260
parts ,
261
261
files = [ ] ;
262
262
263
- while ( arg ) {
264
- if ( arg . indexOf ( "--" ) === 0 ) {
263
+ while ( arg ) {
264
+ if ( arg . indexOf ( "--" ) === 0 ) {
265
265
argName = arg . substring ( 2 ) ;
266
266
267
- if ( argName . indexOf ( "=" ) > - 1 ) {
267
+ if ( argName . indexOf ( "=" ) > - 1 ) {
268
268
parts = argName . split ( "=" ) ;
269
269
options [ parts [ 0 ] ] = parts [ 1 ] ;
270
270
} else {
@@ -274,7 +274,7 @@ function cli(api){
274
274
} else {
275
275
276
276
//see if it's a directory or a file
277
- if ( api . isDirectory ( arg ) ) {
277
+ if ( api . isDirectory ( arg ) ) {
278
278
files = files . concat ( api . getFiles ( arg ) ) ;
279
279
} else {
280
280
files . push ( arg ) ;
@@ -317,7 +317,7 @@ function cli(api){
317
317
data += "--" + optionName + "=" + json [ optionName ] . join ( ) ;
318
318
}
319
319
}
320
- } catch ( e ) { }
320
+ } catch ( e ) { }
321
321
}
322
322
options = processArguments ( data . split ( / [ \s \n \r ] + / m) ) ;
323
323
}
@@ -338,17 +338,17 @@ function cli(api){
338
338
// Preprocess command line arguments
339
339
cliOptions = processArguments ( args ) ;
340
340
341
- if ( cliOptions . help || argCount === 0 ) {
341
+ if ( cliOptions . help || argCount === 0 ) {
342
342
outputHelp ( ) ;
343
343
api . quit ( 0 ) ;
344
344
}
345
345
346
- if ( cliOptions . version ) {
346
+ if ( cliOptions . version ) {
347
347
api . print ( "v" + CSSLint . version ) ;
348
348
api . quit ( 0 ) ;
349
349
}
350
350
351
- if ( cliOptions [ "list-rules" ] ) {
351
+ if ( cliOptions [ "list-rules" ] ) {
352
352
printRules ( ) ;
353
353
api . quit ( 0 ) ;
354
354
}
@@ -366,5 +366,5 @@ function cli(api){
366
366
// Validate options
367
367
validateOptions ( options ) ;
368
368
369
- api . quit ( processFiles ( options . files , options ) ) ;
369
+ api . quit ( processFiles ( options . files , options ) ) ;
370
370
}
0 commit comments