Skip to content

Commit

Permalink
Change the linting
Browse files Browse the repository at this point in the history
It just switches from JSHint to ESLint. ESLint has many good linting
rules as default, and it makes more consistency code. The summary of
changes as follows.

* Intended code under `lib/` and `tests/`.
* Follow default rules of ESLint as much as possible.
* Disable following rules to avoid making large code changes for now.
 * `camelcase`
 * `new-cap`
 * `no-loop-func`
 * `no-process-exit`
 * `no-underscore-dangle`
 * `no-use-before-define`
  • Loading branch information
okuryu committed May 16, 2015
1 parent 038660b commit 8f547eb
Show file tree
Hide file tree
Showing 21 changed files with 656 additions and 605 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"node": true
},
"globals": {
"YUI": true
},
"rules": {
"camelcase": 0,
"new-cap": 0,
"no-loop-func": 0,
"no-process-exit": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"quotes": [2, "single"]
}
}
158 changes: 95 additions & 63 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* Code licensed under the BSD License:
* https://github.com/yui/yuidoc/blob/master/LICENSE
*/
var MarkdownIt = require('markdown-it'),
fs = require('graceful-fs'),
noop = function () {},
path = require('path'),
TEMPLATE;
'use strict';

var MarkdownIt = require('markdown-it');
var fs = require('graceful-fs');
var noop = function () {};
var path = require('path');
var TEMPLATE;

