From 66f64dd86b11db348c3063ed735d5bf8db07cd1c Mon Sep 17 00:00:00 2001 From: Ryan Fitzer Date: Tue, 19 Nov 2019 16:28:14 -0800 Subject: [PATCH] Fix for #5. --- Commands/Show Debug Output.tmCommand | 38 +++++++++++++++++++++++ Support/index.js | 46 +++++++++++++--------------- 2 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 Commands/Show Debug Output.tmCommand diff --git a/Commands/Show Debug Output.tmCommand b/Commands/Show Debug Output.tmCommand new file mode 100644 index 0000000..16418f0 --- /dev/null +++ b/Commands/Show Debug Output.tmCommand @@ -0,0 +1,38 @@ + + + + + beforeRunningCommand + saveActiveFile + command + #!/usr/bin/env node + +const hrstart = process.hrtime(); +const bundle = require( process.env.TM_BUNDLE_SUPPORT ); +const TMdisable = /true/i.test( process.env.TM_eslint_disable_on_save ); + +if ( TMdisable ) return; + +bundle({ + view: 'window', + hrstart: hrstart, + TMdebug: true +}); + input + document + inputFormat + text + name + Show Debug Output + outputCaret + afterOutput + outputFormat + html + outputLocation + newWindow + uuid + 96F87269-F5DE-480E-8314-9F64FDCDCE87 + version + 2 + + diff --git a/Support/index.js b/Support/index.js index 90ee5e2..ee9ece8 100644 --- a/Support/index.js +++ b/Support/index.js @@ -36,7 +36,7 @@ let CLIEngine; let SourceCode; const bundleErrors = []; -function requireTry( modulePath ) { +function requireTry( modulePath, TMconfig ) { let result; @@ -45,7 +45,7 @@ function requireTry( modulePath ) { } catch ( err ) { - if ( TMdebug ) { + if ( TMconfig.TMdebug || TMdebug ) { process.stdout.write( `${err}\n` ); } } @@ -53,7 +53,7 @@ function requireTry( modulePath ) { return result; } -function createCLI() { +function createCLI( TMconfig ) { const options = { fix: false, @@ -61,7 +61,7 @@ function createCLI() { cwd: TMcwd ? path.resolve( TMprojectDir, TMcwd ) : TMprojectDir }; - eslint = requireTry( eslintPath ); + eslint = requireTry( eslintPath, TMconfig ); if ( eslint ) { CLIEngine = eslint.CLIEngine; @@ -100,19 +100,19 @@ function createCLI() { if ( !CLIEngine ) return false; - if ( TMdebug ) { + if ( TMconfig.TMdebug || TMdebug ) { process.stdout.write( `

ESLint.tmbundle Debug

` ); process.stdout.write( `

$PATH

${process.env.PATH}
` ); - process.stdout.write( `

CLIEngine Options

${JSON.stringify( options, null, 2 )}
` ); + process.stdout.write( `

CLIEngine v${CLIEngine.version} options

${JSON.stringify( options, null, 2 )}
` ); } return new CLIEngine( options ); } -function composeData( report ) { +function composeData( report, TMconfig ) { const hasReport = Object.keys( report || {} ).length; - const eslintPkg = requireTry( `${eslintPath}/package.json` ); + const eslintPkg = requireTry( `${eslintPath}/package.json`, TMconfig ); const result = { file: path.parse( TMfilePath ).base, filepathAbs: TMfilePath, @@ -163,34 +163,30 @@ function composeData( report ) { return result; } -module.exports = function ( config ) { +module.exports = function ( TMconfig ) { let data; let report = null; - const cli = createCLI(); - const view = fsp.readFile( `${viewsPath}/${config.view}.hbs` ); + const cli = createCLI( TMconfig ); + const view = fsp.readFile( `${viewsPath}/${TMconfig.view}.hbs` ); const render = function( src ) { const template = handlebars.compile( src ); - const hrend = process.hrtime( config.hrstart ); + const hrend = process.hrtime( TMconfig.hrstart ); - data = data || composeData(); + data = data || composeData( null, TMconfig ); data.time = `${hrend[0]}s ${Math.floor( hrend[1]/1000000 )}ms`; return process.stdout.write( template( data ) ); } - if ( TMdebug ) { - process.stdout.write( `

cli

${JSON.stringify( cli, null, 2 )}
` ); - } - if ( !cli ) { bundleErrors.push( 'Error: No CLIEngine found.' ); - if ( config.view === 'window' ) view.then( render ); + if ( TMconfig.view === 'window' ) view.then( render ); return; } @@ -199,7 +195,7 @@ module.exports = function ( config ) { bundleErrors.push( `Error: Path ignored: ${TMfilePath}.` ); - if ( config.view === 'window' ) view.then( render ); + if ( TMconfig.view === 'window' ) view.then( render ); return; } @@ -226,21 +222,21 @@ module.exports = function ( config ) { bundleErrors.push( 'Error: No ESLint configuration provided (.eslintrc*).' ); - if ( config.view === 'window' ) view.then( render ); + if ( TMconfig.view === 'window' ) view.then( render ); return; } CLIEngine.outputFixes( report ); - data = composeData( report ); + data = composeData( report, TMconfig ); - if ( TMdebug ) { - process.stdout.write( `

data

${JSON.stringify( data, null, 2 )}
` ); - process.stdout.write( `

Config: ${ data.filepathRel }

${JSON.stringify( cli.getConfigForFile( data.filepathRel ), null, 2 )}
` ); + if ( TMconfig.TMdebug || TMdebug ) { + process.stdout.write( `

Report data

${JSON.stringify( data, null, 2 )}
` ); + process.stdout.write( `

Config for ${ data.filepathRel }

${JSON.stringify( cli.getConfigForFile( data.filepathRel ), null, 2 )}
` ); } - if ( config.view === 'tooltip' && !data.errorCount ) return; + if ( TMconfig.view === 'tooltip' && !data.errorCount ) return; view.then( render );