@@ -75,6 +75,8 @@ const debug = require("debug")("eslint:cli-engine");
7575 * @property {LintMessage[] } messages All of the messages for the result.
7676 * @property {number } errorCount Number or errors for the result.
7777 * @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.
7880 */
7981
8082//------------------------------------------------------------------------------
@@ -150,10 +152,10 @@ function multipassFix(text, config, options) {
150152 do {
151153 passNumber ++ ;
152154
153- debug ( " Linting code for " + options . filename + " (pass " + passNumber + ")" ) ;
155+ debug ( ` Linting code for ${ options . filename } (pass ${ passNumber } )` ) ;
154156 messages = eslint . verify ( text , config , options ) ;
155157
156- debug ( " Generating fixed text for " + options . filename + " (pass " + passNumber + ")" ) ;
158+ debug ( ` Generating fixed text for ${ options . filename } (pass ${ passNumber } )` ) ;
157159 fixedResult = SourceCodeFixer . applyFixes ( eslint . getSourceCode ( ) , messages ) ;
158160
159161 // stop if there are any syntax errors.
@@ -175,7 +177,7 @@ function multipassFix(text, config, options) {
175177
176178
177179 /*
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
179181 * the most up-to-date information.
180182 */
181183 if ( fixedResult . fixed ) {
@@ -198,7 +200,7 @@ function multipassFix(text, config, options) {
198200 * @param {string } filename An optional string representing the texts filename.
199201 * @param {boolean } fix Indicates if fixes should be processed.
200202 * @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.
202204 * @private
203205 */
204206function processText ( text , configHelper , filename , fix , allowInlineConfig ) {
@@ -218,7 +220,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
218220 }
219221
220222 filename = filename || "<text>" ;
221- debug ( " Linting " + filename ) ;
223+ debug ( ` Linting ${ filename } ` ) ;
222224 const config = configHelper . getConfig ( filePath ) ;
223225
224226 if ( config . plugins ) {
@@ -279,6 +281,10 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
279281 result . output = fixedResult . output ;
280282 }
281283
284+ if ( result . errorCount + result . warningCount > 0 && typeof result . output === "undefined" ) {
285+ result . source = text ;
286+ }
287+
282288 return result ;
283289}
284290
@@ -288,7 +294,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
288294 * @param {string } filename The filename of the file being checked.
289295 * @param {Object } configHelper The configuration options for ESLint.
290296 * @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.
292298 * @private
293299 */
294300function processFile ( filename , configHelper , options ) {
@@ -304,7 +310,7 @@ function processFile(filename, configHelper, options) {
304310 * Returns result with warning by ignore settings
305311 * @param {string } filePath - File path of checked code
306312 * @param {string } baseDir - Absolute path of base directory
307- * @returns {Result } Result with single warning
313+ * @returns {LintResult } Result with single warning
308314 * @private
309315 */
310316function createIgnoreResult ( filePath , baseDir ) {
@@ -376,7 +382,7 @@ function getCacheFile(cacheFile, cwd) {
376382 * @returns {string } the resolved path to the cacheFile
377383 */
378384 function getCacheFileForDirectory ( ) {
379- return path . join ( resolvedCacheFile , " .cache_" + hash ( cwd ) ) ;
385+ return path . join ( resolvedCacheFile , ` .cache_${ hash ( cwd ) } ` ) ;
380386 }
381387
382388 let fileStats ;
@@ -461,7 +467,7 @@ function CLIEngine(options) {
461467 const cwd = this . options . cwd ;
462468
463469 this . options . rulePaths . forEach ( function ( rulesdir ) {
464- debug ( " Loading rules from " + rulesdir ) ;
470+ debug ( ` Loading rules from ${ rulesdir } ` ) ;
465471 rules . load ( rulesdir , cwd ) ;
466472 } ) ;
467473 }
@@ -497,13 +503,13 @@ CLIEngine.getFormatter = function(format) {
497503
498504 formatterPath = path . resolve ( cwd , format ) ;
499505 } else {
500- formatterPath = " ./formatters/" + format ;
506+ formatterPath = ` ./formatters/${ format } ` ;
501507 }
502508
503509 try {
504510 return require ( formatterPath ) ;
505511 } 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 } ` ;
507513 throw ex ;
508514 }
509515
@@ -524,12 +530,13 @@ CLIEngine.getErrorResults = function(results) {
524530 const filteredMessages = result . messages . filter ( isErrorMessage ) ;
525531
526532 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+ ) ;
533540 }
534541 } ) ;
535542
@@ -608,7 +615,7 @@ CLIEngine.prototype = {
608615
609616 const eslintVersion = pkg . version ;
610617
611- prevConfig . hash = hash ( eslintVersion + "_" + stringify ( config ) ) ;
618+ prevConfig . hash = hash ( ` ${ eslintVersion } _ ${ stringify ( config ) } ` ) ;
612619 }
613620
614621 return prevConfig . hash ;
@@ -645,7 +652,7 @@ CLIEngine.prototype = {
645652 const changed = descriptor . changed || meta . hashOfConfig !== hashOfConfig ;
646653
647654 if ( ! changed ) {
648- debug ( " Skipping file since hasn't changed: " + filename ) ;
655+ debug ( ` Skipping file since hasn't changed: ${ filename } ` ) ;
649656
650657 /*
651658 * Add the the cached results (always will be 0 error and
@@ -662,7 +669,7 @@ CLIEngine.prototype = {
662669 fileCache . destroy ( ) ;
663670 }
664671
665- debug ( " Processing " + filename ) ;
672+ debug ( ` Processing ${ filename } ` ) ;
666673
667674 const res = processFile ( filename , configHelper , options ) ;
668675
@@ -674,7 +681,7 @@ CLIEngine.prototype = {
674681 * next execution will also operate on this file
675682 */
676683 if ( res . errorCount > 0 || res . warningCount > 0 ) {
677- debug ( " File has problems, skipping it: " + filename ) ;
684+ debug ( ` File has problems, skipping it: ${ filename } ` ) ;
678685
679686 // remove the entry from the cache
680687 fileCache . removeEntry ( filename ) ;
@@ -713,7 +720,7 @@ CLIEngine.prototype = {
713720 fileCache . reconcile ( ) ;
714721 }
715722
716- debug ( " Linting complete in: " + ( Date . now ( ) - startTime ) + "ms" ) ;
723+ debug ( ` Linting complete in: ${ Date . now ( ) - startTime } ms` ) ;
717724
718725 return {
719726 results,
0 commit comments