Permalink
Browse files

Make the CLI code pass JSHint

Also add a notice about pull request contribution guidelines
  • Loading branch information...
1 parent 5e574a4 commit b9fe2e543991249e13b22cc8e2e5b71a26eb232a @sindresorhus sindresorhus committed Jul 25, 2012
View
@@ -9,7 +9,6 @@ module.exports = function( grunt ) {
options: {
options: {
node: true,
- browser: true,
es5 : true,
esnext: true,
bitwise: true,
@@ -21,7 +20,7 @@ module.exports = function( grunt ) {
noarg: true,
//regexp: true,
undef: true,
- //strict: true,
+ strict: false,
trailing: true,
smarttabs: true
},
@@ -34,10 +33,10 @@ module.exports = function( grunt ) {
'tasks/*.js'
],
lib: [
- 'lib/**/*.js'
+ 'lib/{plugins,utils}/*.js',
],
test: [
- 'test/**/*.js'
+ //'test/**/*.js'
]
},
watch: {
View
@@ -1,12 +1,15 @@
-
var fs = require('fs'),
path = require('path');
var plugins = module.exports;
fs.readdirSync(path.join(__dirname)).forEach(function(file) {
var plugin = file.replace(path.extname(file), '');
- if(plugin === 'index' || path.extname(file) !== '.js') return;
+
+ if ( plugin === 'index' || path.extname( file ) !== '.js' ) {
+ return;
+ }
+
plugins.__defineGetter__(plugin, function() {
return require('./' + plugin);
});
View
@@ -18,22 +18,24 @@ module.exports = {
var insightRecordCmd = [join(insightFolder, 'yeomaninsight.py'), 'record'];
// Record this action in Insight (e.g. python yeomaninsight.py record cmd cmd2).
- var insight = spawn('python', insightRecordCmd.concat(opts.cmds));
+ spawn('python', insightRecordCmd.concat(opts.cmds));
//insight.stdout.pipe(process.stdout);
fs.stat(join(insightFolder, '.log'), function(err, stats) {
// Error means file doesn't exist and this is the first run.
// Go through stat opt-in flow.
- if (!err) return opts.cb();
+ if ( !err ) {
+ return opts.cb();
+ }
+/*jshint multistr:true */
var msg = "\
==========================================================================".grey + "\n\
We're constantly looking for ways to make ".yellow + opts.pkgname.bold.red + " better! \n\
May we anonymously report usage statistics to improve the tool over time? \n\
More info: http://goo.gl/GPtU9 & http://yeoman.io".yellow + "\n\
==========================================================================".grey;
-
prompt.message = '[' + '?'.green + ']';
prompt.delimiter = ' ';
@@ -54,7 +56,7 @@ More info: http://goo.gl/GPtU9 & http://yeoman.io".yellow + "\n\
if (err) { return opts.cb(err); }
if (/n/i.test(result.optin)) {
- var insight = spawn('python', insightRecordCmd.concat(['NO_STATS']));
+ spawn('python', insightRecordCmd.concat(['NO_STATS']));
}
opts.cb();
});
View
@@ -1,4 +1,3 @@
-
var fs = require('fs'),
path = require('path'),
rjs = require('requirejs');
@@ -49,7 +48,9 @@ plugin.handler = function link($, options, cb) {
src = el.attr('href'),
file = path.resolve(options.cwd, src);
- if(!path.existsSync(file)) return cb(new Error('no ' + src));
+ if ( !path.existsSync( file ) ) {
+ return cb( new Error( 'no ' + src ) );
+ }
var href = el.data('build') || options.output,
output = path.join(options.out, href);
@@ -64,7 +65,9 @@ plugin.handler = function link($, options, cb) {
log.writeln(' › Handle: ' + el.get(0).outerHTML);
log.writeln((' › Writing optimized CSS file to output ' + output).bold);
rjs.optimize(config, function(res) {
- if(!last) return el.remove();
+ if ( !last ) {
+ return el.remove();
+ }
// update dom tree accordingly
el.attr('href', href);
cb(null, res);
View
@@ -1,4 +1,3 @@
-
var fs = require('fs'),
path = require('path'),
rjs = require('requirejs'),
@@ -78,20 +77,28 @@ plugin.handler = function link($, options, cb) {
src = el.attr('src'),
file = path.resolve(options.cwd, src);
- if(!path.existsSync(file)) return cb(new Error('no ' + src));
+ if ( !path.existsSync( file ) ) {
+ return cb( new Error( 'no ' + src ) );
+ }
files = files.concat(fs.readFileSync(file, 'utf8'));
log.writeln(' › Handle: ' + el.get(0).outerHTML);
- if(!last) return el.remove();
+
+ if ( !last ) {
+ return el.remove();
+ }
var href = el.data('build') || options.output,
output = path.join(options.out, href);
log.writeln((' › Writing optimized JS file to output ' + output).bold);
mkdirp(path.dirname(output), function(e) {
- if(e) return cb(e);
+ if ( e ) {
+ return cb( e );
+ }
+
el.attr('src', href);
var content = files.join(options.separator);
@@ -100,10 +107,12 @@ plugin.handler = function link($, options, cb) {
// minification is a quite costly process. We should store in some cache
// the minified output, indexed by the sha1 of concatenated files.
//
- if(options.minify) log
- .writeln((' › Minifying JS file to output ' + output).bold)
- .writeln((' › from ' + set.length + ' file(s)').bold)
- .writeln((' › This may take a while..').bold);
+ if ( options.minify ) {
+ log
+ .writeln( ( ' › Minifying JS file to output ' + output ).bold )
+ .writeln( ( ' › from ' + set.length + ' file(s)' ).bold )
+ .writeln( (' › This may take a while..').bold );
+ }
content = options.minify ? min(content) : content;
fs.writeFile(output, content, cb);
View
@@ -9,15 +9,9 @@ var fs = require('fs'),
var proxy = process.env.http_proxy || process.env.HTTP_PROXY ||
process.env.https_proxy || process.env.HTTPS_PROXY || '';
-module.exports = fetch;
-
-// re-expose the request with proxy defaults, so that we can
-// reuse this instance of request.
-fetch.request = request.defaults({ proxy: proxy });
-
// heavily based on npm's util/untar.js file
function fetch(tarball, target, cb) {
- var now = +new Date;
+ var now = +new Date();
var log = this.log
.subhead('Fetching ' + tarball)
@@ -31,7 +25,7 @@ function fetch(tarball, target, cb) {
req.on('data', function() { log.write('.'); }).on('end', function() {
log.ok().writeln();
- log.ok( ('Done in ' + (+new Date - now) / 1000 + 's.').green );
+ log.ok( ('Done in ' + (+new Date() - now) / 1000 + 's.').green );
});
req
@@ -56,3 +50,10 @@ function fetch(tarball, target, cb) {
cb();
});
}
+
+
+module.exports = fetch;
+
+// re-expose the request with proxy defaults, so that we can
+// reuse this instance of request.
+fetch.request = request.defaults({ proxy: proxy });
View
@@ -5,8 +5,39 @@ var fs = require('fs'),
// the jQuery file content passed in jsdom
var jquery = fs.readFileSync(path.join(__dirname, '../lib/support/jquery.min.js'), 'utf8');
-module.exports = dom;
-dom.processFile = processFile;
+
+
+// ensures is a wrapper to `require`. Failsafe require catching loading error if
+// not installed, displaying a meaningfull help.
+function ensures(name) {
+ return require(name);
+}
+
+
+// ## Helpers
+//
+// The process file function is the asyns.forEach iterator function. It tries
+// to read the file content from the file system, and bootstrap a jsdom
+// environement for each of these.
+//
+// The processor might have change the dom tree. The content of
+// `window.document.innerHTML` is then used to replace the original file.
+//
+
+function processFile(file, jsdom, cb) {
+ fs.readFile(file, 'utf8', function(err, body) {
+ if ( err ) {
+ return cb( err );
+ }
+
+ jsdom.env({
+ html: body,
+ src: [jquery],
+ done: cb
+ });
+ });
+}
+
// attach helpers if any
@@ -34,11 +65,15 @@ function dom(grunt) {
config = grunt.config;
// dom based task only supported on posix for now
- if(process.platform === 'win32') return;
+ if ( process.platform === 'win32' ) {
+ return;
+ }
grunt.registerTask('dom', 'Dom-based build system', function() {
var jsdom = dom.jsdom || (dom.jsdom = ensures('jsdom'));
- if(!jsdom) return console.log('help install dom');
+ if ( !jsdom ) {
+ return console.log('help install dom');
+ }
config.requires('dom');
var conf = config('dom'),
@@ -62,10 +97,15 @@ function dom(grunt) {
(function run(files) {
var f = files.shift();
- if(!f) return cb();
+
+ if ( !f ) {
+ return cb();
+ }
task.helper('dom:plugin', f, plugins, function(err, body) {
- if(err) return grunt.fail.warn(err);
+ if ( err ) {
+ return grunt.fail.warn( err );
+ }
// Write the new content, and keep the doctype safe (innerHTML returns
// the whole document without doctype).
@@ -86,7 +126,9 @@ function dom(grunt) {
var ln = plugins.length;
processFile(f, function(err, window) {
- if(err) return cb(err);
+ if ( err ) {
+ return cb( err );
+ }
var $ = window.$;
@@ -97,7 +139,9 @@ function dom(grunt) {
// if(!plugin.name) return cb(new Error('Require plugin.name missing'));
// if(!plugin.handler) return cb(new Error('Require plugin.handler missing'));
// if(typeof plugin.handler !== 'function') return cb(new Error('plugin.handler must be a function'));
- if(!plugin.name || !plugin.handler) return;
+ if ( !plugin.name || !plugin.handler ) {
+ return;
+ }
// should do this under a single facade do reduce namespace collision
$.fn[plugin.name] = plugin.handler;
});
@@ -108,55 +152,35 @@ function dom(grunt) {
name = plugin.name;
log.writeln(' » Handle ' + el);
- if(!$.fn[name]) return next();
+
+ if ( !$.fn[ name ] ) {
+ return next();
+ }
+
var options = $.extend({}, plugin.defaults, config('dom.options'));
// attach some usefull info / api to the options object
options.log = options.log || log;
// same for grunt helpers
options.helpers = options.helpers || task._helpers;
$(el)[name]($, options, function(err) {
- if(err) return cb(err);
+ if ( err ) {
+ return cb( err );
+ }
next();
});
});
function next() {
- if(--ln) return;
+ if ( --ln ) {
+ return;
+ }
cb(null, window.document.innerHTML, window);
}
});
});
}
-
-
-// ## Helpers
-//
-// The process file function is the asyns.forEach iterator function. It tries
-// to read the file content from the file system, and bootstrap a jsdom
-// environement for each of these.
-//
-// The processor might have change the dom tree. The content of
-// `window.document.innerHTML` is then used to replace the original file.
-//
-
-function processFile(file, jsdom, cb) {
- fs.readFile(file, 'utf8', function(err, body) {
- if(err) return cb(err);
- jsdom.env({
- html: body,
- src: [jquery],
- done: cb
- });
- });
-}
-
-
-// ensures is a wrapper to `require`. Failsafe require catching loading error if
-// not installed, displaying a meaningfull help.
-function ensures(name) {
- return require(name);
-}
-
+module.exports = dom;
+dom.processFile = processFile;
View
@@ -67,7 +67,7 @@ module.exports = function(grunt) {
var valid = Object.keys(targets);
target = target || 'usemin';
- if(!~valid.indexOf(target)) {
+ if ( valid.indexOf( target ) === -1 ) {
grunt.log
.error('Not a valid target')
.error(grunt.helper('invalid targets', targets));
@@ -80,7 +80,9 @@ module.exports = function(grunt) {
grunt.registerHelper('invalid targets', function(valid, code) {
var msg = Object.keys(valid).map(function(key) {
- if(/pre|post/.test(key)) return '';
+ if ( /pre|post/.test( key ) ) {
+ return '';
+ }
return grunt.helper('pad', key, 10) + '# '+ valid[key];
}).join(grunt.util.linefeed);
Oops, something went wrong.

0 comments on commit b9fe2e5

Please sign in to comment.