Skip to content

Commit

Permalink
new linting setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jun 3, 2014
1 parent 9aa5c45 commit 9e1f93c
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 52 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
14 changes: 13 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"freeze": true,
"indent": 2,
"newcap": false,
"quotmark": "single",
"maxdepth": 3,
"maxstatements": 50,
"maxlen": 80,
"eqnull": true,
"funcscope": true,
"strict": true,
"undef": true,
"unused": true,
"node": true,
"mocha": true
}
}
78 changes: 53 additions & 25 deletions bin/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ var simpleTasksFlag = argv['tasks-simple'];
var shouldLog = !argv.silent && !simpleTasksFlag;

// wire up a few err listeners to liftoff
cli.on('require', function(name) {
if (!shouldLog) return;
cli.on('require', function (name) {
if (!shouldLog) {
return;
}
gutil.log('Requiring external module', chalk.magenta(name));
});

cli.on('requireFail', function(name) {
cli.on('requireFail', function (name) {
gutil.log(chalk.red('Failed to load external module'), chalk.magenta(name));
});

Expand All @@ -59,7 +61,10 @@ function handleArguments(env) {
}

if (!env.modulePath) {
gutil.log(chalk.red('No local gulp install found in'), chalk.magenta(tildify(env.cwd)));
gutil.log(
chalk.red('Local gulp not found in'),
chalk.magenta(tildify(env.cwd))
);
gutil.log(chalk.red('Try running: npm install gulp'));
process.exit(1);
}
Expand All @@ -72,16 +77,19 @@ function handleArguments(env) {
// check for semver difference between cli and local installation
if (semver.gt(cliPackage.version, env.modulePackage.version) && shouldLog) {
gutil.log(chalk.red('Warning: gulp version mismatch:'));
gutil.log(chalk.red('Running gulp is', cliPackage.version));
gutil.log(chalk.red('Local gulp (installed in gulpfile dir) is', env.modulePackage.version));
gutil.log(chalk.red('Global gulp is', cliPackage.version));
gutil.log(chalk.red('Local gulp is', env.modulePackage.version));
}

// chdir before requiring gulpfile to make sure
// we let them chdir as needed
if (process.cwd() !== env.cwd) {
process.chdir(env.cwd);
if (shouldLog) {
gutil.log('Working directory changed to', chalk.magenta(tildify(env.cwd)));
gutil.log(
'Working directory changed to',
chalk.magenta(tildify(env.cwd))
);
}
}

Expand All @@ -95,7 +103,7 @@ function handleArguments(env) {
var gulpInst = require(env.modulePath);
logEvents(gulpInst);

process.nextTick(function() {
process.nextTick(function () {
if (simpleTasksFlag) {
return logTasksSimple(env, gulpInst);
}
Expand All @@ -109,49 +117,69 @@ function handleArguments(env) {
function logTasks(env, localGulp) {
var tree = taskTree(localGulp.tasks);
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
archy(tree).split('\n').forEach(function(v) {
if (v.trim().length === 0) return;
gutil.log(v);
});
archy(tree)
.split('\n')
.forEach(function (v) {
if (v.trim().length === 0) {
return;
}
gutil.log(v);
});
}

function logTasksSimple(env, localGulp) {
console.log(Object.keys(localGulp.tasks).join('\n').trim());
console.log(Object.keys(localGulp.tasks)
.join('\n')
.trim());
}

// format orchestrator errors
function formatError(e) {
if (!e.err) return e.message;
if (e.err.message) return e.err.message;
if (!e.err) {
return e.message;
}
if (e.err.message) {
return e.err.message;
}
return JSON.stringify(e.err);
}

// wire up logging events
function logEvents(gulpInst) {

// total hack due to fucked up error management in orchestrator
gulpInst.on('err', function(){});
gulpInst.on('err', function () {});

gulpInst.on('task_start', function(e) {
gulpInst.on('task_start', function (e) {
// TODO: batch these
// so when 5 tasks start at once it only logs one time with all 5
gutil.log('Starting', "'" + chalk.cyan(e.task) + "'...");
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
});

gulpInst.on('task_stop', function(e) {
gulpInst.on('task_stop', function (e) {
var time = prettyTime(e.hrDuration);
gutil.log('Finished', "'" + chalk.cyan(e.task) + "'", 'after', chalk.magenta(time));
gutil.log(
'Finished', '\'' + chalk.cyan(e.task) + '\'',
'after', chalk.magenta(time)
);
});

gulpInst.on('task_err', function(e) {
gulpInst.on('task_err', function (e) {
var msg = formatError(e);
var time = prettyTime(e.hrDuration);
gutil.log("'" + chalk.cyan(e.task) + "'", 'errored after', chalk.magenta(time), chalk.red(msg));
gutil.log(
'\'' + chalk.cyan(e.task) + '\'',
'errored after',
chalk.magenta(time),
chalk.red(msg)
);
});

gulpInst.on('task_not_found', function(err) {
gutil.log(chalk.red("Task '" + err.task + "' was not defined in your gulpfile but you tried to run it."));
gutil.log('Please check the documentation for proper gulpfile formatting.');
gulpInst.on('task_not_found', function (err) {
gutil.log(
chalk.red('Task \'' + err.task + '\' is not in your gulpfile')
);
gutil.log('Please check the documentation for proper gulpfile formatting');
process.exit(1);
});
}
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Gulp() {
util.inherits(Gulp, Orchestrator);

Gulp.prototype.task = Gulp.prototype.add;
Gulp.prototype.run = function() {
Gulp.prototype.run = function () {
// run() is deprecated as of 3.5 and will be removed in 4.0
// use task dependencies instead

Expand All @@ -24,15 +24,15 @@ Gulp.prototype.run = function() {

Gulp.prototype.src = vfs.src;
Gulp.prototype.dest = vfs.dest;
Gulp.prototype.watch = function(glob, opt, fn) {
Gulp.prototype.watch = function (glob, opt, fn) {
if (typeof opt === 'function' || Array.isArray(opt)) {
fn = opt;
opt = null;
}

// array of tasks given
if (Array.isArray(fn)) {
return vfs.watch(glob, opt, function() {
return vfs.watch(glob, opt, function () {
this.start.apply(this, fn);
}.bind(this));
}
Expand All @@ -44,8 +44,20 @@ Gulp.prototype.watch = function(glob, opt, fn) {
Gulp.prototype.Gulp = Gulp;

// deprecations
deprecated.field('gulp.env has been deprecated. Use your own CLI parser instead. We recommend using yargs or minimist.', console.warn, Gulp.prototype, 'env', gutil.env);
Gulp.prototype.run = deprecated.method('gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.', console.warn, Gulp.prototype.run);
deprecated.field('gulp.env has been deprecated. ' +
'Use your own CLI parser instead. ' +
'We recommend using yargs or minimist.',
console.warn,
Gulp.prototype,
'env',
gutil.env
);

Gulp.prototype.run = deprecated.method('gulp.run() has been deprecated. ' +
'Use task dependencies or gulp.watch task triggering instead.',
console.warn,
Gulp.prototype.run
);

var inst = new Gulp();
module.exports = inst;
18 changes: 12 additions & 6 deletions lib/completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
var fs = require('fs');
var path = require('path');

module.exports = function(name) {
if (typeof name !== 'string') throw new Error('Missing completion type');
module.exports = function (name) {
if (typeof name !== 'string') {
throw new Error('Missing completion type');
}
var file = path.join(__dirname, '../completion', name);
try {
console.log(fs.readFileSync(file, 'utf8'));
process.exit(0);
console.log(fs.readFileSync(file, 'utf8'));
process.exit(0);
} catch (err) {
console.log('echo "Specified gulp shell auto-completion rules for \''+name+'\' not found"');
process.exit(5);
console.log(
'echo "gulp autocompletion rules for',
'\'' + name + '\'',
'not found"'
);
process.exit(5);
}
};
17 changes: 10 additions & 7 deletions lib/taskTree.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
'use strict';

module.exports = function(tasks) {
return Object.keys(tasks).reduce(function(prev, task) {
prev.nodes.push({
label: task,
nodes: tasks[task].dep
module.exports = function (tasks) {
return Object.keys(tasks)
.reduce(function (prev, task) {
prev.nodes.push({
label: task,
nodes: tasks[task].dep
});
return prev;
}, {
nodes: []
});
return prev;
}, {nodes: []});
};
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@
"vinyl-fs": "^0.2.0"
},
"devDependencies": {
"mocha": "^1.17.0",
"mocha-lcov-reporter": "^0.0.1",
"coveralls": "^2.7.0",
"graceful-fs": "^3.0.0",
"istanbul": "^0.2.3",
"should": "^4.0.0",
"rimraf": "^2.2.5",
"q": "^1.0.0",
"jshint": "^2.5.0",
"graceful-fs": "^3.0.0",
"mkdirp": "^0.5.0"
"jshint-stylish": "^0.2.0",
"mkdirp": "^0.5.0",
"mocha": "^1.17.0",
"mocha-lcov-reporter": "^0.0.1",
"q": "^1.0.0",
"rimraf": "^2.2.5",
"should": "^4.0.0"
},
"scripts": {
"test": "jshint --exclude node_modules . && mocha --reporter spec",
"lint": "jshint lib bin index.js --reporter node_modules/jshint-stylish/stylish.js --exclude node_modules",
"test": "npm run-script lint && mocha --reporter spec",
"coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage"
},
"engineStrict": true,
Expand Down

0 comments on commit 9e1f93c

Please sign in to comment.