Apply eslint rules to `tools/doc`.
PR-URL: https://github.com/nodejs/node/pull/4973
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
test/**/node_modules
test/disabled
test/tmp*/
+tools/doc/node_modules
$(NODE) benchmark/idle_clients.js &
jslint:
- $(NODE) tools/eslint/bin/eslint.js src lib test tools/eslint-rules \
+ $(NODE) tools/eslint/bin/eslint.js lib src test tools/doc tools/eslint-rules \
--rulesdir tools/eslint-rules --quiet
CPPLINT_EXCLUDE ?=
const path = require('path');
const marked = require('marked');
-const doc = path.resolve(__dirname, '..', '..', 'doc', 'api', 'addons.markdown');
-const verifyDir = path.resolve(__dirname, '..', '..', 'test', 'addons');
+const rootDir = path.resolve(__dirname, '..', '..');
+const doc = path.resolve(rootDir, 'doc', 'api', 'addons.markdown');
+const verifyDir = path.resolve(rootDir, 'test', 'addons');
const contents = fs.readFileSync(doc).toString();
-let tokens = marked.lexer(contents, {});
+const tokens = marked.lexer(contents, {});
let files = null;
let blockName;
let id = 0;
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (token.type === 'heading' && token.text) {
- blockName = token.text
+ blockName = token.text;
if (files && Object.keys(files).length !== 0) {
verifyFiles(files,
blockName,
return;
}
- blockName = blockName.toLowerCase().replace(/\s/g, '_').replace(/[^a-z\d_]/g, '')
- let dir = path.resolve(verifyDir, `${(++id < 10 ? '0' : '') + id}_${blockName}`);
+ blockName = blockName
+ .toLowerCase()
+ .replace(/\s/g, '_')
+ .replace(/[^a-z\d_]/g, '');
+ const dir = path.resolve(
+ verifyDir,
+ `${(++id < 10 ? '0' : '') + id}_${blockName}`
+ );
files = Object.keys(files).map(function(name) {
return {
+'use strict';
+
var processIncludes = require('./preprocess.js');
-var marked = require('marked');
var fs = require('fs');
-var path = require('path');
// parse the args.
// Don't use nopt or whatever for this. It's simple enough.
var template = null;
var inputFile = null;
-args.forEach(function (arg) {
+args.forEach(function(arg) {
if (!arg.match(/^\-\-/)) {
inputFile = arg;
} else if (arg.match(/^\-\-format=/)) {
} else if (arg.match(/^\-\-template=/)) {
template = arg.replace(/^\-\-template=/, '');
}
-})
+});
if (!inputFile) {
});
-
-
function next(er, input) {
if (er) throw er;
switch (format) {
+'use strict';
+
var fs = require('fs');
var marked = require('marked');
var path = require('path');
module.exports = toHTML;
// TODO(chrisdickinson): never stop vomitting / fix this.
-var gtocPath = path.resolve(path.join(__dirname, '..', '..', 'doc', 'api', '_toc.markdown'));
+var gtocPath = path.resolve(path.join(
+ __dirname,
+ '..',
+ '..',
+ 'doc',
+ 'api',
+ '_toc.markdown'
+));
var gtocLoading = null;
var gtocData = null;
}
function toID(filename) {
- return filename.replace('.html', '').replace(/[^\w\-]/g, '-').replace(/-+/g, '-');
+ return filename
+ .replace('.html', '')
+ .replace(/[^\w\-]/g, '-')
+ .replace(/-+/g, '-');
}
function render(lexed, filename, template, cb) {
// content has to be the last thing we do with
// the lexed tokens, because it's destructive.
- content = marked.parser(lexed);
+ const content = marked.parser(lexed);
template = template.replace(/__CONTENT__/g, content);
cb(null, template);
// section is just the first heading
function getSection(lexed) {
- var section = '';
for (var i = 0, l = lexed.length; i < l; i++) {
var tok = lexed[i];
if (tok.type === 'heading') return tok.text;
function buildToc(lexed, filename, cb) {
- var indent = 0;
var toc = [];
var depth = 0;
lexed.forEach(function(tok) {
+'use strict';
+
module.exports = doJSON;
// Take the lexed input, and return a JSON-encoded object
var current = root;
var state = null;
var lexed = marked.lexer(input);
- lexed.forEach(function (tok) {
+ lexed.forEach(function(tok) {
var type = tok.type;
var text = tok.text;
if (type === 'heading' &&
!text.trim().match(/^example/i)) {
if (tok.depth - depth > 1) {
- return cb(new Error('Inappropriate heading level\n'+
+ return cb(new Error('Inappropriate heading level\n' +
JSON.stringify(tok)));
}
//
// If one of these isnt' found, then anything that comes between
// here and the next heading should be parsed as the desc.
- var stability
+ var stability;
if (state === 'AFTERHEADING') {
if (type === 'code' &&
(stability = text.match(/^Stability: ([0-5])(?:\s*-\s*)?(.*)$/))) {
finishSection(current, stack[stack.length - 1]);
}
- return cb(null, root)
+ return cb(null, root);
}
// { type: 'list_item_end' },
// { type: 'list_item_start' },
// { type: 'text',
-// text: 'silent: Boolean, whether or not to send output to parent\'s stdio.' },
+// text: 'silent: Boolean, whether to send output to parent\'s stdio.' },
// { type: 'text', text: 'Default: `false`' },
// { type: 'space' },
// { type: 'list_item_end' },
// desc: 'string arguments passed to worker.' },
// { name: 'silent',
// type: 'boolean',
-// desc: 'whether or not to send output to parent\'s stdio.',
+// desc: 'whether to send output to parent\'s stdio.',
// default: 'false' } ] } ]
function processList(section) {
// each item is an argument, unless the name is 'return',
// in which case it's the return value.
section.signatures = section.signatures || [];
- var sig = {}
+ var sig = {};
section.signatures.push(sig);
sig.params = values.filter(function(v) {
if (v.name === 'return') {
params = params[1];
// the [ is irrelevant. ] indicates optionalness.
params = params.replace(/\[/g, '');
- params = params.split(/,/)
+ params = params.split(/,/);
params.forEach(function(p, i, _) {
p = p.trim();
if (!p) return;
function finishSection(section, parent) {
if (!section || !parent) {
- throw new Error('Invalid finishSection call\n'+
+ throw new Error('Invalid finishSection call\n' +
JSON.stringify(section) + '\n' +
JSON.stringify(parent));
}
// properties are a bit special.
// their "type" is the type of object, not "property"
if (section.properties) {
- section.properties.forEach(function (p) {
+ section.properties.forEach(function(p) {
if (p.typeof) p.type = p.typeof;
else delete p.type;
delete p.typeof;
+'use strict';
+
module.exports = preprocess;
var path = require('path');
function preprocess(inputFile, input, cb) {
input = stripComments(input);
- processIncludes(inputFile, input, function (err, data) {
+ processIncludes(inputFile, input, function(err, data) {
if (err) return cb(err);
cb(null, data);
if (er) return cb(errState = er);
incCount--;
includeData[fname] = inc;
- input = input.split(include+'\n').join(includeData[fname]+'\n');
+ input = input.split(include + '\n').join(includeData[fname] + '\n');
if (incCount === 0) {
return cb(null, input);
}
:jslint
if not defined jslint goto exit
echo running jslint
-%config%\node tools\eslint\bin\eslint.js src lib test tools\eslint-rules --rulesdir tools\eslint-rules --quiet
+%config%\node tools\eslint\bin\eslint.js lib src test tools\doc tools\eslint-rules --rulesdir tools\eslint-rules --quiet
goto exit
:create-msvs-files-failed