From 34441c20f86c0201b29d0ba1ff05a58baedcd654 Mon Sep 17 00:00:00 2001 From: Simon Boudrias Date: Sun, 29 Dec 2013 20:05:42 -0500 Subject: [PATCH] Apply style guide --- .jscs.json | 2 +- lib/actions/actions.js | 16 ++++++++-------- lib/actions/fetch.js | 1 + lib/actions/file.js | 1 + lib/actions/install.js | 1 + lib/actions/invoke.js | 1 + lib/actions/spawn_command.js | 2 +- lib/actions/string.js | 1 + lib/actions/user.js | 1 + lib/actions/wiring.js | 7 +++++-- lib/env/adapter.js | 4 ---- lib/env/index.js | 17 ++++++++--------- lib/env/resolver.js | 1 + lib/env/store.js | 3 ++- lib/test/helpers.js | 15 ++++++++------- lib/util/common.js | 1 + lib/util/conflicter.js | 3 --- lib/util/engines.js | 3 +-- lib/util/log.js | 17 +++++++++-------- lib/util/misc.js | 0 lib/util/storage.js | 4 ++-- 21 files changed, 53 insertions(+), 48 deletions(-) delete mode 100644 lib/util/misc.js diff --git a/.jscs.json b/.jscs.json index 680c574a..48712569 100644 --- a/.jscs.json +++ b/.jscs.json @@ -18,7 +18,7 @@ "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], - "disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"], + "disallowImplicitTypeConversion": ["numeric", "binary", "string"], "disallowKeywords": ["with", "eval"], "disallowMultipleLineBreaks": true, "validateLineBreaks": "LF", diff --git a/lib/actions/actions.js b/lib/actions/actions.js index 87f2b2d7..21a49a78 100644 --- a/lib/actions/actions.js +++ b/lib/actions/actions.js @@ -30,7 +30,7 @@ actions.cacheRoot = function cacheRoot() { }; // Copy helper for two versions of copy action -function prepCopy(source, destination, process) { +actions._prepCopy = function _prepCopy(source, destination, process) { var body; destination = destination || source; @@ -62,7 +62,7 @@ function prepCopy(source, destination, process) { destination: destination, source: source }; -} +}; /** * Make some of the file API aware of our source/destination root paths. @@ -76,7 +76,7 @@ function prepCopy(source, destination, process) { actions.copy = function copy(source, destination, process) { - var file = prepCopy.call(this, source, destination, process); + var file = this._prepCopy(source, destination, process); try { file.body = this.engine(file.body, this); @@ -132,7 +132,7 @@ actions.copy = function copy(source, destination, process) { actions.bulkCopy = function bulkCopy(source, destination, process) { - var file = prepCopy.call(this, source, destination, process); + var file = this._prepCopy(source, destination, process); mkdirp.sync(path.dirname(file.destination)); fs.writeFileSync(file.destination, file.body); @@ -301,7 +301,7 @@ actions.engine = function engine(body, data) { }; // Shared directory method -function _directory(source, destination, process, bulk) { +actions._directory = function _directory(source, destination, process, bulk) { // Only add sourceRoot if the path is not absolute var root = this.isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source); var files = this.expandFiles('**', { dot: true, cwd: root }); @@ -325,7 +325,7 @@ function _directory(source, destination, process, bulk) { } return this; -} +}; /** * Copies recursively the files from source directory to root directory. @@ -336,7 +336,7 @@ function _directory(source, destination, process, bulk) { */ actions.directory = function directory(source, destination, process) { - return _directory.call(this, source, destination, process); + return this._directory(source, destination, process); }; /** @@ -360,7 +360,7 @@ actions.bulkDirectory = function directory(source, destination, process) { return config.callback(); } - _directory.call(this, source, destination, process, true); + this._directory(source, destination, process, true); config.callback(); }); return this; diff --git a/lib/actions/fetch.js b/lib/actions/fetch.js index f979575b..379f9718 100644 --- a/lib/actions/fetch.js +++ b/lib/actions/fetch.js @@ -1,3 +1,4 @@ +'use strict'; var fs = require('fs'); var path = require('path'); var request = require('request'); diff --git a/lib/actions/file.js b/lib/actions/file.js index 5d87f930..c3977312 100644 --- a/lib/actions/file.js +++ b/lib/actions/file.js @@ -1,3 +1,4 @@ +'use strict'; var fs = require('fs'); var path = require('path'); var glob = require('glob'); diff --git a/lib/actions/install.js b/lib/actions/install.js index 7dc5b41c..89b31bcd 100644 --- a/lib/actions/install.js +++ b/lib/actions/install.js @@ -1,3 +1,4 @@ +'use strict'; var _ = require('lodash'); var dargs = require('dargs'); var async = require('async'); diff --git a/lib/actions/invoke.js b/lib/actions/invoke.js index db7f5102..d29f308d 100644 --- a/lib/actions/invoke.js +++ b/lib/actions/invoke.js @@ -1,3 +1,4 @@ +'use strict'; var path = require('path'); /** diff --git a/lib/actions/spawn_command.js b/lib/actions/spawn_command.js index 611273bc..6a36aa1f 100644 --- a/lib/actions/spawn_command.js +++ b/lib/actions/spawn_command.js @@ -1,3 +1,4 @@ +'use strict'; var _ = require('lodash'); var spawn = require('child_process').spawn; var win32 = process.platform === 'win32'; @@ -16,4 +17,3 @@ module.exports = function spawnCommand(command, args, opt) { return spawn(winCommand, winArgs, _.defaults({ stdio: 'inherit' }, opt)); }; - diff --git a/lib/actions/string.js b/lib/actions/string.js index 64ffa6fd..50546765 100644 --- a/lib/actions/string.js +++ b/lib/actions/string.js @@ -1,3 +1,4 @@ +'use strict'; var _ = require('lodash'); _.str = require('underscore.string'); diff --git a/lib/actions/user.js b/lib/actions/user.js index e934c660..3621b9bd 100644 --- a/lib/actions/user.js +++ b/lib/actions/user.js @@ -1,3 +1,4 @@ +'use strict'; var shell = require('shelljs'); var _ = require('lodash'); diff --git a/lib/actions/wiring.js b/lib/actions/wiring.js index 955c7169..95c75c1c 100644 --- a/lib/actions/wiring.js +++ b/lib/actions/wiring.js @@ -1,3 +1,4 @@ +'use strict'; var util = require('util'); var fs = require('fs'); var path = require('path'); @@ -108,7 +109,8 @@ wiring.prependToFile = function prependToFile(path, tagName, content) { */ wiring.generateBlock = function generateBlock(blockType, optimizedPath, filesBlock, searchPath) { - var blockStart, blockEnd; + var blockStart; + var blockEnd; var blockSearchPath = ''; if (searchPath !== undefined) { @@ -137,7 +139,8 @@ wiring.generateBlock = function generateBlock(blockType, optimizedPath, filesBlo */ wiring.appendFiles = function appendFiles(htmlOrOptions, fileType, optimizedPath, sourceFileList, attrs, searchPath) { - var blocks, updatedContent; + var blocks; + var updatedContent; var html = htmlOrOptions; var files = ''; diff --git a/lib/env/adapter.js b/lib/env/adapter.js index 59ba8cde..e3414273 100644 --- a/lib/env/adapter.js +++ b/lib/env/adapter.js @@ -5,7 +5,6 @@ var diff = require('diff'); var chalk = require('chalk'); var logger = require('../util/log'); - /** * `TerminalAdapter` is the default implementation of `Adapter`, an abstraction * layer that defines the I/O interactions. @@ -14,7 +13,6 @@ var logger = require('../util/log'); */ var TerminalAdapter = module.exports = function TerminalAdapter() {}; - TerminalAdapter.prototype._colorDiffAdded = chalk.black.bgGreen; TerminalAdapter.prototype._colorDiffRemoved = chalk.bgRed; TerminalAdapter.prototype._colorLines = function colorLines(name, str) { @@ -69,5 +67,3 @@ TerminalAdapter.prototype.diff = function _diff(actual, expected) { }; TerminalAdapter.prototype.log = logger(); - - diff --git a/lib/env/index.js b/lib/env/index.js index cf40b3c6..43f93ae4 100644 --- a/lib/env/index.js +++ b/lib/env/index.js @@ -1,3 +1,4 @@ +'use strict'; var fs = require('fs'); var util = require('util'); var path = require('path'); @@ -93,7 +94,7 @@ Environment.prototype.appendPath = function appendPath(filepath) { * Appends the defaults node modules paths to the Environment load paths. */ -Environment.prototype.appendDefaultPaths = function() { +Environment.prototype.appendDefaultPaths = function () { this.appendPath(process.cwd()); // We tried using NPM to get the global modules path, but it haven't work out @@ -182,7 +183,7 @@ Environment.prototype.register = function register(name, namespace) { } var modulePath = this.resolveModulePath(name); - namespace || (namespace = this.namespace(modulePath)); + namespace = namespace || this.namespace(modulePath); if (!namespace) { return this.error(new Error('Unable to determine namespace.')); @@ -248,13 +249,11 @@ Environment.prototype.getGeneratorsMeta = function getGeneratorsMeta() { Environment.prototype.get = function get(namespace) { // Stop the recursive search if nothing is left - if (!namespace) { - return; - } + if (!namespace) return; - return this.store.get(namespace) - || this.store.get(this.alias(namespace)) - || this.get(namespace.split(':').slice(0, -1).join(':')); + return this.store.get(namespace) || + this.store.get(this.alias(namespace)) || + this.get(namespace.split(':').slice(0, -1).join(':')); }; /** @@ -419,7 +418,7 @@ Environment.prototype.namespace = function namespace(filepath) { Environment.prototype.resolveModulePath = function resolveModulePath(moduleId) { if (moduleId[0] === '.') { - moduleId = path.resolve(moduleId) + moduleId = path.resolve(moduleId); } if (moduleId[0] === '~') { diff --git a/lib/env/resolver.js b/lib/env/resolver.js index 95510f3e..d6f17e8a 100644 --- a/lib/env/resolver.js +++ b/lib/env/resolver.js @@ -1,3 +1,4 @@ +'use strict'; var path = require('path'); var fs = require('fs'); var _ = require('lodash'); diff --git a/lib/env/store.js b/lib/env/store.js index 01490b80..4aa41fa2 100644 --- a/lib/env/store.js +++ b/lib/env/store.js @@ -1,3 +1,4 @@ +'use strict'; var util = require('util'); var _ = require('lodash'); var Base = require('../base'); @@ -45,7 +46,7 @@ Store.prototype._storeAsPath = function _storeAsPath (namespace, path) { Store.prototype._storeAsModule = function _storeAsModule (namespace, Generator) { this._meta[namespace] = { - resolved: "unknown", + resolved: 'unknown', namespace: namespace }; this._generators[namespace] = Generator; diff --git a/lib/test/helpers.js b/lib/test/helpers.js index 0050cbce..13841803 100644 --- a/lib/test/helpers.js +++ b/lib/test/helpers.js @@ -1,3 +1,4 @@ +'use strict'; var fs = require('fs'); var path = require('path'); var rimraf = require('rimraf'); @@ -148,14 +149,14 @@ helpers.assertTextEqual = function (value, expected) { }; /** - * Assert an Object implement and interface - * @param {Object} obj subject implementing the façade - * @param {Object|Array} interface a façace, hash or array of keys to be implemented + * Assert an Object implement an interface + * @param {Object} obj - subject implementing the façade + * @param {Object|Array} methods - a façace, hash or array of keys to be implemented */ -helpers.assertImplement = function(obj, interface) { - var methods = _.isArray(interface) ? interface : Object.keys(interface); - var pass = methods.reduce(function(rest, method) { +helpers.assertImplement = function (obj, methods) { + methods = _.isArray(methods) ? methods : Object.keys(methods); + var pass = methods.reduce(function (rest, method) { if (obj[method] != null) return true; return rest; }, false); @@ -235,7 +236,7 @@ helpers.createGenerator = function (name, dependencies, args, options) { } }); - var generator = env.create(name, {arguments: args, options: options}); + var generator = env.create(name, { arguments: args, options: options }); generator.on('start', env.emit.bind(this, 'generators:start')); generator.on('start', env.emit.bind(this, name + ':start')); diff --git a/lib/util/common.js b/lib/util/common.js index 0efb29c9..cb48029a 100644 --- a/lib/util/common.js +++ b/lib/util/common.js @@ -1,3 +1,4 @@ +'use strict'; var chalk = require('chalk'); module.exports.yeoman = diff --git a/lib/util/conflicter.js b/lib/util/conflicter.js index 62331032..e2cafd07 100644 --- a/lib/util/conflicter.js +++ b/lib/util/conflicter.js @@ -15,7 +15,6 @@ var Conflicter = module.exports = function Conflicter(adapter) { util.inherits(Conflicter, events.EventEmitter); - Conflicter.prototype.add = function add(conflict) { if (typeof conflict === 'string') { conflict = { @@ -138,7 +137,6 @@ Conflicter.prototype._ask = function (filepath, content, cb) { }); }; - Conflicter.prototype.collision = function collision(filepath, content, cb) { var rfilepath = path.relative(process.cwd(), path.resolve(filepath)); if (!fs.existsSync(filepath)) { @@ -175,7 +173,6 @@ Conflicter.prototype.collision = function collision(filepath, content, cb) { this._ask(filepath, content, cb); }; - // below is borrowed code from visionmedia's excellent mocha (and its reporter) Conflicter.prototype.diff = function _diff(actual, expected) { return this.adapter.diff(actual, expected); diff --git a/lib/util/engines.js b/lib/util/engines.js index 14aedb3d..62136edf 100644 --- a/lib/util/engines.js +++ b/lib/util/engines.js @@ -1,3 +1,4 @@ +'use strict'; var _ = require('lodash'); // TODO(mklabs): @@ -7,10 +8,8 @@ var _ = require('lodash'); // template) // - put in multiple files, possibly other packages. -// engines var engines = module.exports; - // Underscore // ---------- diff --git a/lib/util/log.js b/lib/util/log.js index 17f13bee..0cc20332 100644 --- a/lib/util/log.js +++ b/lib/util/log.js @@ -1,3 +1,4 @@ +'use strict'; var util = require('util'); var events = require('events'); var _ = require('lodash'); @@ -10,13 +11,13 @@ var padding = ' '; // color -> status mappings var colors = { - skip : 'yellow', - force : 'yellow', - create : 'green', - invoke : 'bold', - conflict : 'red', - identical : 'cyan', - info : 'gray' + skip: 'yellow', + force: 'yellow', + create: 'green', + invoke: 'bold', + conflict: 'red', + identical: 'cyan', + info: 'gray' }; function pad(status) { @@ -158,7 +159,7 @@ module.exports = function logger() { log.table = function (opts) { var tableData = []; - opts = Array.isArray(opts) ? { rows: opts } : opts; + opts = Array.isArray(opts) ? { rows: opts }: opts; opts.rows = opts.rows || []; opts.rows.forEach(function (row) { diff --git a/lib/util/misc.js b/lib/util/misc.js deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/util/storage.js b/lib/util/storage.js index e2795f17..cf235f00 100644 --- a/lib/util/storage.js +++ b/lib/util/storage.js @@ -1,10 +1,10 @@ +'use strict'; var fs = require('fs'); var path = require('path'); var EventEmitter = require('events').EventEmitter; var _ = require('lodash'); var util = require('util'); - /** * Storage instances handle a json file where Generator authors can store data. * @param {String} name The name of the new storage (this is a namespace) @@ -59,7 +59,7 @@ Storage.prototype.loadConfig = function () { * @return {null} */ -Storage.prototype.save = function() {}; +Storage.prototype.save = function () {}; /** * Force save (synchronously write the store to disk).