@@ -8,7 +8,7 @@ function cli(api){
8
8
//-------------------------------------------------------------------------
9
9
// Helper functions
10
10
//-------------------------------------------------------------------------
11
-
11
+
12
12
/**
13
13
* Returns an array of messages for a particular type.
14
14
* @param messages {Array} Array of CSS Lint messages.
@@ -18,7 +18,7 @@ function cli(api){
18
18
function pluckByType ( messages , type ) {
19
19
return messages . filter ( function ( message ) {
20
20
return message . type === type ;
21
- } ) ;
21
+ } ) ;
22
22
}
23
23
24
24
/**
@@ -29,24 +29,24 @@ function cli(api){
29
29
function gatherRules ( options , ruleset ) {
30
30
var warnings = options . rules || options . warnings ,
31
31
errors = options . errors ;
32
-
32
+
33
33
if ( warnings ) {
34
34
ruleset = ruleset || { } ;
35
35
warnings . split ( "," ) . forEach ( function ( value ) {
36
36
ruleset [ value ] = 1 ;
37
37
} ) ;
38
38
}
39
-
39
+
40
40
if ( errors ) {
41
41
ruleset = ruleset || { } ;
42
42
errors . split ( "," ) . forEach ( function ( value ) {
43
43
ruleset [ value ] = 2 ;
44
44
} ) ;
45
45
}
46
-
46
+
47
47
return ruleset ;
48
48
}
49
-
49
+
50
50
/**
51
51
* Filters out rules using the ignore command line option.
52
52
* @param options {Object} the CLI options
@@ -55,17 +55,40 @@ function cli(api){
55
55
function filterRules ( options ) {
56
56
var ignore = options . ignore ,
57
57
ruleset = null ;
58
-
58
+
59
59
if ( ignore ) {
60
60
ruleset = CSSLint . getRuleset ( ) ;
61
61
ignore . split ( "," ) . forEach ( function ( value ) {
62
62
delete ruleset [ value ] ;
63
- } ) ;
63
+ } ) ;
64
64
}
65
-
65
+
66
66
return ruleset ;
67
67
}
68
68
69
+
70
+ /**
71
+ * Filters out files using the exclude-files command line option.
72
+ * @param files {Array} the list of files to check for exclusions
73
+ * @param options {Object} the CLI options
74
+ * @return {Array } A list of files
75
+ */
76
+ function filterFiles ( files , options ) {
77
+ var excludeFiles = options [ "exclude-files" ] ,
78
+ filesToLint = files ;
79
+
80
+
81
+ if ( excludeFiles ) {
82
+ excludeFiles . split ( "," ) . forEach ( function ( value ) {
83
+ if ( filesToLint . indexOf ( value ) > - 1 ) {
84
+ filesToLint . splice ( filesToLint . indexOf ( value ) , 1 ) ;
85
+ }
86
+ } ) ;
87
+ }
88
+
89
+ return filesToLint ;
90
+ }
91
+
69
92
/**
70
93
* Outputs all available rules to the CLI.
71
94
* @return {void }
@@ -107,12 +130,12 @@ function cli(api){
107
130
if ( output ) {
108
131
api . print ( output ) ;
109
132
}
110
-
133
+
111
134
if ( messages . length > 0 && pluckByType ( messages , "error" ) . length > 0 ) {
112
135
exitCode = 1 ;
113
136
}
114
137
}
115
-
138
+
116
139
return exitCode ;
117
140
}
118
141
@@ -126,14 +149,15 @@ function cli(api){
126
149
"\nUsage: csslint-rhino.js [options]* [file|dir]*" ,
127
150
" " ,
128
151
"Global Options" ,
129
- " --help Displays this information." ,
130
- " --format=<format> Indicate which format to use for output." ,
131
- " --list-rules Outputs all of the rules available." ,
132
- " --quiet Only output when errors are present." ,
133
- " --errors=<rule[,rule]+> Indicate which rules to include as errors." ,
134
- " --warnings=<rule[,rule]+> Indicate which rules to include as warnings." ,
135
- " --ignore=<rule,[,rule]+> Indicate which rules to ignore completely." ,
136
- " --version Outputs the current version number."
152
+ " --help Displays this information." ,
153
+ " --format=<format> Indicate which format to use for output." ,
154
+ " --list-rules Outputs all of the rules available." ,
155
+ " --quiet Only output when errors are present." ,
156
+ " --errors=<rule[,rule]+> Indicate which rules to include as errors." ,
157
+ " --warnings=<rule[,rule]+> Indicate which rules to include as warnings." ,
158
+ " --ignore=<rule,[,rule]+> Indicate which rules to ignore completely." ,
159
+ " --exclude-files=<file,[,file]+> Indicate which files to exclude from being linted." ,
160
+ " --version Outputs the current version number."
137
161
] . join ( "\n" ) + "\n" ) ;
138
162
}
139
163
@@ -143,56 +167,58 @@ function cli(api){
143
167
* @param options {Object} options object
144
168
* @return {Number } exit code
145
169
*/
146
- function processFiles ( files , options ) {
170
+ function processFiles ( fileArray , options ) {
147
171
var exitCode = 0 ,
148
172
formatId = options . format || "text" ,
149
173
formatter ,
174
+ files = filterFiles ( fileArray , options ) ,
150
175
output ;
151
-
176
+
152
177
if ( ! files . length ) {
153
178
api . print ( "csslint: No files specified." ) ;
154
179
exitCode = 1 ;
155
180
} else {
156
181
if ( ! CSSLint . hasFormat ( formatId ) ) {
157
182
api . print ( "csslint: Unknown format '" + formatId + "'. Cannot proceed." ) ;
158
- exitCode = 1 ;
183
+ exitCode = 1 ;
159
184
} else {
160
185
formatter = CSSLint . getFormatter ( formatId ) ;
161
-
186
+
162
187
output = formatter . startFormat ( ) ;
163
188
if ( output ) {
164
189
api . print ( output ) ;
165
190
}
166
191
192
+
167
193
files . forEach ( function ( file ) {
168
194
if ( exitCode === 0 ) {
169
195
exitCode = processFile ( file , options ) ;
170
196
} else {
171
197
processFile ( file , options ) ;
172
198
}
173
199
} ) ;
174
-
200
+
175
201
output = formatter . endFormat ( ) ;
176
202
if ( output ) {
177
203
api . print ( output ) ;
178
204
}
179
205
}
180
206
}
181
207
return exitCode ;
182
- }
183
-
184
-
208
+ }
209
+
210
+
185
211
function processArguments ( args , options ) {
186
212
var arg = args . shift ( ) ,
187
213
argName ,
188
214
parts ,
189
215
files = [ ] ;
190
-
216
+
191
217
while ( arg ) {
192
218
if ( arg . indexOf ( "--" ) === 0 ) {
193
219
argName = arg . substring ( 2 ) ;
194
220
options [ argName ] = true ;
195
-
221
+
196
222
if ( argName . indexOf ( "=" ) > - 1 ) {
197
223
parts = argName . split ( "=" ) ;
198
224
options [ parts [ 0 ] ] = parts [ 1 ] ;
@@ -201,7 +227,7 @@ function cli(api){
201
227
}
202
228
203
229
} else {
204
-
230
+
205
231
//see if it's a directory or a file
206
232
if ( api . isDirectory ( arg ) ) {
207
233
files = files . concat ( api . getFiles ( arg ) ) ;
@@ -211,24 +237,24 @@ function cli(api){
211
237
}
212
238
arg = args . shift ( ) ;
213
239
}
214
-
240
+
215
241
options . files = files ;
216
242
return options ;
217
243
}
218
-
244
+
219
245
function readConfigFile ( options ) {
220
246
var data = api . readFile ( api . getFullPath ( ".csslintrc" ) ) ;
221
- if ( data ) {
247
+ if ( data ) {
222
248
options = processArguments ( data . split ( / [ \s \n \r ] + / m) , options ) ;
223
249
api . print ( "ignore = " + options . ignore ) ;
224
250
api . print ( "errors = " + options . errors ) ;
225
251
api . print ( "warnings = " + options . warnings ) ;
226
252
}
227
-
253
+
228
254
return options ;
229
255
}
230
-
231
-
256
+
257
+
232
258
233
259
//-----------------------------------------------------------------------------
234
260
// Process command line
@@ -237,10 +263,10 @@ function cli(api){
237
263
var args = api . args ,
238
264
argCount = args . length ,
239
265
options = { } ;
240
-
266
+
241
267
// first look for config file .csslintrc
242
- options = readConfigFile ( options ) ;
243
-
268
+ options = readConfigFile ( options ) ;
269
+
244
270
// Command line arguments override config file
245
271
options = processArguments ( args , options ) ;
246
272
0 commit comments