From 852db0b8f8563542d615e6559cdace99675141b1 Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Wed, 29 Jan 2014 14:48:45 -0800 Subject: [PATCH] Lint the world. --- lib/builder.js | 156 ++++++++++++++++++-------------- lib/cli.js | 8 +- lib/docparser.js | 198 ++++++++++++++++++++++------------------- lib/files.js | 78 ++++++++-------- lib/help.js | 2 +- lib/index.js | 3 +- lib/options.js | 3 +- lib/project.js | 1 + lib/server.js | 25 +++--- lib/utils.js | 9 +- lib/yuidoc.js | 20 ++--- tests/builder.js | 34 +++---- tests/files.js | 1 + tests/options.js | 18 ++-- tests/parser.js | 120 ++++++++++++++----------- tests/parser_coffee.js | 5 +- tests/utils.js | 5 +- 17 files changed, 376 insertions(+), 310 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index 1b10ba5e..f3117e11 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -17,6 +17,7 @@ based templates to generate static HTML content */ YUI.add('doc-builder', function(Y) { + /*jshint onevar:false */ var fixType = Y.Lang.fixType, print = function(items) { @@ -38,11 +39,12 @@ YUI.add('doc-builder', function(Y) { return out; }; - Y.Handlebars.registerHelper('buildFileTree', function(items, fn) { + Y.Handlebars.registerHelper('buildFileTree', function (items) { return print(items); }); - var DEFAULT_THEME = themeDir = path.join(__dirname, '../', 'themes', 'default'); + var DEFAULT_THEME = path.join(__dirname, '../', 'themes', 'default'), + themeDir = DEFAULT_THEME; Y.DocBuilder = function(options, data) { this.options = options; @@ -80,17 +82,17 @@ YUI.add('doc-builder', function(Y) { Y.Handlebars.registerHelper('crossLinkModule', function(item, options) { var str = item; if (self.data.modules[item]) { - var content = options.fn(this); - if (content === "") { - content = item; - } + var content = options.fn(this); + if (content === "") { + content = item; + } str = '' + content + ''; } return str; }); - Y.Handlebars.registerHelper('crossLinkRaw', function(item, fn) { + Y.Handlebars.registerHelper('crossLinkRaw', function (item) { var str = ''; if (!item) { item = ''; @@ -112,7 +114,6 @@ YUI.add('doc-builder', function(Y) { if (options.cacheTemplates === false) { this.cacheTemplates = false; } - }; Y.DocBuilder.prototype = { @@ -141,7 +142,7 @@ YUI.add('doc-builder', function(Y) { * @return {HTML} The rendered HTML */ markdown: function(md) { - html = marked(md, this.options.markdown); + var html = marked(md, this.options.markdown); //Only reprocess if helpers were asked for if (this.options.helpers || (html.indexOf('{{#crossLink') > -1)) { //console.log('MD: ', html); @@ -171,7 +172,7 @@ YUI.add('doc-builder', function(Y) { _parseCrossLink: function(item, raw, content) { var self = this; var base = '../', - baseName = item, + baseItem, newWin = false, className = 'crosslink'; @@ -212,7 +213,7 @@ YUI.add('doc-builder', function(Y) { if (method.indexOf(':') > -1) { parts = method.split(':'); - method = parts[0], + method = parts[0]; type = parts[1]; if (type.indexOf('attr') === 0) { type = 'attribute'; @@ -257,12 +258,12 @@ YUI.add('doc-builder', function(Y) { } } if (link) { - if (content !== undefined) { - content = content.trim(); - } - if (!content) { - content = baseItem; - } + if (content !== undefined) { + content = content.trim(); + } + if (!content) { + content = baseItem; + } item = '' + content + ''; } return (raw) ? href : item; @@ -361,8 +362,8 @@ YUI.add('doc-builder', function(Y) { } }); } - if (item.return) { - item.return.type = fixType(item.return.type); + if (item["return"]) { + item["return"].type = fixType(item["return"].type); } self.data.classitems.push(item); }); @@ -468,7 +469,7 @@ YUI.add('doc-builder', function(Y) { Y.log('Loading theme from ' + theme, 'info', 'builder'); meta = Y.Files.getJSON(theme); } else if (DEFAULT_THEME !== themeDir) { - theme = path.join(DEFAULT_THEME, 'theme.json') + theme = path.join(DEFAULT_THEME, 'theme.json'); if (Y.Files.exists(theme)) { Y.log('Loading theme from ' + theme, 'info', 'builder'); meta = Y.Files.getJSON(theme); @@ -489,7 +490,7 @@ YUI.add('doc-builder', function(Y) { var key = k.substring(0, 1).toUpperCase() + k.substring(1, k.length); obj.meta['project' + key] = v; }); - return obj + return obj; }, /** * Populate the meta data for classes @@ -500,7 +501,7 @@ YUI.add('doc-builder', function(Y) { populateClasses: function(opts) { opts.meta.classes = []; Y.each(this.data.classes, function(v) { - if (v.external) { return } + if (v.external) { return; } opts.meta.classes.push({ displayName: v.name, name: v.name, @@ -524,21 +525,21 @@ YUI.add('doc-builder', function(Y) { opts.meta.modules = []; opts.meta.allModules = []; Y.each(this.data.modules, function(v) { - if (v.external) { return } + if (v.external) { return; } opts.meta.allModules.push({ displayName: v.displayName || v.name, name: self.filterFileName(v.name), description: v.description }); if (!v.is_submodule) { var o = { displayName: v.displayName || v.name, name: self.filterFileName(v.name) }; if (v.submodules) { o.submodules = []; Y.each(v.submodules, function(i, k) { - moddef = self.data.modules[k]; + var moddef = self.data.modules[k]; if (moddef) { o.submodules.push({ displayName: k, description: moddef.description }); - } else { - //Y.log('Submodule data missing: ' + k + ' for ' + v.name, 'warn', 'builder'); + // } else { + // Y.log('Submodule data missing: ' + k + ' for ' + v.name, 'warn', 'builder'); } }); o.submodules.sort(self.nameSort); @@ -560,14 +561,14 @@ YUI.add('doc-builder', function(Y) { var self = this; opts.meta.files = []; Y.each(this.data.files, function(v) { - if (v.external) { return } + if (v.external) { return; } opts.meta.files.push({ displayName: v.name, name: self.filterFileName(v.name), path: v.path || v.name }); }); var tree = {}; var files = []; Y.each(this.data.files, function(v) { - if (v.external) { return } + if (v.external) { return; } files.push(v.name); }); files.sort(); @@ -610,7 +611,7 @@ YUI.add('doc-builder', function(Y) { if (a.file && a.line && !self.options.nocode) { a.foundAt = '../files/' + self.filterFileName(a.file) + '.html#l' + a.line; if (a.path) { - a.foundAt = a.path + '#l' + a.line; + a.foundAt = a.path + '#l' + a.line; } } return a; @@ -724,14 +725,14 @@ YUI.add('doc-builder', function(Y) { }, - _resolveUrl: function(url, opts) { - if(!url) { + _resolveUrl: function(url, opts) { + if (!url) { return null; } if ( url.indexOf("://") >= 0 ) { return url; } - return path.join(opts.meta.projectRoot,url); + return path.join(opts.meta.projectRoot, url); }, /** @@ -781,9 +782,9 @@ YUI.add('doc-builder', function(Y) { render: function(source, view, layout, partials, callback) { var html = []; - function buffer(line) { - html.push(line); - } + // function buffer(line) { + // html.push(line); + // } // Allow callback as third or fourth param. if (typeof partials === 'function') { @@ -810,7 +811,7 @@ YUI.add('doc-builder', function(Y) { } else { _v[k] = view[k]; } - }; + } html = TEMPLATE(_v); //html = html.replace(/{{//g, '{{/'); @@ -864,7 +865,7 @@ YUI.add('doc-builder', function(Y) { Y.Files.writeFile(path.join(self.options.outdir, 'index.html'), html, stack.add(noop)); })); - stack.done(function(html, view) { + stack.done(function(/* html, view */) { Y.log('Writing index.html', 'info', 'builder'); cb(stack.html, stack.view); }); @@ -918,7 +919,7 @@ YUI.add('doc-builder', function(Y) { }); data.example = e; } else { - data.example = self._parseCode(self.markdown(i.example)); + data.example = self._parseCode(self.markdown(data.example)); } opts.meta.example = data.example; } @@ -945,7 +946,6 @@ YUI.add('doc-builder', function(Y) { stack.done(function() { cb(stack.html, stack.view); }); - }, /** * Generates the module files under "out"/modules/ @@ -967,12 +967,16 @@ YUI.add('doc-builder', function(Y) { }); Y.log('Rendering and writing ' + counter + ' modules pages.', 'info', 'builder'); Y.each(self.data.modules, function(v) { - if (v.external) { return } + if (v.external) { return; } self.renderModule(function(html, view) { stack.html.push(html); stack.view.push(view); if (self.options.dumpview) { - Y.Files.writeFile(path.join(self.options.outdir, 'json', 'module_' + v.name + '.json'), JSON.stringify(view), stack.add(noop)); + Y.Files.writeFile( + path.join(self.options.outdir, 'json', 'module_' + v.name + '.json'), + JSON.stringify(view), + stack.add(noop) + ); } Y.Files.writeFile(path.join(self.options.outdir, 'modules', v.name + '.html'), html, stack.add(noop)); }, v, layout); @@ -991,7 +995,7 @@ YUI.add('doc-builder', function(Y) { */ hasProperty: function(a, b) { var other = false; - var h = Y.some(a, function(i, k) { + Y.some(a, function (i, k) { if ((i.itemtype === b.itemtype) && (i.name === b.name)) { other = k; return true; @@ -1032,16 +1036,17 @@ YUI.add('doc-builder', function(Y) { //console.error(v.class, '==', info.extends); if (hasItems[v.class]) { if (!v.static) { - var override = self.hasProperty(classItems, v); + var q, + override = self.hasProperty(classItems, v); if (override === false) { //This method was extended from the parent class but not over written //console.error('Merging extends from', v.class, 'onto', info.name); - var q = Y.merge({}, v); + q = Y.merge({}, v); q.extended_from = v.class; classItems.push(q); } else { //This method was extended from the parent and overwritten in this class - var q = Y.merge({}, v); + q = Y.merge({}, v); q = self.augmentData(q); classItems[override].overwritten_from = q; } @@ -1120,10 +1125,10 @@ YUI.add('doc-builder', function(Y) { i = self.augmentData(i); i.paramsList = []; if (i.params) { - i.params.forEach(function(p, v) { + i.params.forEach(function(p) { var name = p.name; if (p.optional) { - name = '[' + name + ((p.optdefault) ? '=' + p.optdefault : '') + ']' + name = '[' + name + ((p.optdefault) ? '=' + p.optdefault : '') + ']'; } i.paramsList.push(name); }); @@ -1137,9 +1142,9 @@ YUI.add('doc-builder', function(Y) { i.paramsList = ' '; } i.returnType = ' '; - if (i.return) { + if (i["return"]) { i.hasReturn = true; - i.returnType = i.return.type; + i.returnType = i["return"].type; } //console.error(i); opts.meta.is_constructor = [i]; @@ -1157,15 +1162,16 @@ YUI.add('doc-builder', function(Y) { } classItems.forEach(function(i) { + var e; switch (i.itemtype) { case 'method': i = self.augmentData(i); i.paramsList = []; if (i.params && i.params.forEach) { - i.params.forEach(function(p, v) { + i.params.forEach(function(p) { var name = p.name; if (p.optional) { - name = '[' + name + ((p.optdefault) ? '=' + p.optdefault : '') + ']' + name = '[' + name + ((p.optdefault) ? '=' + p.optdefault : '') + ']'; } i.paramsList.push(name); }); @@ -1174,7 +1180,7 @@ YUI.add('doc-builder', function(Y) { i.methodDescription = self._parseCode(i.description); if (i.example && i.example.length) { if (i.example.forEach) { - var e = ''; + e = ''; i.example.forEach(function(v) { e += self._parseCode(self.markdown(v)); }); @@ -1191,9 +1197,9 @@ YUI.add('doc-builder', function(Y) { i.paramsList = ' '; } i.returnType = ' '; - if (i.return) { + if (i["return"]) { i.hasReturn = true; - i.returnType = i.return.type; + i.returnType = i["return"].type; } // If this item is provided by a module other @@ -1219,7 +1225,7 @@ YUI.add('doc-builder', function(Y) { } if (i.example && i.example.length) { if (i.example.forEach) { - var e = ''; + e = ''; i.example.forEach(function(v) { e += self._parseCode(self.markdown(v)); }); @@ -1258,7 +1264,7 @@ YUI.add('doc-builder', function(Y) { if (i.example && i.example.length) { if (i.example.forEach) { - var e = ''; + e = ''; i.example.forEach(function(v) { e += self._parseCode(self.markdown(v)); }); @@ -1286,7 +1292,7 @@ YUI.add('doc-builder', function(Y) { if (i.example && i.example.length) { if (i.example.forEach) { - var e = ''; + e = ''; i.example.forEach(function(v) { e += self._parseCode(self.markdown(v)); }); @@ -1362,12 +1368,16 @@ YUI.add('doc-builder', function(Y) { }); Y.log('Rendering and writing ' + counter + ' class pages.', 'info', 'builder'); Y.each(self.data.classes, function(v) { - if (v.external) { return } + if (v.external) { return; } self.renderClass(stack.add(function(html, view) { stack.html.push(html); stack.view.push(view); if (self.options.dumpview) { - Y.Files.writeFile(path.join(self.options.outdir, 'json', 'classes_' + v.name + '.json'), JSON.stringify(view), stack.add(noop)); + Y.Files.writeFile( + path.join(self.options.outdir, 'json', 'classes_' + v.name + '.json'), + JSON.stringify(view), + stack.add(noop) + ); } Y.Files.writeFile(path.join(self.options.outdir, 'classes', v.name + '.html'), html, stack.add(noop)); }), v, layout); @@ -1396,7 +1406,7 @@ YUI.add('doc-builder', function(Y) { ret = -1; } if (an > bn) { - ret = 1 + ret = 1; } return ret; }, @@ -1420,7 +1430,7 @@ YUI.add('doc-builder', function(Y) { }); Y.log('Rendering and writing ' + counter + ' source files.', 'info', 'builder'); Y.each(self.data.files, function(v) { - if (v.external) { return } + if (v.external) { return; } self.renderFile(stack.add(function(html, view, data) { if (!view || !data) { return; @@ -1428,9 +1438,17 @@ YUI.add('doc-builder', function(Y) { stack.html.push(html); stack.view.push(view); if (self.options.dumpview) { - Y.Files.writeFile(path.join(self.options.outdir, 'json', 'files_' + self.filterFileName(data.name) + '.json'), JSON.stringify(view), stack.add(noop)); + Y.Files.writeFile( + path.join(self.options.outdir, 'json', 'files_' + self.filterFileName(data.name) + '.json'), + JSON.stringify(view), + stack.add(noop) + ); } - Y.Files.writeFile(path.join(self.options.outdir, 'files', self.filterFileName(data.name) + '.html'), html, stack.add(noop)); + Y.Files.writeFile( + path.join(self.options.outdir, 'files', self.filterFileName(data.name) + '.html'), + html, + stack.add(noop) + ); }), v, layout); }); stack.done(function() { @@ -1513,7 +1531,7 @@ YUI.add('doc-builder', function(Y) { */ renderAPIMeta: function(cb) { - var opts = { meta: {} }, self = this; + var opts = { meta: {} }; opts = this.populateClasses(opts); opts = this.populateModules(opts); @@ -1564,7 +1582,13 @@ YUI.add('doc-builder', function(Y) { if (!Y.Files.isDirectory(path.join(self.options.outdir, 'assets'))) { fs.mkdirSync(path.join(self.options.outdir, 'assets'), 0777); } - Y.Files.copyAssets([path.join(DEFAULT_THEME, 'assets'), path.join(themeDir, 'assets')], path.join(self.options.outdir, 'assets'), false, function() { + Y.Files.copyAssets([ + path.join(DEFAULT_THEME, 'assets'), + path.join(themeDir, 'assets') + ], + path.join(self.options.outdir, 'assets'), + false, + function () { var cstack = new Y.Parallel(); self.writeModules(cstack.add(function() { @@ -1594,5 +1618,5 @@ YUI.add('doc-builder', function(Y) { }); }); } - } + }; }); diff --git a/lib/cli.js b/lib/cli.js index f6d63d82..dcde47c8 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -11,14 +11,14 @@ http://yuilibrary.com/license/ * @module yuidoc */ -var Y = require('./index'), - path = require('path'); +/*global Y:true */ +var Y = require('./index'); var options = Y.Options(Y.Array(process.argv, 2)); Y.log('Starting YUIDoc@' + Y.packageInfo.version + ' using YUI@' + Y.version + ' with NodeJS@' + process.versions.node, 'info', 'yuidoc'); -var starttime = (new Date).getTime(); +var starttime = (new Date()).getTime(); options = Y.Project.init(options); @@ -42,7 +42,7 @@ if (options.server) { if (!options.parseOnly) { var builder = new Y.DocBuilder(options, json); builder.compile(function() { - var endtime = (new Date).getTime(); + var endtime = (new Date()).getTime(); Y.log('Completed in ' + ((endtime - starttime) / 1000) + ' seconds' , 'info', 'yuidoc'); }); } diff --git a/lib/docparser.js b/lib/docparser.js index 435cfef5..37974571 100644 --- a/lib/docparser.js +++ b/lib/docparser.js @@ -7,7 +7,6 @@ YUI.add('docparser', function(Y) { var Lang = Y.Lang, trim = Lang.trim, - stringify = Y.JSON.stringify, fixType = Y.Lang.fixType, /** * Parses the JSON data and formats it into a nice log string for filename and line number: @@ -248,7 +247,7 @@ YUI.add('docparser', function(Y) { return; } - var type, name, optional, optdefault, parent, multiple, len, + var type, name, parts, optional, optdefault, parent, multiple, len, result, desc = implodeString(trim(value)), match = REGEX_TYPE.exec(desc), host = target.params; @@ -287,7 +286,7 @@ YUI.add('docparser', function(Y) { len = name.length - 1; - if (name.charAt(len) == '*') { + if (name.charAt(len) === '*') { multiple = true; name = name.substr(0, len); } @@ -304,10 +303,10 @@ YUI.add('docparser', function(Y) { name = parts[0]; optdefault = parts[1]; //Add some shortcuts for object/array defaults - if (optdefault.toLowerCase() == 'object') { + if (optdefault.toLowerCase() === 'object') { optdefault = '{}'; } - if (optdefault.toLowerCase() == 'array') { + if (optdefault.toLowerCase() === 'array') { optdefault = '[]'; } } @@ -319,7 +318,7 @@ YUI.add('docparser', function(Y) { match = name.split('.'); parent = trim(match[0]); Y.each(target.params, function(param) { - if (param.name == parent) { + if (param.name === parent) { param.props = param.props || []; host = param.props; match.shift(); @@ -364,9 +363,8 @@ YUI.add('docparser', function(Y) { if (multiple) { result.multiple = true; } - host.push(result); - + host.push(result); }, // @return {type} description // methods @@ -416,24 +414,22 @@ YUI.add('docparser', function(Y) { this.set(CURRENT_MODULE, value); var go = true; Y.some(block, function(o) { - if (trim(o.tag) == 'submodule') { + if (trim(o.tag) === 'submodule') { go = false; return true; } }); if (go) { if (!this.get(MAIN_MODULE)) { - var o = { + this.set(MAIN_MODULE, { tag: tagname, name: value, file: target.file, line: target.line, description: target.description - }; - this.set(MAIN_MODULE, o); + }); } - host = this.modules[value]; - return host; + return this.modules[value]; } return null; }, @@ -444,7 +440,7 @@ YUI.add('docparser', function(Y) { o.mainName = value; o.tag = tagname; o.itemtype = 'main'; - o._main = true; + o._main = true; this.set(MAIN_MODULE, o); }, @@ -477,7 +473,7 @@ YUI.add('docparser', function(Y) { // A key bock type for declaring classes, subsequent // member blocks will be assigned to this class 'class': function(tagname, value, target, block) { - var _namespace, _value = value; + var namespace, fullname, host, parent; block.forEach(function(def) { if (def.tag === 'namespace') { @@ -485,21 +481,22 @@ YUI.add('docparser', function(Y) { var name = trim(def.value) + '.' + value; if (value.indexOf(trim(def.value) + '.') === -1) { value = name; - _namespace = trim(def.value); + namespace = trim(def.value); } } }); - if (_namespace) { - this.set(CURRENT_NAMESPACE, _namespace); + if (namespace) { + this.set(CURRENT_NAMESPACE, namespace); } this.set(CURRENT_CLASS, value); - var fullname = this.get(CURRENT_CLASS); - var host = this.classes[fullname], - parent = this.get(CURRENT_MODULE); - if (_namespace) { - host.namespace = _namespace; + fullname = this.get(CURRENT_CLASS); + host = this.classes[fullname]; + parent = this.get(CURRENT_MODULE); + + if (namespace) { + host.namespace = namespace; } if (parent) { host.module = parent; @@ -521,17 +518,18 @@ YUI.add('docparser', function(Y) { 'const': function(tagname, value, target, block) { target.itemtype = 'property'; target.name = value; + /*jshint sub:true */ target['final'] = ''; }, // supported classitems 'property': function(tagname, value, target, block) { - var match, name, desc; + var match, name, desc, type; target.itemtype = tagname; target.name = value; if (!target.type) { - desc = implodeString(trim(value)), + desc = implodeString(trim(value)); match = REGEX_TYPE.exec(desc); // Extract {type} @@ -597,7 +595,7 @@ YUI.add('docparser', function(Y) { var e = value; block.forEach(function(v) { - if (v.tag == 'example') { + if (v.tag === 'example') { if (v.value.indexOf(value) > -1) { e = v.value; } @@ -609,7 +607,6 @@ YUI.add('docparser', function(Y) { 'url': 'todo', 'icon': 'todo', 'see': 'todo', - 'throws': 'todo', 'requires': 'todo', 'knownissue': 'todo', 'uses': 'todo', @@ -639,26 +636,30 @@ YUI.add('docparser', function(Y) { //Shortcut this if namespace is an empty string. return; } - var file = this.get(CURRENT_FILE); + var m, + mod, + name, + lastNS, + file = this.get(CURRENT_FILE); if (file) { this.files[file].namespaces[value] = 1; } - var mod = this.get(CURRENT_MODULE); + mod = this.get(CURRENT_MODULE); if (mod) { this.modules[mod].namespaces[value] = 1; } - var mod = this.get(CURRENT_SUBMODULE); + mod = this.get(CURRENT_SUBMODULE); if (mod) { this.modules[mod].namespaces[value] = 1; } - var mod = this.get(CURRENT_CLASS); + mod = this.get(CURRENT_CLASS); if (mod) { - var lastNS = this.get('lastnamespace'); + lastNS = this.get('lastnamespace'); if (lastNS && lastNS !== value && (value.indexOf(lastNS + '.') !== 0)) { if (this.classes[mod]) { - var m = this.classes[mod]; + m = this.classes[mod]; delete this.classes[mod]; mod = value + '.' + mod.replace(lastNS + '.', ''); m.name = mod; @@ -674,17 +675,17 @@ YUI.add('docparser', function(Y) { } if (mod.indexOf(value + '.') === -1) { if (mod.indexOf('.') === -1) { - var m = this.classes[mod]; + m = this.classes[mod]; delete this.classes[mod]; - var name = m.namespace + '.' + m.name; + name = m.namespace + '.' + m.name; m.name = name; this.classes[name] = m; this.set(CURRENT_CLASS, name); } else { if (mod.indexOf(this.classes[mod].namespace + '.') === -1) { - var m = this.classes[mod]; + m = this.classes[mod]; delete this.classes[mod]; - var name = m.namespace + '.' + m.shortname; + name = m.namespace + '.' + m.shortname; m.name = name; this.classes[name] = m; this.set(CURRENT_CLASS, name); @@ -698,22 +699,27 @@ YUI.add('docparser', function(Y) { // updates the current class only (doesn't create // a new class definition) 'for': function(tagname, value, target, block) { + var ns, file, mod; + value = this._resolveFor(value); this.set(CURRENT_CLASS, value); - var ns = ((this.classes[value]) ? this.classes[value].namespace : ''); + + ns = ((this.classes[value]) ? this.classes[value].namespace : ''); this.set(CURRENT_NAMESPACE, ns); - var file = this.get(CURRENT_FILE); + + file = this.get(CURRENT_FILE); if (file) { this.files[file].fors[value] = 1; } - var mod = this.get(CURRENT_MODULE); + + mod = this.get(CURRENT_MODULE); if (mod) { this.modules[mod].fors[value] = 1; } - var mod = this.get(CURRENT_SUBMODULE); + mod = this.get(CURRENT_SUBMODULE); if (mod) { - this.modules[mod].fors[value]; + this.modules[mod].fors[value] = 1; } } @@ -838,10 +844,10 @@ YUI.add('docparser', function(Y) { if (!o) { return; } - //console.log('Main Module Setter: ', o); + //console.log('Main Module Setter: ', o); var write = true, name = o.mainName || o.name; - if (this.get(CURRENT_MODULE) === name) { + if (this.get(CURRENT_MODULE) === name) { if (name in this.modules) { //console.log('In Global Modules', this.modules[name]); @@ -852,12 +858,12 @@ YUI.add('docparser', function(Y) { } } if (write) { - //console.log('Writing'); + //console.log('Writing'); this.modules[name] = Y.merge(this.modules[name], o); } } else { if (o._main) { - //console.log('Writing'); + //console.log('Writing'); this.modules[name] = o; } } @@ -875,13 +881,18 @@ YUI.add('docparser', function(Y) { return val; } val = trim(val); + + var modMain, clazz; + this.set(CURRENT_SUBMODULE, ''); this.set(CURRENT_NAMESPACE, ''); - var m = this.get(MAIN_MODULE); - if (m && m.name !== val) { - this.set(MAIN_MODULE, ''); - } - var clazz = this.classes[this.get(CURRENT_CLASS)]; + + modMain = this.get(MAIN_MODULE); + if (modMain && modMain.name !== val) { + this.set(MAIN_MODULE, ''); + } + + clazz = this.classes[this.get(CURRENT_CLASS)]; if (clazz) { //Handles case where @module comes after @class in a new directory of files if (clazz.module !== val) { @@ -903,6 +914,7 @@ YUI.add('docparser', function(Y) { } } } + if (!(val in this.modules)) { this.modules[val] = { name: val, @@ -912,6 +924,7 @@ YUI.add('docparser', function(Y) { namespaces: {} }; } + return val; } }, @@ -968,18 +981,22 @@ YUI.add('docparser', function(Y) { } this.set('lastclass', this.get(CURRENT_CLASS)); val = trim(val); + var name = val, + ns, clazz; if (!(val in this.classes)) { - var ns = this.get(CURRENT_NAMESPACE), - name = (ns && ns !== '' && (val.indexOf(ns + '.') !== 0)) ? ns + '.' + val : val, - clazz = this.classes[name] = { - name: name, - shortname: val, - classitems: [], - plugins: [], - extensions: [], - plugin_for: [], - extension_for: [] - }; + ns = this.get(CURRENT_NAMESPACE); + if (ns && ns !== '' && (val.indexOf(ns + '.') !== 0)) { + name = ns + '.' + name; + } + clazz = this.classes[name] = { + name: name, + shortname: val, + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [] + }; clazz.module = this.get(CURRENT_MODULE); if (this.get(CURRENT_SUBMODULE)) { clazz.submodule = this.get(CURRENT_SUBMODULE); @@ -1104,20 +1121,21 @@ YUI.add('docparser', function(Y) { var lines = comment.split(REGEX_LINES), len = lines.length, i, parts, part, peek, skip, + tag, value, results = [{tag: 'file', value: file}, {tag: 'line', value: line}], syntaxtype = this.get('syntaxtype'), lineHeadCharRegex = REGEX_LINE_HEAD_CHAR[syntaxtype], hasLineHeadChar = lines[0] && lineHeadCharRegex.test(lines[0]); -// trim leading line head char(star or harp) if there are any + // trim leading line head char(star or harp) if there are any if (hasLineHeadChar) { for (i = 0; i < len; i++) { lines[i] = lines[i].replace(lineHeadCharRegex, ''); } } -// reconsitute and tokenize the comment block + // reconsitute and tokenize the comment block comment = this.unindent(lines.join('\n')); parts = comment.split(/(?:^|\n)\s*(@\w*)/); len = parts.length; @@ -1129,7 +1147,7 @@ YUI.add('docparser', function(Y) { } skip = false; -// the first token may be the description, otherwise it should be a tag + // the first token may be the description, otherwise it should be a tag if (i === 0 && part.substr(0, 1) !== '@') { if (part) { tag = '@description'; @@ -1174,11 +1192,11 @@ YUI.add('docparser', function(Y) { extract: function(filemap, dirmap) { filemap = filemap || this.get('filemap'); dirmap = dirmap || this.get('dirmap'); - var syntaxtype = this.get('syntaxtype'); - var commentmap = {}; + var syntaxtype = this.get('syntaxtype'), + commentmap = {}; Y.each(filemap, function(code, filename) { - var commentlines, comment, + var commentlines, comment, line, lines = code.split(REGEX_LINES), len = lines.length, i, linenum; @@ -1219,17 +1237,15 @@ YUI.add('docparser', function(Y) { */ processblock: function(block) { var target = {}, - clazz, - module, - submodule, digestname, digester, host; + // Y.log(block); - Y.each(block, function(tag) { + Y.each(block, function (tag) { var name = trim(tag.tag), value = trim(tag.value), - parent, ret; + ret; //Convert empty values to a 1 for JSON data parsing later if (SHORT_TAGS[name] && value === '') { @@ -1266,7 +1282,6 @@ YUI.add('docparser', function(Y) { target[name] = value; } } - }, this); if (host) { @@ -1275,10 +1290,12 @@ YUI.add('docparser', function(Y) { this.classitems.push(target); target['class'] = this.get(CURRENT_CLASS); target.module = this.get(CURRENT_MODULE); + host = this.get(CURRENT_SUBMODULE); if (host) { target.submodule = host; } + host = this.get(CURRENT_NAMESPACE); if (host) { target.namespace = host; @@ -1300,28 +1317,29 @@ YUI.add('docparser', function(Y) { files = self.files = {}, modules = self.modules = {}, classes = self.classes = {}, - classitems = self.classitems = [], - data = self.data = { - project: project, - files: files, - modules: modules, - classes: classes, - classitems: classitems - }; + classitems = self.classitems = []; + + self.data = { + project: project, + files: files, + modules: modules, + classes: classes, + classitems: classitems + }; commentmap = commentmap || self.commentmap; // process - Y.each(commentmap, function(blocks, file) { + Y.each(commentmap, function (blocks, file) { //Y.log('transform: ' + file, 'info', 'docparser'); self.set(CURRENT_FILE, file); - Y.each(blocks, function(block) { + Y.each(blocks, function (block) { self.processblock(block); }); }); // cross reference - Y.each(modules, function(module, name) { + Y.each(modules, function (module, name) { if (module.file) { files[module.file].modules[name] = 1; } @@ -1333,7 +1351,7 @@ YUI.add('docparser', function(Y) { delete module._main; }); - Y.each(classes, function(clazz, name) { + Y.each(classes, function (clazz, name) { if (clazz.module) { modules[clazz.module].classes[name] = 1; } @@ -1369,7 +1387,7 @@ YUI.add('docparser', function(Y) { } }); - Y.each(classitems, function(v) { + Y.each(classitems, function (v) { if (!v.itemtype) { self.warnings.push({ message: 'Missing item type' + (v.description ? '\n' + v.description : ''), @@ -1390,7 +1408,7 @@ YUI.add('docparser', function(Y) { } }); - Y.each(modules, function(mod) { + Y.each(modules, function (mod) { if (!mod.file || !mod.line || !mod.name) { console.log('Failed to find lines for', mod); } @@ -1417,5 +1435,5 @@ YUI.add('docparser', function(Y) { Y.DocParser = DocParser; -}, '0.1.0', { requires: ['base-base', 'json-stringify'] }); +}, '0.1.0', { requires: ['base-base'] }); diff --git a/lib/files.js b/lib/files.js index a9a033b6..d27abf23 100644 --- a/lib/files.js +++ b/lib/files.js @@ -15,20 +15,18 @@ Copyright (c) 2011 Yahoo! Inc. Licensed under the BSD License. */ -var fs = require('graceful-fs'); - fsPath = require('path'), +var fs = require('graceful-fs'), + fsPath = require('path'), useFS = (fs.exists) ? fs : fsPath; - - -var exists = function(file, cb) { +function exists(file, cb) { if (cb) { useFS.exists(file, cb); } else { return useFS.existsSync(file); } -}; +} Y.Files.exists = exists; @@ -96,6 +94,7 @@ function copyDirectory(source, dest, overwrite, callback) { if (!pending) { return callback(); } while ((filename = files.shift())) { + /*jshint loopfunc:true */ copyPath(fsPath.join(source, filename), fsPath.join(dest, filename), overwrite, function (err) { if (err) { return callback(err); } @@ -177,8 +176,7 @@ if they already exist. @param {Error} callback.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') { @@ -235,23 +233,25 @@ Check to see if this is a directory @return {Boolean} True if it is a directory **/ function isDirectory(path, link) { - var i = false; + var stat, + result = false; + link = (link === false) ? false : true; + try { - var stat = fs.lstatSync(path); - + stat = fs.lstatSync(path); if (stat) { if (stat.isSymbolicLink() && link) { stat = fs.statSync(path); } - i = stat.isDirectory(); + result = stat.isDirectory(); } } catch (e) { - i = false; + result = false; } - return i; -}; + return result; +} Y.Files.isDirectory = isDirectory; @@ -263,21 +263,22 @@ Check to see if this is a File @return {Boolean} True if it is a file **/ function isFile(path, link) { - var i = false; + var stat, + result = false; + try { - var stat = fs.lstatSync(path); - + stat = fs.lstatSync(path); if (stat) { if (stat.isSymbolicLink() && link) { stat = fs.statSync(path); } - i = stat.isFile(); + result = stat.isFile(); } } catch (e) { - i = false; + result = false; } - return i; + return result; } Y.Files.isFile = isFile; @@ -368,7 +369,7 @@ function copyAssets() { copyPath(from[0], to, true, function() { if (isDirectory(from[1])) { - copyPath(from[1], to, true, callback) + copyPath(from[1], to, true, callback); } else { callback(); } @@ -393,7 +394,7 @@ Y.Files.getJSON = function(filename) { var data = {}; if (exists(filename)) { data = JSON.parse(fs.readFileSync(filename, 'utf8')); - }; + } return data; }; @@ -405,46 +406,47 @@ Y.Files.getJSON = function(filename) { * @param {Callback} callback* */ -var writeFileTimer = 100, - readFileTimer = 100; +function writeFile(file, data, cb) { + var out, + args = arguments, + flags = { + flags: "w", encoding: Y.charset, mode: 0644 + }; -var writeFile = function(file, data, cb) { - var flags = { - flags: "w", encoding: Y.charset, mode: 0644 - } - var args = arguments; if (cb) { fs.writeFile(file, data, flags, function(err) { if (err && err.message.match(/^EMFILE, Too many open files/)) { Y.log('Writefile failed, too many open files (' + args[0] + '). Trying again.', 'warn', 'files'); - writeFileTimer++; - Y.later(writeFileTimer, Y, writeFile, args); + writeFile.timer++; + Y.later(writeFile.timer, Y, writeFile, args); return; } cb(); }); } else { - var out = fs.createWriteStream(file, flags); + out = fs.createWriteStream(file, flags); out.write(data); out.end(); } -}; +} +writeFile.timer = 100; Y.Files.writeFile = writeFile; -var readFile = function(file, enc, cb) { +function readFile(file, enc, cb) { var args = arguments; fs.readFile(file, enc, function(err, data) { if (err && err.message.match(/^EMFILE, Too many open files/)) { Y.log('Readfile failed, too many open files (' + args[0] + '). Trying again.', 'warn', 'files'); - readFileTimer++; - Y.later(readFileTimer, Y, readFile, args); + readFile.timer++; + Y.later(readFile.timer, Y, readFile, args); return; } cb(err, data); }); -}; +} +readFile.timer = 100; Y.Files.readFile = readFile; diff --git a/lib/help.js b/lib/help.js index 3de4dd5a..e2b3731a 100644 --- a/lib/help.js +++ b/lib/help.js @@ -74,5 +74,5 @@ YUI.add('help', function(Y) { Y.showHelp = function() { console.error(Y.renderHelp()); process.exit(0); //Shouldn't exit one on help - } + }; }); diff --git a/lib/index.js b/lib/index.js index c6bd6a49..9f676c53 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://yuilibrary.com/license/ */ +/*global YUI:true, Y:true */ /** Module creates the YUI instance with the required modules, uses them and exports the **Y** to be used by the _CLI class_ or by extenders: `require('yuidocjs');` @@ -44,7 +45,7 @@ process.on('uncaughtException', function(msg) { inst.applyConfig({ debug: true, useColor: useColor - }); + }); inst.log('--------------------------------------------------------------------------', 'error'); inst.log('An uncaught YUIDoc error has occurred, stack trace given below', 'error'); diff --git a/lib/options.js b/lib/options.js index 1b262d43..dec5caca 100644 --- a/lib/options.js +++ b/lib/options.js @@ -15,7 +15,8 @@ YUI.add('options', function(Y) { * @return {Object} The config object */ Y.Options = function(args) { - + /*jshint onevar:false */ + var options = { port: 3000, nocode: false diff --git a/lib/project.js b/lib/project.js index c66f31d7..12300077 100644 --- a/lib/project.js +++ b/lib/project.js @@ -47,6 +47,7 @@ YUI.add('project', function(Y) { } if (typeof options.tabtospace === 'number') { + /*jshint onevar:false */ options.tabspace = ''; for (var s = 0; s < options.tabtospace; s++) { options.tabspace += ' '; diff --git a/lib/server.js b/lib/server.js index 907ea6b6..a47af3db 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,12 +1,12 @@ YUI.add('server', function(Y) { - - var path = require('path'); + + var path = require('path'), /** * Provides the `--server` server option for YUIDoc * @class Server * @module yuidoc */ - var Server = { + Server = { /** * Cache for external mixed in data. * @property _externalData @@ -81,8 +81,7 @@ YUI.add('server', function(Y) { app.get('*', function(req, res) { var type = req.url.split('/')[1], - oType = type; - var html = ['

Item Not Found in internal meta-data

']; + html = ['

Item Not Found in internal meta-data

']; if (type === 'class') { type = 'classes'; @@ -110,8 +109,8 @@ YUI.add('server', function(Y) { * @param {Response} res Express response object */ files: function(req, res, next) { - var fileName = req.params.file; - var data; + var fileName = req.params.file, + data; Object.keys(Server.builder.data.files).forEach(function(file) { if (fileName === Server.builder.filterFileName(file)) { data = Server.builder.data.files[file]; @@ -179,12 +178,13 @@ YUI.add('server', function(Y) { */ init: function() { var express = require('express'), - path = require('path'); + path = require('path'), + stat; Server.app = express(); //console.log(Server.options); - var stat = Server.options.themedir || path.join(__dirname, '../', 'themes', 'default'); + stat = Server.options.themedir || path.join(__dirname, '../', 'themes', 'default'); Server.app.use(express.static(stat)); Server.routes(); Server.app.listen(Server.options.port); @@ -209,9 +209,12 @@ YUI.add('server', function(Y) { if (Server.options.external) { Y.log('Fetching external data, this may take a minute', 'warn', 'server'); - var json = (new Y.YUIDoc(Server.options)).run(); + var json, builder; + + json = (new Y.YUIDoc(Server.options)).run(); Server.options = Y.Project.mix(json, Server.options); - var builder = new Y.DocBuilder(Server.options, json); + + builder = new Y.DocBuilder(Server.options, json); builder.mixExternal(function() { Y.log('External data fetched, launching server..', 'info', 'server'); Server._externalData = builder.options.externalData; diff --git a/lib/utils.js b/lib/utils.js index 251538e8..ec2850d7 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -3,8 +3,8 @@ Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://yuilibrary.com/license/ */ +/*jshint onevar:false */ var path = require('path'), - util = require('util'), minimatch = require('minimatch'), fs = require('graceful-fs'); @@ -143,9 +143,9 @@ Mix/merge/munge data into the template. @param {Object} callback.options Merged options. **/ function prepare(inDirs, options, callback) { - var compiled = {}, - meta = {}, - type = 'project'; + var layouts, + partials, + type = 'project'; if (options && options.skipLoad) { // Skip loading layouts, metadata, pages, and partials and assume that @@ -234,6 +234,7 @@ var getProjectData = function(dir) { // * there are no more dirs to process // * we abort due to failsafe while (dirs.length && !projectData) { + /*jshint loopfunc:true */ if (dirCount++ > 5000) { Y.log('Scanned ' + dirCount + ' directories looking for a yuidoc.json file, something is probably wrong here..', 'error', 'yuidoc'); process.exit(1); diff --git a/lib/yuidoc.js b/lib/yuidoc.js index ff7827c1..f923f199 100755 --- a/lib/yuidoc.js +++ b/lib/yuidoc.js @@ -156,7 +156,7 @@ YUI.add('yuidoc', function(Y) { } var allfiles = fs.readdirSync(dir), stats, files = [], fullpath, self = this; - + if (dir in self.options.excludes) { return; } @@ -188,7 +188,7 @@ YUI.add('yuidoc', function(Y) { */ parsefiles: function(dir, files) { var self = this; - files = files.sort(); + files = files.sort(); Y.each(files, function(filename) { var ext = path.extname(filename), text, fullpath; @@ -221,7 +221,7 @@ YUI.add('yuidoc', function(Y) { //Y.log('Checking for Selleck data: ' + comp, 'info', 'yuidoc'); if (Y.Files.exists(comp)) { try { - var json = JSON.parse(fs.readFileSync(comp, 'utf8')); + json = JSON.parse(fs.readFileSync(comp, 'utf8')); delete json.examples; //Remove the selleck example data, we only want the comp info self.selleck[fullpath] = json; } catch (e) { @@ -239,7 +239,9 @@ YUI.add('yuidoc', function(Y) { */ writeJSON: function(parser) { var self = this, - data; + data, + file, + out; data = parser.data; @@ -271,7 +273,7 @@ YUI.add('yuidoc', function(Y) { if (self.options.writeJSON) { // Y.log(Y.JSON.stringify(parser.data, null, 4)); - var file = path.join(self.options.outdir, 'data.json'), out; + file = path.join(self.options.outdir, 'data.json'); if (Y.Files.exists(self.options.outdir) && !self.options.nodeleteout) { Y.log('Found out dir, deleting: ' + self.options.outdir, 'warn', 'yuidoc'); rimraf.sync(self.options.outdir); @@ -322,15 +324,13 @@ YUI.add('yuidoc', function(Y) { Y.log('YUIDoc Starting from: ' + this.options.paths.join(','), 'info', 'yuidoc'); this.starttime = new Date().getTime(); - var self = this; - this._processConfig(); this.walk(); var json = this.writeJSON(new Y.DocParser({ - syntaxtype: self.options.syntaxtype, - filemap: self.filemap, - dirmap: self.dirmap + syntaxtype: this.options.syntaxtype, + filemap: this.filemap, + dirmap: this.dirmap }).parse()); if (this.options.lint) { diff --git a/tests/builder.js b/tests/builder.js index 628699dd..171f3582 100644 --- a/tests/builder.js +++ b/tests/builder.js @@ -1,6 +1,6 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, - ArrayAssert = YUITest.ArrayAssert, path = require('path'), fs = require('fs'), Y = require(path.join(__dirname, '../', 'lib', 'index')); @@ -23,8 +23,9 @@ var suite = new YUITest.TestSuite({ return ret; }, setUp: function() { - var test = this; - var options = { + var options, json, builder; + + options = { quiet: true, paths: [ 'input/' ], outdir: './out', @@ -35,12 +36,12 @@ var suite = new YUITest.TestSuite({ langPrefix: "language-" } }; - var json = (new Y.YUIDoc(options)).run(); + json = (new Y.YUIDoc(options)).run(); this.project = json.project; this.data = json; - var builder = new Y.DocBuilder(options, json); + builder = new Y.DocBuilder(options, json); builder.compile(function() { suite._setupComplete = true; }); @@ -62,8 +63,8 @@ suite.add(new YUITest.TestCase({ so I have to check it in the first test to make sure my async task in the setup is complete before I can test against it. */ - var test = this; - var timer = setInterval(function() { + var test = this, + timer = setInterval(function() { if (suite._setupComplete) { clearInterval(timer); test.resume(function() { @@ -91,40 +92,39 @@ suite.add(new YUITest.TestCase({ }, 'test: index.html': function() { var p = path.join(__dirname, 'out', 'index.html'); - Assert.isTrue(exists(p), 'Failed to find: ' + p) + Assert.isTrue(exists(p), 'Failed to find: ' + p); }, 'test: data.json': function() { var p = path.join(__dirname, 'out', 'data.json'); - Assert.isTrue(exists(p), 'Failed to find: ' + p) + Assert.isTrue(exists(p), 'Failed to find: ' + p); }, 'test: api.js': function() { var p = path.join(__dirname, 'out', 'api.js'); - Assert.isTrue(exists(p), 'Failed to find: ' + p) + Assert.isTrue(exists(p), 'Failed to find: ' + p); }, 'test: classes/JSON.html': function() { var p = path.join(__dirname, 'out', 'classes', 'JSON.html'); - Assert.isTrue(exists(p), 'Failed to find: ' + p) + Assert.isTrue(exists(p), 'Failed to find: ' + p); }, 'test: files name filter': function() { var dir = path.join(__dirname, 'out', 'files'); - var files = fs.readdirSync(dir); - files.forEach(function(file) { + fs.readdirSync(dir).forEach(function(file) { Assert.isTrue(((file.indexOf('input_') ===0) || file.indexOf('index.html') === 0), 'Filed to parse: ' + file); }); }, 'test: module files': function() { var mods = this.data.modules; Object.keys(mods).forEach(function(name) { - var m = mods[name]; - var p = path.join(__dirname, 'out', 'modules', m.name + '.html'); + var m = mods[name], + p = path.join(__dirname, 'out', 'modules', m.name + '.html'); Assert.isTrue(exists(p), 'Failed to render: ' + m.name + '.html'); }); }, 'test: class files': function() { var mods = this.data.classes; Object.keys(mods).forEach(function(name) { - var m = mods[name]; - var p = path.join(__dirname, 'out', 'classes', m.name + '.html'); + var m = mods[name], + p = path.join(__dirname, 'out', 'classes', m.name + '.html'); Assert.isTrue(exists(p), 'Failed to render: ' + m.name + '.html'); }); } diff --git a/tests/files.js b/tests/files.js index e243ff1d..df132eae 100644 --- a/tests/files.js +++ b/tests/files.js @@ -1,3 +1,4 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, path = require('path'), diff --git a/tests/options.js b/tests/options.js index 81cb8d38..996a2a97 100644 --- a/tests/options.js +++ b/tests/options.js @@ -1,8 +1,7 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, - ArrayAssert = YUITest.ArrayAssert, path = require('path'), - fs = require('fs'), Y = require(path.join(__dirname, '../', 'lib', 'index')); //Move to the test dir before running the tests. @@ -236,24 +235,21 @@ suite.add(new YUITest.TestCase({ '-T', 'simple' ]); - var p = path.join(__dirname, '../themes/simple'); - Assert.areEqual(p, options.themedir); + Assert.areEqual(path.join(__dirname, '../themes/simple'), options.themedir); }, 'test: --theme simple': function() { var options = Y.Options([ '--theme', 'simple' ]); - var p = path.join(__dirname, '../themes/simple'); - Assert.areEqual(p, options.themedir); + Assert.areEqual(path.join(__dirname, '../themes/simple'), options.themedir); }, 'test: --theme foobar': function() { var options = Y.Options([ '--theme', 'foobar' ]); - var p = path.join(__dirname, '../themes/foobar'); - Assert.areEqual(p, options.themedir); + Assert.areEqual(path.join(__dirname, '../themes/foobar'), options.themedir); }, 'test: -t ./foobar': function() { var options = Y.Options([ @@ -337,7 +333,7 @@ suite.add(new YUITest.TestCase({ }, 'test --debug': function() { Assert.isFalse(Y.config.debug); - var options = Y.Options([ + Y.Options([ '--debug' ]); Assert.isTrue(Y.config.debug); @@ -347,14 +343,14 @@ suite.add(new YUITest.TestCase({ }); }, 'test: --charset': function() { - var options = Y.Options([ + Y.Options([ '--charset' ]); Assert.areEqual('utf8', Y.charset); }, 'test: --charset foo': function() { - var options = Y.Options([ + Y.Options([ '--charset', 'foo' ]); diff --git a/tests/parser.js b/tests/parser.js index 8b682e2e..3ba3d51f 100644 --- a/tests/parser.js +++ b/tests/parser.js @@ -1,3 +1,4 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, ArrayAssert = YUITest.ArrayAssert, @@ -67,28 +68,29 @@ suite.add(new YUITest.TestCase({ Assert.areSame('http://two.url', this.project.url[1], 'URL #2 is wrong'); }, 'test: files parsing': function() { - var files = this.data.files; + var files = this.data.files, + one, two, three, four; // 1 module, 3 classes - var one = files[path.normalize('input/test/anim.js')]; + one = files[path.normalize('input/test/anim.js')]; Assert.isObject(one, 'Failed to parse input/test/anim.js'); Assert.areSame(1, Object.keys(one.modules).length, '1 module should be found'); Assert.areSame(3, Object.keys(one.classes).length, '3 classes should be found'); // 2 modules, 3 classes - var two = files[path.normalize('input/test/test.js')]; + two = files[path.normalize('input/test/test.js')]; Assert.isObject(two, 'Failed to parse input/test/test.js'); Assert.areSame(2, Object.keys(two.modules).length, '2 modules should be found'); Assert.areSame(3, Object.keys(two.classes).length, '3 classes should be found'); //Module -> class association - var three = files[path.normalize('input/test2/dump/dump.js')]; + three = files[path.normalize('input/test2/dump/dump.js')]; Assert.isObject(three, 'Failed to parse input/test2/dump/dump.js'); Assert.areSame(1, three.modules.dump, 'dump module not found'); Assert.areSame(1, three.classes['YUI~dump'], 'YUI~dump class not found'); //Module -> class association - var four = files[path.normalize('input/test2/oop/oop.js')]; + four = files[path.normalize('input/test2/oop/oop.js')]; Assert.isObject(four, 'Failed to parse input/test2/oop/oop.js'); Assert.areSame(1, four.modules.oop, 'oop module not found'); Assert.areSame(1, four.classes['YUI~oop'], 'YUI~oop class not found'); @@ -123,33 +125,35 @@ suite.add(new YUITest.TestCase({ Assert.areSame('main', mod.itemtype, 'ItemType should be main'); }, 'test: submodule parsing': function() { - var mods = this.data.modules; + var mods = this.data.modules, + m, desc; //anim-easing submodule - var m = mods['anim-easing']; + m = mods['anim-easing']; Assert.isObject(m, 'Failed to parse anim-easing module'); - var desc = 'The easing module provides methods for customizing\nhow an animation behaves during each run.'; + desc = 'The easing module provides methods for customizing\nhow an animation behaves during each run.'; Assert.areSame(desc, m.description, 'Failed to parse submodule description'); Assert.areSame(0, Object.keys(m.submodules).length, 'Should have 0 submodules'); Assert.areSame(1, Object.keys(m.classes).length, 'Should have 1 class'); - Assert.areSame(1, m['is_submodule'], 'Submodule association failed'); + Assert.areSame(1, m.is_submodule, 'Submodule association failed'); Assert.areSame('anim', m.module, 'Failed to associate module'); //anim-easing-foo submodule - var m = mods['anim-easing-foo']; + m = mods['anim-easing-foo']; Assert.isObject(m, 'Failed to parse anim-easing-foo module'); - var desc = 'FOO FOO FOO FOO FOO The easing module provides methods for customizing'; + desc = 'FOO FOO FOO FOO FOO The easing module provides methods for customizing'; Assert.areSame(desc, m.description, 'Failed to parse submodule description'); Assert.areSame(0, Object.keys(m.submodules).length, 'Should have 0 submodules'); Assert.areSame(1, Object.keys(m.classes).length, 'Should have 1 class'); - Assert.areSame(1, m['is_submodule'], 'Submodule association failed'); + Assert.areSame(1, m.is_submodule, 'Submodule association failed'); Assert.areSame('anim', m.module, 'Failed to associate module'); }, 'test: extra module data parsing': function() { - var mods = this.data.modules; + var mods = this.data.modules, + m; - var m = mods.mymodule; + m = mods.mymodule; Assert.isObject(m, 'Failed to parse mymodule module'); Assert.areSame(1, Object.keys(m.submodules).length, 'Should have 1 submodules'); Assert.areSame(3, Object.keys(m.classes).length, 'Should have 3 class'); @@ -158,58 +162,59 @@ suite.add(new YUITest.TestCase({ ArrayAssert.itemsAreSame(['one', 'two'], m.requires, 'Requires parsing failed'); ArrayAssert.itemsAreSame(['three', 'four'], m.uses, 'Uses parsing failed'); - var m = mods.mysubmodule; + m = mods.mysubmodule; Assert.isObject(m, 'Failed to parse mysubmodule module'); Assert.areSame(0, Object.keys(m.submodules).length, 'Should have 0 submodules'); Assert.areSame(3, Object.keys(m.classes).length, 'Should have 3 class'); - Assert.areSame(1, m['is_submodule'], 'Submodule association failed'); + Assert.areSame(1, m.is_submodule, 'Submodule association failed'); ArrayAssert.itemsAreSame(['three', 'four'], m.category, 'Category parsing failed'); //Testing modules with slashes in them - var m = mods['myapp/views/index']; + m = mods['myapp/views/index']; Assert.isObject(m, 'Failed to parse myapp/views/index module'); Assert.areSame(1, Object.keys(m.classes).length, 'Should have 1 class'); - var m = mods['P.storage']; + m = mods['P.storage']; Assert.isObject(m, 'Failed to parse P.storage module'); ArrayAssert.itemsAreSame(['P.storage.Store', 'P.storage.LocalStore', 'P.storage'], Object.keys(m.classes), 'Failed to parse classes'); ArrayAssert.itemsAreSame(['P.storage', 'P'], Object.keys(m.namespaces), 'Namespace failed to parse'); }, 'test: class parsing': function() { - var cl = this.data.classes; + var cl = this.data.classes, + anim, easing, my, other, m; - var anim = cl.Anim; + anim = cl.Anim; Assert.isObject(anim, 'Failed to find Anim class'); Assert.areSame('Anim', anim.name, 'Failed to set name'); Assert.areSame('Anim', anim.shortname, 'Failed to set shortname'); Assert.areSame('anim', anim.module, 'Failed to test module.'); - var easing = cl.Easing; + easing = cl.Easing; Assert.isObject(easing, 'Failed to find Easing class'); Assert.areSame('Easing', easing.name, 'Failed to set name'); Assert.areSame('Easing', easing.shortname, 'Failed to set shortname'); Assert.areSame('anim', easing.module, 'Failed to test module.'); Assert.areSame('anim-easing', easing.submodule, 'Failed to test submodule.'); - var my = cl.myclass; + my = cl.myclass; Assert.isObject(my, 'Failed to find myclass class'); Assert.areSame('myclass', my.name, 'Failed to set name'); Assert.areSame('myclass', my.shortname, 'Failed to set shortname'); Assert.areSame('mymodule', my.module, 'Failed to test module.'); Assert.areSame('mysubmodule', my.submodule, 'Failed to test submodule.'); - Assert.areSame(1, my['is_constructor'], 'Failed to register constructor.'); + Assert.areSame(1, my.is_constructor, 'Failed to register constructor.'); - var other = cl.OtherClass; + other = cl.OtherClass; Assert.isObject(other, 'Failed to find myclass class'); Assert.areSame('OtherClass', other.name, 'Failed to set name'); Assert.areSame('OtherClass', other.shortname, 'Failed to set shortname'); Assert.areSame('mymodule', other.module, 'Failed to test module.'); Assert.areSame('mysubmodule', other.submodule, 'Failed to test submodule.'); - Assert.areSame(1, Object.keys(other['extension_for']).length, 'Failed to assign extension_for'); - Assert.areSame('myclass', other['extension_for'][0], 'Failed to assign extension_for'); + Assert.areSame(1, Object.keys(other.extension_for).length, 'Failed to assign extension_for'); + Assert.areSame('myclass', other.extension_for[0], 'Failed to assign extension_for'); - var m = cl['P.storage.P.storage']; + m = cl['P.storage.P.storage']; Assert.isUndefined(m, 'Should not have double namespaces'); Assert.isNotUndefined(cl['P.storage'], 'Should not have double namespaces'); @@ -218,15 +223,30 @@ suite.add(new YUITest.TestCase({ }, 'test: classitems parsing': function() { Assert.isArray(this.data.classitems, 'Failed to populate classitems array'); - - var item = this.findByName('testoptional', 'myclass'); + var keys, item, item2; + + item = this.findByName('testoptional', 'myclass'); Assert.areSame('testoptional', item.name, 'Failed to find item: testoptional'); Assert.areSame('myclass', item.class, 'Failed to find class: testoptional'); Assert.areSame('mymodule', item.module, 'Failed to find module: testoptional'); Assert.areSame('mysubmodule', item.submodule, 'Failed to find submodule: testoptional'); Assert.areSame('method', item.itemtype, 'Should be a method'); - var keys = [ 'file', 'line', 'description', 'itemtype', 'name', 'params', 'evil', 'injects', 'return', 'example', 'class', 'module', 'submodule' ]; + keys = [ + 'file', + 'line', + 'description', + 'itemtype', + 'name', + 'params', + 'evil', + 'injects', + 'return', + 'example', + 'class', + 'module', + 'submodule' + ]; ArrayAssert.itemsAreSame(keys, Object.keys(item), 'Item missing from output'); @@ -236,11 +256,12 @@ suite.add(new YUITest.TestCase({ Assert.isUndefined(item.return.type, 'Type should be missing'); Assert.areSame(2, item.example.length, 'Should have 2 example snippets'); - var item2 = this.findByName('testobjectparam', 'myclass'); + item2 = this.findByName('testobjectparam', 'myclass'); Assert.areSame('String', item2.return.type, 'Type should not be missing'); }, 'test: parameter parsing': function() { - var item = this.findByName('testoptional', 'myclass'); + var item, item2; + item = this.findByName('testoptional', 'myclass'); Assert.isArray(item.params, 'Params should be an array'); Assert.areSame(5, item.params.length, 'Failed to parse all 5 parameters'); @@ -259,14 +280,14 @@ suite.add(new YUITest.TestCase({ Assert.isTrue(item.params[4].optional, 'Parameter should be optional'); Assert.areSame('"defaultval"', item.params[4].optdefault, 'Optional Default value is incorrect'); - var item2 = this.findByName('test0ton', 'myclass'); + item2 = this.findByName('test0ton', 'myclass'); Assert.isArray(item2.params, 'Params should be an array'); Assert.areSame(1, item2.params.length, 'Failed to parse all 5 parameters'); Assert.isTrue(item2.params[0].optional, 'Optional not set'); Assert.isTrue(item2.params[0].multiple, 'Multiple not set'); Assert.isUndefined(item2.return.type, 'Type should be missing'); - var item2 = this.findByName('test1ton', 'myclass'); + item2 = this.findByName('test1ton', 'myclass'); Assert.isArray(item2.params, 'Params should be an array'); Assert.areSame(1, item2.params.length, 'Failed to parse all 5 parameters'); Assert.isUndefined(item2.params[0].optional, 'Optional should not be set'); @@ -275,8 +296,9 @@ suite.add(new YUITest.TestCase({ }, 'test: object parameters': function() { - var item = this.findByName('testobjectparam', 'myclass'); + var item, props; + item = this.findByName('testobjectparam', 'myclass'); Assert.areSame('testobjectparam', item.name, 'Failed to find item: testobjectparam'); Assert.areSame('myclass', item.class, 'Failed to find class: testobjectparam'); Assert.areSame('mymodule', item.module, 'Failed to find module: testobjectparam'); @@ -284,7 +306,7 @@ suite.add(new YUITest.TestCase({ Assert.areSame('method', item.itemtype, 'Should be a method'); Assert.areSame(1, item.params.length, 'More than one param found'); - var props = item.params[0].props; + props = item.params[0].props; Assert.areSame(2, props.length, 'First param should have props'); Assert.areSame('prop1', props[0].name, 'Invalid item'); Assert.areSame('prop1', props[0].description, 'Invalid item'); @@ -307,13 +329,11 @@ suite.add(new YUITest.TestCase({ item = this.findByName('crashTest', 'OtherClass2'); Assert.isObject(item, 'failed to find item'); Assert.areEqual(1, item.params.length, 'Failed to replace params with param'); - - }, 'test: double namespaces': function() { - var cls = this.data.classes; - var mod_bad = cls['Foo.Bar.Foo.Bar']; - var mod_good = cls['Foo.Bar']; + var cls = this.data.classes, + mod_bad = cls['Foo.Bar.Foo.Bar'], + mod_good = cls['Foo.Bar']; Assert.isUndefined(mod_bad, 'Found class Foo.Bar.Foo.Bar'); Assert.isObject(mod_good, 'Failed to parse Foo.Bar namespace'); }, @@ -353,15 +373,15 @@ suite.add(new YUITest.TestCase({ 'test: event with optional items': function() { var item = this.findByName('changeWithOptional', 'OtherClass2'); Assert.isObject(item, 'Failed to locate event object'); - var params = item.params; - Assert.isArray(params); - var ev = params[0]; - Assert.areSame(ev.name, 'ev'); - Assert.areSame(ev.type, 'EventFacade'); - var props = ev.props; - Assert.isArray(props); - Assert.areSame(props[0].name, 'name'); - Assert.isTrue(props[0].optional); + + Assert.isArray(item.params); + + Assert.areSame(item.params[0].name, 'ev'); + Assert.areSame(item.params[0].type, 'EventFacade'); + + Assert.isArray(item.params[0].props); + Assert.areSame(item.params[0].props[0].name, 'name'); + Assert.isTrue( item.params[0].props[0].optional); } })); diff --git a/tests/parser_coffee.js b/tests/parser_coffee.js index 9e778bfa..b33e8d19 100644 --- a/tests/parser_coffee.js +++ b/tests/parser_coffee.js @@ -1,15 +1,12 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, - ArrayAssert = YUITest.ArrayAssert, path = require('path'), - fs = require('fs'), Y = require(path.join(__dirname, '../', 'lib', 'index')); //Move to the test dir before running the tests. process.chdir(__dirname); -var existsSync = fs.existsSync || path.existsSync; - var suite = new YUITest.TestSuite({ name: 'Coffee Parser Test Suite', setUp: function() { diff --git a/tests/utils.js b/tests/utils.js index 4f146437..211a864a 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -1,6 +1,7 @@ +/*global Y:true */ var YUITest = require('yuitest'), Assert = YUITest.Assert, - path = require('path') + path = require('path'), Y = require(path.join(__dirname, '../', 'lib', 'index')) ; @@ -9,7 +10,7 @@ var suite = new YUITest.TestSuite({ }); suite.add(new YUITest.TestCase({ - name: 'getProjectData Folder Priority', + name: 'getProjectData Folder Priority', 'test: Nearest Folder Priority': function() { var d = Y.getProjectData('input/folders1'); Assert.areEqual('yuidoc-root', d.name, 'must use nearest yuidoc.json first');