Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Added -p option to jslint command allowing results to be printed to s…
Browse files Browse the repository at this point in the history
…tdout
  • Loading branch information
mridgway committed Jun 10, 2012
1 parent 6effc8d commit 726a2e4
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions source/lib/management/commands/jslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
var fs = require('fs'),
path = require('path'),
utils = require('../utils'),
usage = 'mojito jslint [app | mojit] [<name>]';
usage = 'mojito jslint [app | mojit] [<name>]',
options = [
{
shortName: 'p',
longName: 'print',
hasValue: false
}
];


// ---------- Generic file system utilities ----------
Expand Down Expand Up @@ -122,6 +129,23 @@ function OutputFile(filename) {
}


/*
* A very simple class to allow writes to stdout.
*/
function OutputStdout(filename) {
var printedName = false;

this.write = function(s) {
if (!printedName) {
printedName = true;
process.stdout.write(filename + '\n');
}
process.stdout.write(s);
};
this.done = function() {};
}


// ---------- JSLint processing ----------


Expand Down Expand Up @@ -325,14 +349,24 @@ function processFiles(inDir, outDir, excludeMatcher) {
rowdata = [];

inDir = path.normalize(inDir);
outDir = path.normalize(outDir);
if (outDir) {
outDir = path.normalize(outDir);
}

processDir(inDir,
function(f) {
var relname = f.replace(inDir, '').replace(/^\//, ''),
outname = relname.replace(/\.js$/, '.txt'),
out = new OutputFile(path.join(outDir, outname)),
errors = lintOneFile(f, out);
out,
errors;

if (!outDir) {
out = new OutputStdout(relname);
} else {
out = new OutputFile(path.join(outDir, outname))
}

errors = lintOneFile(f, out);

if (errors > 0) {
rowdata.push({count: errors, text: relname, url: outname});
Expand All @@ -351,7 +385,7 @@ function processFiles(inDir, outDir, excludeMatcher) {
(s.isDirectory() || /\.js$/.test(p));
});

if (totalErrors > 0) {
if (outDir && totalErrors > 0) {
writePage(outDir, rowdata, totalErrors);
}

Expand All @@ -369,7 +403,8 @@ function run(params, options) {
inDir,
outDir,
failures,
errors;
errors,
print = options && options.print;

// Process params to determine input and output locations.
if (!params || params.length === 0) {
Expand Down Expand Up @@ -429,9 +464,14 @@ function run(params, options) {
});
}

// Set outDir to null if we just plan on printing to stdout
if (print) {
outDir = null;
}

// Process the files with JSLint.
errors = processFiles(inDir, outDir, utils.getExclusionMatcher(excludes));
if (errors) {
if (!print && errors) {
console.log('Lint report: ' + path.normalize(outDir));
}
process.stdout.write(errors + ' errors found.\n', 'utf8',
Expand All @@ -452,6 +492,12 @@ function run(params, options) {
exports.usage = usage;


/**
* Standard options export.
*/
exports.options = options;


/**
* Standard run method hook export.
*/
Expand Down

0 comments on commit 726a2e4

Please sign in to comment.