Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
Fix for #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfitzer committed Nov 20, 2019
1 parent 2b663e9 commit 66f64dd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
38 changes: 38 additions & 0 deletions Commands/Show Debug Output.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string>#!/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
});</string>
<key>input</key>
<string>document</string>
<key>inputFormat</key>
<string>text</string>
<key>name</key>
<string>Show Debug Output</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>html</string>
<key>outputLocation</key>
<string>newWindow</string>
<key>uuid</key>
<string>96F87269-F5DE-480E-8314-9F64FDCDCE87</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>
46 changes: 21 additions & 25 deletions Support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let CLIEngine;
let SourceCode;
const bundleErrors = [];

function requireTry( modulePath ) {
function requireTry( modulePath, TMconfig ) {

let result;

Expand All @@ -45,23 +45,23 @@ function requireTry( modulePath ) {
}
catch ( err ) {

if ( TMdebug ) {
if ( TMconfig.TMdebug || TMdebug ) {
process.stdout.write( `${err}\n` );
}
}

return result;
}

function createCLI() {
function createCLI( TMconfig ) {

const options = {
fix: false,
useEslintrc: true,
cwd: TMcwd ? path.resolve( TMprojectDir, TMcwd ) : TMprojectDir
};

eslint = requireTry( eslintPath );
eslint = requireTry( eslintPath, TMconfig );

if ( eslint ) {
CLIEngine = eslint.CLIEngine;
Expand Down Expand Up @@ -100,19 +100,19 @@ function createCLI() {

if ( !CLIEngine ) return false;

if ( TMdebug ) {
if ( TMconfig.TMdebug || TMdebug ) {
process.stdout.write( `<h1>ESLint.tmbundle Debug</h1>` );
process.stdout.write( `<h2><code>$PATH</code></h2><pre>${process.env.PATH}</pre>` );
process.stdout.write( `<h2><code>CLIEngine Options</code></h2><pre>${JSON.stringify( options, null, 2 )}</pre>` );
process.stdout.write( `<h2><code>CLIEngine v${CLIEngine.version} options</code></h2><pre>${JSON.stringify( options, null, 2 )}</pre>` );
}

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,
Expand Down Expand Up @@ -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( `<h2><code>cli</code></h2><pre>${JSON.stringify( cli, null, 2 )}</pre>` );
}

if ( !cli ) {

bundleErrors.push( 'Error: No <code>CLIEngine</code> found.' );

if ( config.view === 'window' ) view.then( render );
if ( TMconfig.view === 'window' ) view.then( render );

return;
}
Expand All @@ -199,7 +195,7 @@ module.exports = function ( config ) {

bundleErrors.push( `Error: Path ignored: <code>${TMfilePath}</code>.` );

if ( config.view === 'window' ) view.then( render );
if ( TMconfig.view === 'window' ) view.then( render );

return;
}
Expand All @@ -226,21 +222,21 @@ module.exports = function ( config ) {

bundleErrors.push( 'Error: No ESLint configuration provided (<code>.eslintrc*</code>).' );

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( `<h2><code>data</code></h2><pre>${JSON.stringify( data, null, 2 )}</pre>` );
process.stdout.write( `<h2><code>Config: ${ data.filepathRel }</code></h2><pre>${JSON.stringify( cli.getConfigForFile( data.filepathRel ), null, 2 )}</pre>` );
if ( TMconfig.TMdebug || TMdebug ) {
process.stdout.write( `<h2>Report <code>data</code></h2><pre>${JSON.stringify( data, null, 2 )}</pre>` );
process.stdout.write( `<h2>Config for <code>${ data.filepathRel }</code></h2><pre>${JSON.stringify( cli.getConfigForFile( data.filepathRel ), null, 2 )}</pre>` );
}

if ( config.view === 'tooltip' && !data.errorCount ) return;
if ( TMconfig.view === 'tooltip' && !data.errorCount ) return;

view.then( render );

Expand Down

0 comments on commit 66f64dd

Please sign in to comment.