@@ -75,6 +75,8 @@ const debug = require("debug")("eslint:cli-engine");
75
75
* @property {LintMessage[] } messages All of the messages for the result.
76
76
* @property {number } errorCount Number or errors for the result.
77
77
* @property {number } warningCount Number or warnings for the result.
78
+ * @property {string= } [source] The source code of the file that was linted.
79
+ * @property {string= } [output] The source code of the file that was linted, with as many fixes applied as possible.
78
80
*/
79
81
80
82
//------------------------------------------------------------------------------
@@ -150,10 +152,10 @@ function multipassFix(text, config, options) {
150
152
do {
151
153
passNumber ++ ;
152
154
153
- debug ( " Linting code for " + options . filename + " (pass " + passNumber + ")" ) ;
155
+ debug ( ` Linting code for ${ options . filename } (pass ${ passNumber } )` ) ;
154
156
messages = eslint . verify ( text , config , options ) ;
155
157
156
- debug ( " Generating fixed text for " + options . filename + " (pass " + passNumber + ")" ) ;
158
+ debug ( ` Generating fixed text for ${ options . filename } (pass ${ passNumber } )` ) ;
157
159
fixedResult = SourceCodeFixer . applyFixes ( eslint . getSourceCode ( ) , messages ) ;
158
160
159
161
// stop if there are any syntax errors.
@@ -175,7 +177,7 @@ function multipassFix(text, config, options) {
175
177
176
178
177
179
/*
178
- * If the last result had fixes, we need to lint again to me sure we have
180
+ * If the last result had fixes, we need to lint again to be sure we have
179
181
* the most up-to-date information.
180
182
*/
181
183
if ( fixedResult . fixed ) {
@@ -198,7 +200,7 @@ function multipassFix(text, config, options) {
198
200
* @param {string } filename An optional string representing the texts filename.
199
201
* @param {boolean } fix Indicates if fixes should be processed.
200
202
* @param {boolean } allowInlineConfig Allow/ignore comments that change config.
201
- * @returns {Result } The results for linting on this text.
203
+ * @returns {LintResult } The results for linting on this text.
202
204
* @private
203
205
*/
204
206
function processText ( text , configHelper , filename , fix , allowInlineConfig ) {
@@ -218,7 +220,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
218
220
}
219
221
220
222
filename = filename || "<text>" ;
221
- debug ( " Linting " + filename ) ;
223
+ debug ( ` Linting ${ filename } ` ) ;
222
224
const config = configHelper . getConfig ( filePath ) ;
223
225
224
226
if ( config . plugins ) {
@@ -279,6 +281,10 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
279
281
result . output = fixedResult . output ;
280
282
}
281
283
284
+ if ( result . errorCount + result . warningCount > 0 && typeof result . output === "undefined" ) {
285
+ result . source = text ;
286
+ }
287
+
282
288
return result ;
283
289
}
284
290
@@ -288,7 +294,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
288
294
* @param {string } filename The filename of the file being checked.
289
295
* @param {Object } configHelper The configuration options for ESLint.
290
296
* @param {Object } options The CLIEngine options object.
291
- * @returns {Result } The results for linting on this file.
297
+ * @returns {LintResult } The results for linting on this file.
292
298
* @private
293
299
*/
294
300
function processFile ( filename , configHelper , options ) {
@@ -304,7 +310,7 @@ function processFile(filename, configHelper, options) {
304
310
* Returns result with warning by ignore settings
305
311
* @param {string } filePath - File path of checked code
306
312
* @param {string } baseDir - Absolute path of base directory
307
- * @returns {Result } Result with single warning
313
+ * @returns {LintResult } Result with single warning
308
314
* @private
309
315
*/
310
316
function createIgnoreResult ( filePath , baseDir ) {
@@ -376,7 +382,7 @@ function getCacheFile(cacheFile, cwd) {
376
382
* @returns {string } the resolved path to the cacheFile
377
383
*/
378
384
function getCacheFileForDirectory ( ) {
379
- return path . join ( resolvedCacheFile , " .cache_" + hash ( cwd ) ) ;
385
+ return path . join ( resolvedCacheFile , ` .cache_${ hash ( cwd ) } ` ) ;
380
386
}
381
387
382
388
let fileStats ;
@@ -461,7 +467,7 @@ function CLIEngine(options) {
461
467
const cwd = this . options . cwd ;
462
468
463
469
this . options . rulePaths . forEach ( function ( rulesdir ) {
464
- debug ( " Loading rules from " + rulesdir ) ;
470
+ debug ( ` Loading rules from ${ rulesdir } ` ) ;
465
471
rules . load ( rulesdir , cwd ) ;
466
472
} ) ;
467
473
}
@@ -497,13 +503,13 @@ CLIEngine.getFormatter = function(format) {
497
503
498
504
formatterPath = path . resolve ( cwd , format ) ;
499
505
} else {
500
- formatterPath = " ./formatters/" + format ;
506
+ formatterPath = ` ./formatters/${ format } ` ;
501
507
}
502
508
503
509
try {
504
510
return require ( formatterPath ) ;
505
511
} catch ( ex ) {
506
- ex . message = " There was a problem loading formatter: " + formatterPath + " \nError: " + ex . message ;
512
+ ex . message = ` There was a problem loading formatter: ${ formatterPath } \nError: ${ ex . message } ` ;
507
513
throw ex ;
508
514
}
509
515
@@ -524,12 +530,13 @@ CLIEngine.getErrorResults = function(results) {
524
530
const filteredMessages = result . messages . filter ( isErrorMessage ) ;
525
531
526
532
if ( filteredMessages . length > 0 ) {
527
- filtered . push ( {
528
- filePath : result . filePath ,
529
- messages : filteredMessages ,
530
- errorCount : filteredMessages . length ,
531
- warningCount : 0
532
- } ) ;
533
+ filtered . push (
534
+ Object . assign ( result , {
535
+ messages : filteredMessages ,
536
+ errorCount : filteredMessages . length ,
537
+ warningCount : 0
538
+ } )
539
+ ) ;
533
540
}
534
541
} ) ;
535
542
@@ -608,7 +615,7 @@ CLIEngine.prototype = {
608
615
609
616
const eslintVersion = pkg . version ;
610
617
611
- prevConfig . hash = hash ( eslintVersion + "_" + stringify ( config ) ) ;
618
+ prevConfig . hash = hash ( ` ${ eslintVersion } _ ${ stringify ( config ) } ` ) ;
612
619
}
613
620
614
621
return prevConfig . hash ;
@@ -645,7 +652,7 @@ CLIEngine.prototype = {
645
652
const changed = descriptor . changed || meta . hashOfConfig !== hashOfConfig ;
646
653
647
654
if ( ! changed ) {
648
- debug ( " Skipping file since hasn't changed: " + filename ) ;
655
+ debug ( ` Skipping file since hasn't changed: ${ filename } ` ) ;
649
656
650
657
/*
651
658
* Add the the cached results (always will be 0 error and
@@ -662,7 +669,7 @@ CLIEngine.prototype = {
662
669
fileCache . destroy ( ) ;
663
670
}
664
671
665
- debug ( " Processing " + filename ) ;
672
+ debug ( ` Processing ${ filename } ` ) ;
666
673
667
674
const res = processFile ( filename , configHelper , options ) ;
668
675
@@ -674,7 +681,7 @@ CLIEngine.prototype = {
674
681
* next execution will also operate on this file
675
682
*/
676
683
if ( res . errorCount > 0 || res . warningCount > 0 ) {
677
- debug ( " File has problems, skipping it: " + filename ) ;
684
+ debug ( ` File has problems, skipping it: ${ filename } ` ) ;
678
685
679
686
// remove the entry from the cache
680
687
fileCache . removeEntry ( filename ) ;
@@ -713,7 +720,7 @@ CLIEngine.prototype = {
713
720
fileCache . reconcile ( ) ;
714
721
}
715
722
716
- debug ( " Linting complete in: " + ( Date . now ( ) - startTime ) + "ms" ) ;
723
+ debug ( ` Linting complete in: ${ Date . now ( ) - startTime } ms` ) ;
717
724
718
725
return {
719
726
results,
0 commit comments