From 40898c19a10bd074c9c50fb06bf2e9ae0ca25544 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Wed, 4 Jul 2012 15:06:11 -0700 Subject: [PATCH 1/9] enable JSHint's "bitwise" test --- .jshintrc | 2 +- rhino_modules/jsdoc/tag/dictionary.js | 6 +++++- rhino_modules/jsdoc/tag/type.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.jshintrc b/.jshintrc index c1260897..8c8a75fa 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,5 +1,5 @@ { - "bitwise": false, + "bitwise": true, "curly": false, "eqeqeq": false, "forin": false, diff --git a/rhino_modules/jsdoc/tag/dictionary.js b/rhino_modules/jsdoc/tag/dictionary.js index 4f3c1651..18b1492a 100644 --- a/rhino_modules/jsdoc/tag/dictionary.js +++ b/rhino_modules/jsdoc/tag/dictionary.js @@ -52,7 +52,11 @@ var dictionary = { /** @function */ isNamespace: function(kind) { - return ( ~ _namespaces.indexOf(kind) ); + if ( _namespaces.indexOf(kind) !== -1) { + return true; + } + + return false; }, /** @function */ diff --git a/rhino_modules/jsdoc/tag/type.js b/rhino_modules/jsdoc/tag/type.js index 256cc5d4..d799bad9 100644 --- a/rhino_modules/jsdoc/tag/type.js +++ b/rhino_modules/jsdoc/tag/type.js @@ -82,7 +82,7 @@ function parseVariable(type) { function parseTypes(type) { var types = []; - if ( ~type.indexOf('|') ) { + if ( type.indexOf('|') !== -1 ) { // remove optional parens, like: { ( string | number ) } // see: http://code.google.com/closure/compiler/docs/js-for-compiler.html#types if ( /^\s*\(\s*(.+)\s*\)\s*$/.test(type) ) { From 324af73dcfde8eb6176183f163b497ada5ed2cef Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Wed, 4 Jul 2012 15:19:31 -0700 Subject: [PATCH 2/9] enable JSHint's "curly" test --- .jshintrc | 2 +- rhino_modules/jsdoc/borrow.js | 4 +- rhino_modules/jsdoc/doclet.js | 4 +- rhino_modules/jsdoc/name.js | 8 +-- rhino_modules/jsdoc/src/parser.js | 26 +++++++--- .../jsdoc/tag/dictionary/definitions.js | 8 ++- rhino_modules/jsdoc/util/dumper.js | 4 +- templates/default/publish.js | 52 +++++++++++++------ 8 files changed, 72 insertions(+), 36 deletions(-) diff --git a/.jshintrc b/.jshintrc index 8c8a75fa..08eb3b40 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,6 +1,6 @@ { "bitwise": true, - "curly": false, + "curly": true, "eqeqeq": false, "forin": false, "immed": false, diff --git a/rhino_modules/jsdoc/borrow.js b/rhino_modules/jsdoc/borrow.js index 12054639..44dba578 100644 --- a/rhino_modules/jsdoc/borrow.js +++ b/rhino_modules/jsdoc/borrow.js @@ -32,8 +32,8 @@ exports.resolveBorrows = function(docs) { asName = asName.replace(/^prototype\./, '#'); var parts = asName.split('#'); - if (parts.length === 2) clone.scope = 'instance'; - else clone.scope = 'static'; + if (parts.length === 2) { clone.scope = 'instance'; } + else { clone.scope = 'static'; } asName = parts.pop(); clone.name = asName; diff --git a/rhino_modules/jsdoc/doclet.js b/rhino_modules/jsdoc/doclet.js index aae2f6e2..21c06a9a 100644 --- a/rhino_modules/jsdoc/doclet.js +++ b/rhino_modules/jsdoc/doclet.js @@ -126,7 +126,7 @@ exports.Doclet.prototype.setLongname = function(name) { */ exports.Doclet.prototype.borrow = function(source, target) { var about = {from: source}; - if (target) about.as = target; + if (target) { about.as = target; } if (!this.borrowed) { /** @@ -203,7 +203,7 @@ exports.Doclet.prototype.setMeta = function(meta) { @namespace */ this.meta.code = (this.meta.code || {}); - if (meta.id) this.meta.code.id = meta.id; + if (meta.id) { this.meta.code.id = meta.id; } if (meta.code) { if (meta.code.name) { /** The name of the symbol in the source code. */ diff --git a/rhino_modules/jsdoc/name.js b/rhino_modules/jsdoc/name.js index d5c7d064..815d98c1 100644 --- a/rhino_modules/jsdoc/name.js +++ b/rhino_modules/jsdoc/name.js @@ -79,7 +79,9 @@ exports.resolve = function(doclet) { doclet.scope = puncToScope[RegExp.$1]; doclet.name = doclet.name.substr(1); } - else doclet.scope = 'static'; // default scope when none is provided + else { + doclet.scope = 'static'; // default scope when none is provided + } doclet.setLongname(doclet.memberof + scopeToPunc[doclet.scope] + doclet.name); } @@ -166,8 +168,8 @@ exports.shorten = function(longname, forcedMemberof) { name = longname.substr(forcedMemberof.length); var parts = forcedMemberof.match(/^(.*?)([#.~]?)$/); - if (parts[1]) memberof = parts[1] || forcedMemberof; - if (parts[2]) scope = parts[2]; + if (parts[1]) { memberof = parts[1] || forcedMemberof; } + if (parts[2]) { scope = parts[2]; } } else { var parts = longname? diff --git a/rhino_modules/jsdoc/src/parser.js b/rhino_modules/jsdoc/src/parser.js index 55253ab9..96969a99 100644 --- a/rhino_modules/jsdoc/src/parser.js +++ b/rhino_modules/jsdoc/src/parser.js @@ -199,7 +199,9 @@ exports.Parser.prototype.astnodeToMemberof = function(node) { id = 'astnode'+node.parent.hashCode(); doclet = this.refs[id]; - if (!doclet) return ''; // global? + if (!doclet) { + return ''; // global? + } return doclet.longname||doclet.name; } } @@ -236,16 +238,22 @@ exports.Parser.prototype.resolveThis = function(node) { if (node.enclosingFunction){ return this.resolveThis(node.enclosingFunction/* memberof.doclet.meta.code.val */); } - else return ''; // TODO handle global this? + else { + return ''; // TODO handle global this? + } } } else if (node.parent) { var parent = node.parent; - if (parent.type === Token.COLON) parent = parent.parent; // go up one more + if (parent.type === Token.COLON) { + parent = parent.parent; // go up one more + } memberof.id = 'astnode'+parent.hashCode(); memberof.doclet = this.refs[memberof.id]; - if (!memberof.doclet) return ''; // global? + if (!memberof.doclet) { + return ''; // global? + } return memberof.doclet.longname||memberof.doclet.name; } @@ -262,7 +270,9 @@ exports.Parser.prototype.resolvePropertyParent = function(node) { if (node.parent) { var parent = node.parent; - if (parent.type === Token.COLON) parent = parent.parent; // go up one more + if (parent.type === Token.COLON) { + parent = parent.parent; // go up one more + } memberof.id = 'astnode'+parent.hashCode(); memberof.doclet = this.refs[memberof.id]; @@ -366,7 +376,9 @@ function visitNode(node) { var basename = getBasename(e.code.name); - if (basename !== 'this') e.code.funcscope = currentParser.resolveVar(node, basename); + if (basename !== 'this') { + e.code.funcscope = currentParser.resolveVar(node, basename); + } } else if (node.type === Token.COLON) { // assignment within an object literal e = { @@ -553,7 +565,7 @@ function aboutNode(node) { function nodeToString(node) { var str; - if (!node) return; + if (!node) { return; } if (node.type === Token.GETPROP) { str = [nodeToString(node.target), node.property.string].join('.'); diff --git a/rhino_modules/jsdoc/tag/dictionary/definitions.js b/rhino_modules/jsdoc/tag/dictionary/definitions.js index 82fe601f..ab5f0cf8 100644 --- a/rhino_modules/jsdoc/tag/dictionary/definitions.js +++ b/rhino_modules/jsdoc/tag/dictionary/definitions.js @@ -513,7 +513,9 @@ exports.defineTags = function(dictionary) { onTagged: function(doclet, tag) { if (tag.value && tag.value.type) { doclet.type = tag.value.type; - if (doclet.kind === 'function') doclet.addTag('returns', tag.text); // for backwards compatibility we allow @type for functions to imply return type + if (doclet.kind === 'function') { + doclet.addTag('returns', tag.text); // for backwards compatibility we allow @type for functions to imply return type + } } } }); @@ -601,7 +603,9 @@ function applyNamespace(docletOrNs, tag) { tag.value = app.jsdoc.name.applyNamespace(tag.value, docletOrNs); } else { // doclet - if (!docletOrNs.name) return; // error? + if (!docletOrNs.name) { + return; // error? + } //doclet.displayname = doclet.name; docletOrNs.longname = app.jsdoc.name.applyNamespace(docletOrNs.name, tag.title); diff --git a/rhino_modules/jsdoc/util/dumper.js b/rhino_modules/jsdoc/util/dumper.js index 1e13d2e0..9392401a 100644 --- a/rhino_modules/jsdoc/util/dumper.js +++ b/rhino_modules/jsdoc/util/dumper.js @@ -37,7 +37,7 @@ function pad(depth) { */ function indent(openingBrace) { indentBy++; - if (openingBrace) output += openingBrace + '\n'; + if (openingBrace) { output += openingBrace + '\n'; } } /** @@ -51,7 +51,7 @@ function outdent(closingBrace) { indentBy--; output = output.replace(/,\n$/, '\n'); // trim trailing comma if (closingBrace === false) { output = output.replace(/\n$/, ''); } - else if (closingBrace) output += pad(indentBy) + closingBrace + ',\n'; + else if (closingBrace) { output += pad(indentBy) + closingBrace + ',\n'; } } var seen = []; diff --git a/templates/default/publish.js b/templates/default/publish.js index 794eb3d3..fd40ea8a 100644 --- a/templates/default/publish.js +++ b/templates/default/publish.js @@ -53,7 +53,7 @@ while (doc = doc.memberof) { doc = find({longname: doc}); if (doc) { doc = doc[0]; } - if (!doc) break; + if (!doc) { break; } ancestors.unshift( linkto(doc.longname, (scopeToPunc[doc.scope] || '') + doc.name) ); } if (ancestors.length) { @@ -109,11 +109,15 @@ } if (f.scope && f.scope !== 'instance' && f.scope !== 'global') { - if (f.kind == 'function' || f.kind == 'member' || f.kind == 'constant') attribs.push(f.scope); + if (f.kind == 'function' || f.kind == 'member' || f.kind == 'constant') { + attribs.push(f.scope); + } } if (f.readonly === true) { - if (f.kind == 'member') attribs.push('readonly'); + if (f.kind == 'member') { + attribs.push('readonly'); + } } if (f.kind === 'constant') { @@ -246,7 +250,9 @@ if (moduleNames.length) { nav += '

Modules