@@ -78,7 +78,9 @@ describe("formatter:codeframe", () => {
78
78
ruleId : "foo"
79
79
} ] ,
80
80
errorCount : 0 ,
81
- warningCount : 1
81
+ warningCount : 1 ,
82
+ fixableErrorCount : 0 ,
83
+ fixableWarningCount : 0
82
84
} ] ;
83
85
84
86
it ( "should return a string in the correct format for warnings" , ( ) => {
@@ -104,6 +106,27 @@ describe("formatter:codeframe", () => {
104
106
assert . equal ( chalkStub . yellow . bold . callCount , 1 ) ;
105
107
assert . equal ( chalkStub . red . bold . callCount , 0 ) ;
106
108
} ) ;
109
+
110
+ describe ( "when the warning is fixable" , ( ) => {
111
+ beforeEach ( ( ) => {
112
+ code [ 0 ] . fixableWarningCount = 1 ;
113
+ } ) ;
114
+
115
+ it ( "should return a string in the correct format" , ( ) => {
116
+ const result = formatter ( code ) ;
117
+
118
+ assert . equal ( chalk . stripColor ( result ) , [
119
+ `warning: Unexpected foo (foo) at ${ path . join ( "lib" , "foo.js" ) } :1:5:` ,
120
+ "> 1 | var foo = 1;" ,
121
+ " | ^" ,
122
+ " 2 | var bar = 2;" ,
123
+ " 3 | " ,
124
+ "\n" ,
125
+ "1 warning found." ,
126
+ "1 warning potentially fixable with the `--fix` option."
127
+ ] . join ( "\n" ) ) ;
128
+ } ) ;
129
+ } ) ;
107
130
} ) ;
108
131
109
132
describe ( "when passed a single error message" , ( ) => {
@@ -353,4 +376,93 @@ describe("formatter:codeframe", () => {
353
376
assert . equal ( chalk . stripColor ( result ) , "error: Unexpected foo (foo) at foo.js\n\n\n1 error found." ) ;
354
377
} ) ;
355
378
} ) ;
379
+
380
+
381
+ describe ( "fixable problems" , ( ) => {
382
+ it ( "should not output fixable problems message when no errors or warnings are fixable" , ( ) => {
383
+ const code = [ {
384
+ filePath : "foo.js" ,
385
+ errorCount : 1 ,
386
+ warningCount : 0 ,
387
+ fixableErrorCount : 0 ,
388
+ fixableWarningCount : 0 ,
389
+ messages : [ {
390
+ message : "Unexpected foo." ,
391
+ severity : 2 ,
392
+ line : 5 ,
393
+ column : 10 ,
394
+ ruleId : "foo"
395
+ } ]
396
+ } ] ;
397
+
398
+ const result = formatter ( code ) ;
399
+
400
+ assert . notInclude ( result , "potentially fixable" ) ;
401
+ } ) ;
402
+
403
+ it ( "should output the fixable problems message when errors are fixable" , ( ) => {
404
+ const code = [ {
405
+ filePath : "foo.js" ,
406
+ errorCount : 1 ,
407
+ warningCount : 0 ,
408
+ fixableErrorCount : 1 ,
409
+ fixableWarningCount : 0 ,
410
+ messages : [ {
411
+ message : "Unexpected foo." ,
412
+ severity : 2 ,
413
+ line : 5 ,
414
+ column : 10 ,
415
+ ruleId : "foo"
416
+ } ]
417
+ } ] ;
418
+
419
+ const result = formatter ( code ) ;
420
+
421
+ assert . include ( result , "1 error potentially fixable with the `--fix` option." ) ;
422
+ } ) ;
423
+
424
+ it ( "should output fixable problems message when warnings are fixable" , ( ) => {
425
+ const code = [ {
426
+ filePath : "foo.js" ,
427
+ errorCount : 0 ,
428
+ warningCount : 3 ,
429
+ fixableErrorCount : 0 ,
430
+ fixableWarningCount : 2 ,
431
+ messages : [ {
432
+ message : "Unexpected foo."
433
+ } ]
434
+ } ] ;
435
+
436
+ const result = formatter ( code ) ;
437
+
438
+ assert . include ( result , "2 warnings potentially fixable with the `--fix` option." ) ;
439
+ } ) ;
440
+
441
+ it ( "should output the total number of fixable errors and warnings" , ( ) => {
442
+ const code = [ {
443
+ filePath : "foo.js" ,
444
+ errorCount : 5 ,
445
+ warningCount : 3 ,
446
+ fixableErrorCount : 5 ,
447
+ fixableWarningCount : 2 ,
448
+ messages : [ {
449
+ message : "Unexpected foo."
450
+ } ]
451
+ } , {
452
+ filePath : "bar.js" ,
453
+ errorCount : 4 ,
454
+ warningCount : 2 ,
455
+ fixableErrorCount : 4 ,
456
+ fixableWarningCount : 1 ,
457
+ messages : [ {
458
+ message : "Unexpected bar."
459
+ } ]
460
+ } ] ;
461
+
462
+ const result = formatter ( code ) ;
463
+
464
+ assert . include ( result , "9 errors and 3 warnings potentially fixable with the `--fix` option." ) ;
465
+ } ) ;
466
+ } ) ;
467
+
356
468
} ) ;
0 commit comments