Skip to content

Commit

Permalink
refactor to allow --link flag to create symlinked config file; issue
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasmalik committed Nov 5, 2016
1 parent 0779014 commit 3b00f86
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
'use strict';

var exec = require('child_process').exec;
var path = require('path');
var eslint = require('eslint');
var parse = require('minimist');
Expand All @@ -11,21 +12,50 @@ var cli, report;
var args = parse(process.argv.slice(2));
var dir = args._.slice(0, 1);

var shouldFix = args.hasOwnProperty('fix');
/*
* Symlinks the eslintrc file into the dependent project's root
*/
function createSymLink () {
var fullpath = path.resolve(dir[0]);

exec(
'ln -sf ' + configFilePath + ' ' + path.join(fullpath, '.eslintrc.js'),
function (err) {
if (err) {
console.error('Error encountered when trying to create symlink', err); // eslint-disable-line
}

console.log('Successfully symlinked .eslintrc.js to ' + fullpath); // eslint-disable-line
}
);
}

cli = new eslint.CLIEngine({ configFile: configFilePath, fix: shouldFix });
/*
* Lints the directory passed in as a command line argument
*/
function lintDirectory () {
var shouldFix = args.hasOwnProperty('fix');

report = cli.executeOnFiles(dir);
cli = new eslint.CLIEngine({ configFile: configFilePath, fix: shouldFix });

if (shouldFix) {
eslint.CLIEngine.outputFixes(report);
}
report = cli.executeOnFiles(dir);

if (shouldFix) {
eslint.CLIEngine.outputFixes(report);
}

console.log(cli.getFormatter()(report.results)); // eslint-disable-line
console.log(cli.getFormatter()(report.results)); // eslint-disable-line

// End with exit code 1 if there are errors
// Use process.exit instead of throwing to mimic the behaviour of eslints bin
// We don't want a stacktrace, it would just be confusing
if (report.errorCount) {
process.exit(1); // eslint-disable-line
}
}

// End with exit code 1 if there are errors
// Use process.exit instead of throwing to mimic the behaviour of eslints bin
// We don't want a stacktrace, it would just be confusing
if (report.errorCount) {
process.exit(1); // eslint-disable-line
if (args.hasOwnProperty('link')) {
createSymLink();
} else {
lintDirectory();
}

0 comments on commit 3b00f86

Please sign in to comment.