From df2d9f021c0cb0ad81e46c3a996059d22474d6e4 Mon Sep 17 00:00:00 2001 From: NickCrews Date: Tue, 2 Mar 2021 20:38:56 -0700 Subject: [PATCH] Improve lint() logic, https://github.com/phetsims/phet-info/issues/150 Only format the results if we actually are going to print them --- js/grunt/lint.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/js/grunt/lint.js b/js/grunt/lint.js index 7bff4dd2..dbc36157 100644 --- a/js/grunt/lint.js +++ b/js/grunt/lint.js @@ -91,17 +91,14 @@ const lint = async ( patterns, options ) => { await ESLint.outputFixes( results ); } - // 4. Format the results. - const formatter = await eslint.loadFormatter( 'stylish' ); - const resultText = formatter.format( results ); - + // 4. Parse the results. const totalWarnings = _.sum( results.map( result => result.warningCount ) ); const totalErrors = _.sum( results.map( result => result.errorCount ) ); - const total = totalWarnings + totalErrors; - - // 5. Output it. - if ( total > 0 ) { + // 5. Output results on errors. + if ( totalWarnings + totalErrors > 0 ) { + const formatter = await eslint.loadFormatter( 'stylish' ); + const resultText = formatter.format( results ); console.log( resultText ); options.warn && grunt.fail.warn( `${totalErrors} errors and ${totalWarnings} warnings` ); }