File tree Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Expand file tree Collapse file tree 2 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,11 @@ var loadConfigFile = require('jscs/lib/cli-config');
9
9
module . exports = function ( opts ) {
10
10
opts = opts || { } ;
11
11
12
+ var config ;
12
13
var checker = new Checker ( ) ;
13
14
14
- checker . registerDefaultRules ( ) ;
15
-
16
15
try {
17
- checker . configure ( loadConfigFile . load ( opts . configPath ) ) ;
16
+ config = loadConfigFile . load ( opts . configPath ) ;
18
17
} catch ( err ) {
19
18
err . message = 'Unable to load JSCS config file' ;
20
19
@@ -27,6 +26,14 @@ module.exports = function (opts) {
27
26
throw err ;
28
27
}
29
28
29
+ // run autofix over as many errors as possible
30
+ if ( opts . fix ) {
31
+ config . maxErrors = Infinity ;
32
+ }
33
+
34
+ checker . registerDefaultRules ( ) ;
35
+ checker . configure ( config ) ;
36
+
30
37
return through . obj ( function ( file , enc , cb ) {
31
38
if ( file . isNull ( ) ) {
32
39
cb ( null , file ) ;
Original file line number Diff line number Diff line change @@ -147,6 +147,43 @@ it('should accept the fix option', function (cb) {
147
147
stream . end ( ) ;
148
148
} ) ;
149
149
150
+ it ( 'should run autofix over as many errors as possible' , function ( done ) {
151
+ var config = {
152
+ maxErrors : 1 ,
153
+ requireSpaceBeforeBinaryOperators : [ '=' ]
154
+ } ;
155
+ var validJS = 'var foo =1;\nvar bar =2;' ;
156
+ var invalidJS = 'var foo=1;\nvar bar=2;' ;
157
+
158
+ var stream = jscs ( {
159
+ fix : true ,
160
+ configPath : tempWrite . sync ( JSON . stringify ( config ) )
161
+ } ) ;
162
+
163
+ stream
164
+ . pipe ( streamAssert . first ( function ( file ) {
165
+ assert . equal ( file . contents . toString ( ) , validJS ) ;
166
+ } ) )
167
+ . pipe ( streamAssert . second ( function ( file ) {
168
+ assert . equal ( file . contents . toString ( ) , validJS ) ;
169
+ } ) )
170
+ . pipe ( streamAssert . end ( done ) ) ;
171
+
172
+ stream . write ( new gutil . File ( {
173
+ base : __dirname ,
174
+ path : path . join ( __dirname , 'fixture.js' ) ,
175
+ contents : new Buffer ( invalidJS )
176
+ } ) ) ;
177
+
178
+ stream . write ( new gutil . File ( {
179
+ base : __dirname ,
180
+ path : path . join ( __dirname , 'fixture2.js' ) ,
181
+ contents : new Buffer ( invalidJS )
182
+ } ) ) ;
183
+
184
+ stream . end ( ) ;
185
+ } ) ;
186
+
150
187
it ( 'should not mutate the options object passed as argument' , function ( ) {
151
188
var options = { foo : true } ;
152
189
jscs ( options ) ;
You can’t perform that action at this time.
0 commit comments