/**
* Takes the `JSON` data from the `DocParser` class, creates and parses markdown and handlebars
Expand Down Expand Up @@ -63,7 +65,7 @@ YUI.add('doc-builder', function (Y) {
this.files = 0;
var self = this;

Y.Handlebars.registerHelper('crossLink', function (item, options) {
Y.Handlebars.registerHelper('crossLink', function (item, helperOptions) {
var str = '';
if (!item) {
item = '';
Expand All @@ -77,16 +79,16 @@ YUI.add('doc-builder', function (Y) {
});
str = p.join(' | ');
} else {
str = self._parseCrossLink.call(self, item, false, options.fn(this));
str = self._parseCrossLink.call(self, item, false, helperOptions.fn(this));
}
return str;
});

Y.Handlebars.registerHelper('crossLinkModule', function (item, options) {
Y.Handlebars.registerHelper('crossLinkModule', function (item, helperOptions) {
var str = item;
if (self.data.modules[item]) {
var content = options.fn(this);
if (content === "") {
var content = helperOptions.fn(this);
if (content === '') {
content = item;
}
str = '<a href="../modules/' + item.replace(/\//g, '_') +
Expand Down Expand Up @@ -151,7 +153,7 @@ YUI.add('doc-builder', function (Y) {
try {
// markdown-it auto-escapes quotation marks (and unfortunately
// does not expose the escaping function)
html = html.replace(/&quot;/g, "\"");
html = html.replace(/&quot;/g, '"');
html = (Y.Handlebars.compile(html))({});
} catch (hError) {
//Remove all the extra escapes
Expand Down Expand Up @@ -363,8 +365,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);
});
Expand Down Expand Up @@ -414,13 +416,13 @@ YUI.add('doc-builder', function (Y) {
on: {
complete: stack.add(function (id, e) {
Y.log('Received: ' + i, 'info', 'builder');
var data = JSON.parse(e.responseText);
data.base = base;
var parsedData = JSON.parse(e.responseText);
parsedData.base = base;
//self.options.externalData = Y.mix(self.options.externalData || {}, data);
if (!self.options.externalData) {
self.options.externalData = [];
}
self.options.externalData.push(data);
self.options.externalData.push(parsedData);
})
}
});
Expand Down Expand Up @@ -715,13 +717,13 @@ YUI.add('doc-builder', function (Y) {
if (self.options.dumpview) {
dirs.push('json');
}
var writeRedirect = function (dir, file, cb) {
var writeRedirect = function (dir, file, cbWriteRedirect) {
Y.Files.exists(file, function (x) {
if (x) {
var out = path.join(dir, 'index.html');
fs.createReadStream(file).pipe(fs.createWriteStream(out));
}
cb();
cbWriteRedirect();
});
};
var defaultIndex = path.join(themeDir, 'assets', 'index.html');
Expand All @@ -731,7 +733,7 @@ YUI.add('doc-builder', function (Y) {
var dir = path.join(self.options.outdir, d);
Y.Files.exists(dir, stack.add(function (x) {
if (!x) {
fs.mkdir(dir, 0777, stack.add(function () {
fs.mkdir(dir, '0777', stack.add(function () {
writeRedirect(dir, defaultIndex, stack.add(noop));
}));
} else {
Expand All @@ -751,7 +753,7 @@ YUI.add('doc-builder', function (Y) {
if (!url) {
return null;
}
if (url.indexOf("://") >= 0) {
if (url.indexOf('://') >= 0) {
return url;
}
return path.join(opts.meta.projectRoot, url);
Expand Down Expand Up @@ -819,8 +821,8 @@ YUI.add('doc-builder', function (Y) {
var parts = Y.merge(partials || {}, {
layout_content: source
});
Y.each(parts, function (source, name) {
Y.Handlebars.registerPartial(name, source);
Y.each(parts, function (partialsSource, name) {
Y.Handlebars.registerPartial(name, partialsSource);
});

if (!TEMPLATE || !this.cacheTemplates) {
Expand Down Expand Up @@ -856,6 +858,11 @@ YUI.add('doc-builder', function (Y) {
var self = this;

Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
if (err) {
Y.log(err, 'error', 'builder');
cb(err);
return;
}
opts.meta.title = self.data.project.name;
opts.meta.projectRoot = './';
opts.meta.projectAssets = './assets';
Expand All @@ -864,7 +871,12 @@ YUI.add('doc-builder', function (Y) {
opts = self.populateModules(opts);

var view = new Y.DocView(opts.meta);
self.render('{{>index}}', view, opts.layouts.main, opts.partials, function (err, html) {
self.render('{{>index}}', view, opts.layouts.main, opts.partials, function (renderErr, html) {
if (renderErr) {
Y.log(renderErr, 'error', 'builder');
cb(renderErr);
return;
}
self.files++;
cb(html, view);
});
Expand Down Expand Up @@ -910,6 +922,11 @@ YUI.add('doc-builder', function (Y) {
data.displayName = data.name;
data.name = self.filterFileName(data.name);
Y.prepare([DEFAULT_THEME, themeDir], self.getProjectMeta(), function (err, opts) {
if (err) {
Y.log(err, 'error', 'builder');
cb(err);
return;
}
opts.meta = Y.merge(opts.meta, data);

//opts.meta.htmlTitle = v.name + ': ' + self.data.project.name;
Expand Down Expand Up @@ -969,7 +986,12 @@ YUI.add('doc-builder', function (Y) {

var view = new Y.DocView(opts.meta);
var mainLayout = opts.layouts[layout];
self.render('{{>module}}', view, mainLayout, opts.partials, stack.add(function (err, html) {
self.render('{{>module}}', view, mainLayout, opts.partials, stack.add(function (renderErr, html) {
if (renderErr) {
Y.log(renderErr, 'error', 'builder');
cb(renderErr);
return;
}
self.files++;
stack.html = html;
stack.view = view;
Expand Down Expand Up @@ -1149,51 +1171,51 @@ YUI.add('doc-builder', function (Y) {
}

var classItems = [];
self.data.classitems.forEach(function (i) {
if (i.class === data.name) {
classItems.push(i);
self.data.classitems.forEach(function (classItem) {
if (classItem.class === data.name) {
classItems.push(classItem);
}
});

classItems = self.mergeExtends(data, classItems, true);

if (data.is_constructor) {
var i = Y.mix({}, data);
i = self.augmentData(i);
i.paramsList = [];
if (i.params) {
i.params.forEach(function (p) {
var constructor = Y.mix({}, data);
constructor = self.augmentData(constructor);
constructor.paramsList = [];
if (constructor.params) {
constructor.params.forEach(function (p) {
var name = p.name;
if (p.optional) {
name = '[' + name + ((p.optdefault) ? '=' + p.optdefault : '') + ']';
}
i.paramsList.push(name);
constructor.paramsList.push(name);
});
}
//i.methodDescription = self._parseCode(markdown(i.description));
i.hasAccessType = i.access;
i.hasParams = i.paramsList.length;
if (i.paramsList.length) {
i.paramsList = i.paramsList.join(', ');
constructor.hasAccessType = constructor.access;
constructor.hasParams = constructor.paramsList.length;
if (constructor.paramsList.length) {
constructor.paramsList = constructor.paramsList.join(', ');
} else {
i.paramsList = ' ';
constructor.paramsList = ' ';
}
i.returnType = ' ';
if (i["return"]) {
i.hasReturn = true;
i.returnType = i["return"].type;
constructor.returnType = ' ';
if (constructor.return) {
constructor.hasReturn = true;
constructor.returnType = constructor.return.type;
}
//console.error(i);
opts.meta.is_constructor = [i];
if (i.example && i.example.length) {
if (i.example.forEach) {
var e = '';
i.example.forEach(function (v) {
e += self._parseCode(self.markdown(v));
opts.meta.is_constructor = [constructor];
if (constructor.example && constructor.example.length) {
if (constructor.example.forEach) {
var example = '';
constructor.example.forEach(function (v) {
example += self._parseCode(self.markdown(v));
});
i.example = e;
constructor.example = example;
} else {
i.example = self._parseCode(self.markdown(i.example));
constructor.example = self._parseCode(self.markdown(constructor.example));
}
}
}
Expand Down Expand Up @@ -1233,9 +1255,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
Expand Down Expand Up @@ -1374,7 +1396,12 @@ YUI.add('doc-builder', function (Y) {

var view = new Y.DocView(opts.meta);
var mainLayout = opts.layouts[layout];
self.render('{{>classes}}', view, mainLayout, opts.partials, stack.add(function (err, html) {
self.render('{{>classes}}', view, mainLayout, opts.partials, stack.add(function (renderErr, html) {
if (renderErr) {
Y.log(renderErr, 'error', 'builder');
cb(renderErr);
return;
}
self.files++;
stack.html = html;
stack.view = view;
Expand Down Expand Up @@ -1533,23 +1560,28 @@ YUI.add('doc-builder', function (Y) {
opts = self.populateFiles(opts);

opts.meta.fileName = data.name;
fs.readFile(opts.meta.fileName, Y.charset, Y.rbind(function (err, str, opts, data) {
if (err) {
Y.log(err, 'error', 'builder');
cb(err);
fs.readFile(opts.meta.fileName, Y.charset, Y.rbind(function (readErr, str, readOpts, readData) {
if (readErr) {
Y.log(readErr, 'error', 'builder');
cb(readErr);
return;
}

if (typeof self.options.tabspace === 'string') {
str = str.replace(/\t/g, self.options.tabspace);
}

opts.meta.fileData = str;
var view = new Y.DocView(opts.meta, 'index');
var mainLayout = opts.layouts[layout];
self.render('{{>files}}', view, mainLayout, opts.partials, function (err, html) {
readOpts.meta.fileData = str;
var view = new Y.DocView(readOpts.meta, 'index');
var mainLayout = readOpts.layouts[layout];
self.render('{{>files}}', view, mainLayout, readOpts.partials, function (renderErr, html) {
if (renderErr) {
Y.log(renderErr, 'error', 'builder');
cb(renderErr);
return;
}
self.files++;
cb(html, view, data);
cb(html, view, readData);
});

}, this, opts, data));
Expand Down Expand Up @@ -1629,7 +1661,7 @@ YUI.add('doc-builder', function (Y) {
self.makeDirs(function () {
Y.log('Copying Assets', 'info', 'builder');
if (!Y.Files.isDirectory(path.join(self.options.outdir, 'assets'))) {
fs.mkdirSync(path.join(self.options.outdir, 'assets'), 0777);
fs.mkdirSync(path.join(self.options.outdir, 'assets'), '0777');
}
Y.Files.copyAssets([
path.join(DEFAULT_THEME, 'assets'),
Expand Down
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
'use strict';

/**
* Copyright (c) 2011, Yahoo! Inc. All rights reserved.
Expand All @@ -12,7 +13,6 @@
* @module yuidoc
*/

/*global Y:true */
var Y = require('./index');

var options = Y.Options(Y.Array(process.argv, 2));
Expand All @@ -35,7 +35,7 @@ if (options.server) {
} else {
var json = (new Y.YUIDoc(options)).run();
if (json === null) {
return;
throw new Error('Running YUIDoc returns null.');
}
options = Y.Project.mix(json, options);

Expand Down
Loading

0 comments on commit 8f547eb

Please sign in to comment.