Skip to content

Commit e95fd6a

Browse files
Trottrvagg
authored andcommitted
tools: apply linting to doc tools
Apply eslint rules to `tools/doc`. PR-URL: #4973 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent 101de9d commit e95fd6a

8 files changed

+51
-31
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ test/fixtures
66
test/**/node_modules
77
test/disabled
88
test/tmp*/
9+
tools/doc/node_modules

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ bench-idle:
514514
$(NODE) benchmark/idle_clients.js &
515515

516516
jslint:
517-
$(NODE) tools/eslint/bin/eslint.js src lib test tools/eslint-rules \
517+
$(NODE) tools/eslint/bin/eslint.js lib src test tools/doc tools/eslint-rules \
518518
--rulesdir tools/eslint-rules --quiet
519519

520520
CPPLINT_EXCLUDE ?=

tools/doc/addon-verify.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const fs = require('fs');
44
const path = require('path');
55
const marked = require('marked');
66

7-
const doc = path.resolve(__dirname, '..', '..', 'doc', 'api', 'addons.markdown');
8-
const verifyDir = path.resolve(__dirname, '..', '..', 'test', 'addons');
7+
const rootDir = path.resolve(__dirname, '..', '..');
8+
const doc = path.resolve(rootDir, 'doc', 'api', 'addons.markdown');
9+
const verifyDir = path.resolve(rootDir, 'test', 'addons');
910

1011
const contents = fs.readFileSync(doc).toString();
1112

