Permalink
Browse files

jshint fixes

  • Loading branch information...
davglass committed Oct 9, 2012
1 parent e827fae commit 36ac8917f3ca619db549674adec7bca8f07acf1a
Showing with 124 additions and 115 deletions.
  1. +29 −28 lib/fileutils.js
  2. +24 −22 lib/higgins.js
  3. +43 −41 lib/selleck.js
  4. +4 −2 lib/server.js
  5. +23 −21 lib/util.js
  6. +1 −1 lib/view/index.js
View
@@ -1,3 +1,4 @@
+/*jshint expr: true, latedef: false,loopfunc:true */
/*
Selleck
Copyright (c) 2011 Yahoo! Inc.
@@ -18,16 +19,28 @@ function copyDirectory(source, dest, overwrite, callback) {
overwrite = null;
}
- fs.stat(source, afterSourceStat);
-
- function afterSourceStat(err, stats) {
+ function afterReadDir(err, files) {
if (err) { return callback(err); }
- if (!stats.isDirectory()) {
- return callback(new Error("Source is not a directory: " + source));
+ var pending = files.length,
+ filename;
+
+ while ((filename = files.shift())) {
+ copyPath(fsPath.join(source, filename), fsPath.join(dest, filename), overwrite, function (err) {
+ if (err) { return callback(err); }
+
+ pending -= 1;
+
+ if (!pending) {
+ callback();
+ }
+ });
}
+ }
- fs.lstat(dest, afterDestStat);
+ function afterMkDir(err) {
+ if (err && err.code !== 'EEXIST') { return callback(err); }
+ fs.readdir(source, afterReadDir);
}
function afterDestStat(err, stats) {
@@ -47,33 +60,22 @@ function copyDirectory(source, dest, overwrite, callback) {
afterMkDir();
} else {
- fs.mkdir(dest, 0755, afterMkDir);
+ fs.mkdir(dest, parseInt('0755', 8), afterMkDir);
}
}
- function afterMkDir(err) {
- if (err && err.code !== 'EEXIST') { return callback(err); }
- fs.readdir(source, afterReadDir);
- }
-
- function afterReadDir(err, files) {
+ function afterSourceStat(err, stats) {
if (err) { return callback(err); }
- var pending = files.length,
- filename;
+ if (!stats.isDirectory()) {
+ return callback(new Error("Source is not a directory: " + source));
+ }
- while ((filename = files.shift())) {
- copyPath(fsPath.join(source, filename), fsPath.join(dest, filename), overwrite, function (err) {
- if (err) { return callback(err); }
+ fs.lstat(dest, afterDestStat);
+ }
- pending -= 1;
+ fs.stat(source, afterSourceStat);
- if (!pending) {
- callback();
- }
- });
- }
- }
}
exports.copyDirectory = copyDirectory;
@@ -107,7 +109,7 @@ function copyFile(source, dest, overwrite, callback) {
}
nodeUtil.pump(fs.createReadStream(source),
- fs.createWriteStream(dest, {mode: 0655}), callback);
+ fs.createWriteStream(dest, {mode: parseInt('0655', 8)}), callback);
});
});
}
@@ -134,8 +136,7 @@ Known issues:
@param {Error} err
**/
function copyPath(source, dest, overwrite, callback) {
- var destStats = statSync(dest),
- sourceStats = statSync(source);
+ var sourceStats = statSync(source);
// Allow callback as third arg.
if (typeof overwrite === 'function') {
View
@@ -1,3 +1,4 @@
+/*jshint expr: true, latedef: false, bitwise: false */
/*
Selleck
Copyright (c) 2011 Yahoo! Inc.
@@ -30,6 +31,29 @@ Higgins.render = function (html) {
return new Higgins(html).render();
};
+// -- Private Functions --------------------------------------------------------
+
+/**
+Normalizes the initial indentation of the given _content_ so that the first line
+is unindented, and all other lines are unindented to the same degree as the
+first line. So if the first line has four spaces at the beginning, then all
+lines will be unindented four spaces.
+
+@method unindent
+@param {String} content Text to unindent.
+@return {String} Unindented text.
+@private
+**/
+function unindent(content) {
+ var indent = content.match(/^(\s+)/);
+
+ if (indent) {
+ content = content.replace(new RegExp('^' + indent[1], 'gm'), '');
+ }
+
+ return content;
+}
+
Higgins.prototype = {
// -- Public Functions -----------------------------------------------------
render: function () {
@@ -250,25 +274,3 @@ Higgins.prototype = {
module.exports = Higgins;
-// -- Private Functions --------------------------------------------------------
-
-/**
-Normalizes the initial indentation of the given _content_ so that the first line
-is unindented, and all other lines are unindented to the same degree as the
-first line. So if the first line has four spaces at the beginning, then all
-lines will be unindented four spaces.
-
-@method unindent
-@param {String} content Text to unindent.
-@return {String} Unindented text.
-@private
-**/
-function unindent(content) {
- var indent = content.match(/^(\s+)/);
-
- if (indent) {
- content = content.replace(new RegExp('^' + indent[1], 'gm'), '');
- }
-
- return content;
-}
View
@@ -1,3 +1,4 @@
+/*jshint expr: true, latedef: false */
/*
Selleck
Copyright (c) 2011 Yahoo! Inc.
@@ -76,7 +77,7 @@ function createOutputDir(outDir) {
}
} else {
// TODO: mkdir -p
- fs.mkdirSync(outDir, 0755);
+ fs.mkdirSync(outDir, parseInt('0755', 8));
}
}
exports.createOutputDir = createOutputDir;
@@ -124,6 +125,43 @@ function findDocs(dir, docs) {
}
exports.findDocs = findDocs;
+/**
+@method writePages
+**/
+function writePages(outDir, options, callback) {
+ var ext = options['out-ext'],
+ toWrite = util.size(options.pages);
+
+ if (!toWrite) { return callback(); }
+
+ function finish(err) {
+ if (err) { return callback(err); }
+
+ if (!(toWrite -= 1)) {
+ callback();
+ }
+ }
+
+ // Render each page to HTML and write it to the output directory.
+ util.each(options.pages, function (source, name) {
+ var view = new options.viewClass(options.meta, name),
+ layout = options.layouts[view.layout];
+
+ render(source, view, layout, options.partials, function (err, html) {
+ if (err) { return callback(err); }
+
+ if (options.dumpViews) {
+ fs.writeFile(path.join(outDir, name + '.json'),
+ JSON.stringify(view, null, 2), 'utf8');
+ }
+
+ fs.writeFile(path.join(outDir, name + ext), html, 'utf8', finish);
+ });
+ });
+
+}
+exports.writePages = writePages;
+
/**
@method generate
@param {String} inDir Input directory containing docs and assets to generate.
@@ -286,10 +324,10 @@ exports.isProjectDirectory = isProjectDirectory;
/**
Logs a message to stdout or stderr, with an optional log level.
-@method log
+@method log
@param {String} message A message to write to the console.
-@param {String} [level] A short string describing the type of message.
- If the level is 'error', Selleck logs the message to stderr.
+@param {String} [level] A short string describing the type of message.
+ If the level is 'error', Selleck logs the message to stderr.
Otherwise, Selleck logs the message to stdout.
The default level is 'info'.
**/
@@ -311,8 +349,7 @@ exports.log = log;
@param {Object} options Merged options.
**/
function prepare(inDir, options, callback) {
- var compiled = {},
- meta = {},
+ var meta = {},
type = options.component ? 'component' : 'project';
if (options && options.skipLoad) {
@@ -458,38 +495,3 @@ function render(source, view, layout, partials, callback) {
}
exports.render = render;
-/**
-@method writePages
-**/
-function writePages(outDir, options, callback) {
- var ext = options['out-ext'],
- toWrite = util.size(options.pages);
-
- if (!toWrite) { return callback(); }
-
- // Render each page to HTML and write it to the output directory.
- util.each(options.pages, function (source, name) {
- var view = new options.viewClass(options.meta, name),
- layout = options.layouts[view.layout];
-
- render(source, view, layout, options.partials, function (err, html) {
- if (err) { return callback(err); }
-
- if (options.dumpViews) {
- fs.writeFile(path.join(outDir, name + '.json'),
- JSON.stringify(view, null, 2), 'utf8');
- }
-
- fs.writeFile(path.join(outDir, name + ext), html, 'utf8', finish);
- });
- });
-
- function finish(err) {
- if (err) { return callback(err); }
-
- if (!(toWrite -= 1)) {
- callback();
- }
- }
-}
-exports.writePages = writePages;
View
@@ -46,6 +46,8 @@ module.exports = function (config) {
if (!component.meta.examples) { return; }
component.meta.examples.forEach(function (example) {
+ /*jshint expr: true*/
+ //TODO FIX
example.componentName || (example.componentName = component.meta.name);
if (!example.modules) { return; }
@@ -134,7 +136,7 @@ module.exports = function (config) {
options.layouts = selleck.getLayouts(config.theme);
options.partials = selleck.getPartials(config.theme);
- selleck.prepare(projectPath, options, function (err, options, compiled) {
+ selleck.prepare(projectPath, options, function (err, options) {
if (err) { return next(err); }
options.meta.components = util.values(components).sort(function (a, b) {
@@ -185,7 +187,7 @@ module.exports = function (config) {
selleck.getPartials(projectPath)
);
- selleck.prepare(docPath, options, function (err, options, compiled) {
+ selleck.prepare(docPath, options, function (err, options) {
if (err) { return next(err); }
if (options.meta.examples) {
View
@@ -50,27 +50,6 @@ function escapeHTML(html) {
}
exports.escapeHTML = escapeHTML;
-/**
-Returns a new object containing a deep merge of the enumerable properties of all
-passed objects. Properties in later arguments take precedence over properties
-with the same name in earlier arguments. Object values are deep-cloned. Array
-values are _not_ deep-cloned.
-
-@method merge
-@param {object} obj* One or more objects to merge.
-@return {object} New object with merged values from all other objects.
-**/
-function merge() {
- var args = Array.prototype.slice.call(arguments),
- target = {};
-
- args.unshift(target);
- mix.apply(this, args);
-
- return target;
-}
-exports.merge = merge;
-
/**
Like `merge()`, but augments the first passed object with a deep merge of the
enumerable properties of all other passed objects, rather than returning a
@@ -94,6 +73,8 @@ function mix() {
value = source[key];
if (value && typeof value === 'object' && !Array.isArray(value)) {
+ /*jshint expr: true*/
+ //TODO FIX
typeof target[key] === 'object' || (target[key] = {});
mix(target[key], value);
} else {
@@ -106,6 +87,27 @@ function mix() {
}
exports.mix = mix;
+/**
+Returns a new object containing a deep merge of the enumerable properties of all
+passed objects. Properties in later arguments take precedence over properties
+with the same name in earlier arguments. Object values are deep-cloned. Array
+values are _not_ deep-cloned.
+
+@method merge
+@param {object} obj* One or more objects to merge.
+@return {object} New object with merged values from all other objects.
+**/
+function merge() {
+ var args = Array.prototype.slice.call(arguments),
+ target = {};
+
+ args.unshift(target);
+ mix.apply(this, args);
+
+ return target;
+}
+exports.merge = merge;
+
/**
If _obj_ is an array, returns `obj.length`. If _obj_ is an object, returns the
number of enumerable properties.
View
@@ -21,7 +21,7 @@ function View(data, templateName) {
util.mix(this, this.pages[this.templateName]);
} else {
/*
- Template name was not found in this pages list, so walk all the pages and
+ Template name was not found in this pages list, so walk all the pages and
see if any of them contain this example. If it does, then
mix the data in and reset the `self.examples` before the
below code mixes them.

0 comments on commit 36ac891

Please sign in to comment.