12-
let tokens = marked.lexer(contents, {});
13+
const tokens = marked.lexer(contents, {});
1314
let files = null;
1415
let blockName;
1516
let id = 0;
@@ -27,7 +28,7 @@ oldDirs = oldDirs.filter(function(dir) {
2728
for (var i = 0; i < tokens.length; i++) {
2829
var token = tokens[i];
2930
if (token.type === 'heading' && token.text) {
30-
blockName = token.text
31+
blockName = token.text;
3132
if (files && Object.keys(files).length !== 0) {
3233
verifyFiles(files,
3334
blockName,
@@ -60,8 +61,14 @@ function verifyFiles(files, blockName, onprogress, ondone) {
6061
return;
6162
}
6263

63-
blockName = blockName.toLowerCase().replace(/\s/g, '_').replace(/[^a-z\d_]/g, '')
64-
let dir = path.resolve(verifyDir, `${(++id < 10 ? '0' : '') + id}_${blockName}`);
64+
blockName = blockName
65+
.toLowerCase()
66+
.replace(/\s/g, '_')
67+
.replace(/[^a-z\d_]/g, '');
68+
const dir = path.resolve(
69+
verifyDir,
70+
`${(++id < 10 ? '0' : '') + id}_${blockName}`
71+
);
6572

6673
files = Object.keys(files).map(function(name) {
6774
return {

tools/doc/generate.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
'use strict';
2+
13
var processIncludes = require('./preprocess.js');
2-
var marked = require('marked');
34
var fs = require('fs');
4-
var path = require('path');
55

66
// parse the args.
77
// Don't use nopt or whatever for this. It's simple enough.
@@ -11,15 +11,15 @@ var format = 'json';
1111
var template = null;
1212
var inputFile = null;
1313

14-
args.forEach(function (arg) {
14+
args.forEach(function(arg) {
1515
if (!arg.match(/^\-\-/)) {
1616
inputFile = arg;
1717
} else if (arg.match(/^\-\-format=/)) {
1818
format = arg.replace(/^\-\-format=/, '');
1919
} else if (arg.match(/^\-\-template=/)) {
2020
template = arg.replace(/^\-\-template=/, '');
2121
}
22-
})
22+
});
2323

2424

2525
if (!inputFile) {
@@ -35,8 +35,6 @@ fs.readFile(inputFile, 'utf8', function(er, input) {
3535
});
3636

3737

38-
39-
4038
function next(er, input) {
4139
if (er) throw er;
4240
switch (format) {

tools/doc/html.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var fs = require('fs');
24
var marked = require('marked');
35
var path = require('path');
@@ -6,7 +8,14 @@ var preprocess = require('./preprocess.js');
68
module.exports = toHTML;
79

810
// TODO(chrisdickinson): never stop vomitting / fix this.
9-
var gtocPath = path.resolve(path.join(__dirname, '..', '..', 'doc', 'api', '_toc.markdown'));
11+
var gtocPath = path.resolve(path.join(
12+
__dirname,
13+
'..',
14+
'..',
15+
'doc',
16+
'api',
17+
'_toc.markdown'
18+
));
1019
var gtocLoading = null;
1120
var gtocData = null;
1221

@@ -55,7 +64,10 @@ function loadGtoc(cb) {
5564
}
5665

5766
function toID(filename) {
58-
return filename.replace('.html', '').replace(/[^\w\-]/g, '-').replace(/-+/g, '-');
67+
return filename
68+
.replace('.html', '')
69+
.replace(/[^\w\-]/g, '-')
70+
.replace(/-+/g, '-');
5971
}
6072

6173
function render(lexed, filename, template, cb) {
@@ -85,7 +97,7 @@ function render(lexed, filename, template, cb) {
8597

8698
// content has to be the last thing we do with
8799
// the lexed tokens, because it's destructive.
88-
content = marked.parser(lexed);
100+
const content = marked.parser(lexed);
89101
template = template.replace(/__CONTENT__/g, content);
90102

91103
cb(null, template);
@@ -173,7 +185,6 @@ function parseAPIHeader(text) {
173185

174186
// section is just the first heading
175187
function getSection(lexed) {
176-
var section = '';
177188
for (var i = 0, l = lexed.length; i < l; i++) {
178189
var tok = lexed[i];
179190
if (tok.type === 'heading') return tok.text;
@@ -183,7 +194,6 @@ function getSection(lexed) {
183194

184195

185196
function buildToc(lexed, filename, cb) {
186-
var indent = 0;
187197
var toc = [];
188198
var depth = 0;
189199
lexed.forEach(function(tok) {

tools/doc/json.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = doJSON;
24

35
// Take the lexed input, and return a JSON-encoded object
@@ -12,7 +14,7 @@ function doJSON(input, filename, cb) {
1214
var current = root;
1315
var state = null;
1416
var lexed = marked.lexer(input);
15-
lexed.forEach(function (tok) {
17+
lexed.forEach(function(tok) {
1618
var type = tok.type;
1719
var text = tok.text;
1820

@@ -31,7 +33,7 @@ function doJSON(input, filename, cb) {
3133
if (type === 'heading' &&
3234
!text.trim().match(/^example/i)) {
3335
if (tok.depth - depth > 1) {
34-
return cb(new Error('Inappropriate heading level\n'+
36+
return cb(new Error('Inappropriate heading level\n' +
3537
JSON.stringify(tok)));
3638
}
3739

@@ -77,7 +79,7 @@ function doJSON(input, filename, cb) {
7779
//
7880
// If one of these isnt' found, then anything that comes between
7981
// here and the next heading should be parsed as the desc.
80-
var stability
82+
var stability;
8183
if (state === 'AFTERHEADING') {
8284
if (type === 'code' &&
8385
(stability = text.match(/^Stability: ([0-5])(?:\s*-\s*)?(.*)$/))) {
@@ -125,7 +127,7 @@ function doJSON(input, filename, cb) {
125127
finishSection(current, stack[stack.length - 1]);
126128
}
127129

128-
return cb(null, root)
130+
return cb(null, root);
129131
}
130132

131133

@@ -146,7 +148,7 @@ function doJSON(input, filename, cb) {
146148
// { type: 'list_item_end' },
147149
// { type: 'list_item_start' },
148150
// { type: 'text',
149-
// text: 'silent: Boolean, whether or not to send output to parent\'s stdio.' },
151+
// text: 'silent: Boolean, whether to send output to parent\'s stdio.' },
150152
// { type: 'text', text: 'Default: `false`' },
151153
// { type: 'space' },
152154
// { type: 'list_item_end' },
@@ -168,7 +170,7 @@ function doJSON(input, filename, cb) {
168170
// desc: 'string arguments passed to worker.' },
169171
// { name: 'silent',
170172
// type: 'boolean',
171-
// desc: 'whether or not to send output to parent\'s stdio.',
173+
// desc: 'whether to send output to parent\'s stdio.',
172174
// default: 'false' } ] } ]
173175

174176
function processList(section) {
@@ -231,7 +233,7 @@ function processList(section) {
231233
// each item is an argument, unless the name is 'return',
232234
// in which case it's the return value.
233235
section.signatures = section.signatures || [];
234-
var sig = {}
236+
var sig = {};
235237
section.signatures.push(sig);
236238
sig.params = values.filter(function(v) {
237239
if (v.name === 'return') {
@@ -273,7 +275,7 @@ function parseSignature(text, sig) {
273275
params = params[1];
274276
// the [ is irrelevant. ] indicates optionalness.
275277
params = params.replace(/\[/g, '');
276-
params = params.split(/,/)
278+
params = params.split(/,/);
277279
params.forEach(function(p, i, _) {
278280
p = p.trim();
279281
if (!p) return;
@@ -362,7 +364,7 @@ function parseListItem(item) {
362364

363365
function finishSection(section, parent) {
364366
if (!section || !parent) {
365-
throw new Error('Invalid finishSection call\n'+
367+
throw new Error('Invalid finishSection call\n' +
366368
JSON.stringify(section) + '\n' +
367369
JSON.stringify(parent));
368370
}
@@ -405,7 +407,7 @@ function finishSection(section, parent) {
405407
// properties are a bit special.
406408
// their "type" is the type of object, not "property"
407409
if (section.properties) {
408-
section.properties.forEach(function (p) {
410+
section.properties.forEach(function(p) {
409411
if (p.typeof) p.type = p.typeof;
410412
else delete p.type;
411413
delete p.typeof;

tools/doc/preprocess.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
module.exports = preprocess;
24

35
var path = require('path');
@@ -8,7 +10,7 @@ var includeData = {};
810

911
function preprocess(inputFile, input, cb) {
1012
input = stripComments(input);
11-
processIncludes(inputFile, input, function (err, data) {
13+
processIncludes(inputFile, input, function(err, data) {
1214
if (err) return cb(err);
1315

1416
cb(null, data);
@@ -47,7 +49,7 @@ function processIncludes(inputFile, input, cb) {
4749
if (er) return cb(errState = er);
4850
incCount--;
4951
includeData[fname] = inc;
50-
input = input.split(include+'\n').join(includeData[fname]+'\n');
52+
input = input.split(include + '\n').join(includeData[fname] + '\n');
5153
if (incCount === 0) {
5254
return cb(null, input);
5355
}

vcbuild.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ goto jslint
259259
:jslint
260260
if not defined jslint goto exit
261261
echo running jslint
262-
%config%\node tools\eslint\bin\eslint.js src lib test tools\eslint-rules --rulesdir tools\eslint-rules --quiet
262+
%config%\node tools\eslint\bin\eslint.js lib src test tools\doc tools\eslint-rules --rulesdir tools\eslint-rules --quiet
263263
goto exit
264264

265265
:create-msvs-files-failed

0 commit comments

Comments
 (0)