Skip to content

Commit 7d74060

Browse files
Eslint add new rules - no-var and prefer-const
1 parent c1611ca commit 7d74060

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+784
-743
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"flowtype"
99
],
1010
"rules": {
11+
"no-var": 2,
12+
"prefer-const": 2,
1113
"no-use-before-define": [2, "nofunc"],
1214
"camelcase": 2,
1315
"no-lonely-if": 2,

__tests__/bin-readme.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var path = require('path'),
2-
os = require('os'),
3-
exec = require('child_process').exec,
4-
tmp = require('tmp'),
5-
fs = require('fs-extra');
1+
const path = require('path');
2+
const os = require('os');
3+
const exec = require('child_process').exec;
4+
const tmp = require('tmp');
5+
const fs = require('fs-extra');
66

77
function documentation(args, options, parseJSON) {
88
return new Promise((resolve, reject) => {
@@ -23,13 +23,13 @@ function documentation(args, options, parseJSON) {
2323
}
2424

2525
describe('readme command', function() {
26-
var fixtures = path.join(__dirname, 'fixture/readme');
27-
var sourceFile = path.join(fixtures, 'index.js');
28-
var d;
29-
var removeCallback;
26+
const fixtures = path.join(__dirname, 'fixture/readme');
27+
const sourceFile = path.join(fixtures, 'index.js');
28+
let d;
29+
let removeCallback;
3030

3131
beforeEach(() => {
32-
var dirEntry = tmp.dirSync({ unsafeCleanup: true });
32+
const dirEntry = tmp.dirSync({ unsafeCleanup: true });
3333
d = dirEntry.name;
3434
fs.copySync(
3535
path.join(fixtures, 'README.input.md'),
@@ -41,13 +41,13 @@ describe('readme command', function() {
4141
// run tests after setting up temp dir
4242

4343
test('--diff-only: changes needed', async function() {
44-
var before = fs.readFileSync(path.join(d, 'README.md'), 'utf-8');
44+
const before = fs.readFileSync(path.join(d, 'README.md'), 'utf-8');
4545
try {
4646
await documentation(['readme index.js --diff-only -s API'], {
4747
cwd: d
4848
});
4949
} catch (err) {
50-
var after = fs.readFileSync(path.join(d, 'README.md'), 'utf-8');
50+
const after = fs.readFileSync(path.join(d, 'README.md'), 'utf-8');
5151
expect(err).toBeTruthy();
5252
expect(err.code).not.toBe(0);
5353
expect(after).toEqual(before);
@@ -56,7 +56,7 @@ describe('readme command', function() {
5656

5757
test('updates README.md', async function() {
5858
await documentation(['readme index.js -s API'], { cwd: d });
59-
var outputPath = path.join(d, 'README.md');
59+
const outputPath = path.join(d, 'README.md');
6060
expect(fs.readFileSync(outputPath, 'utf-8')).toMatchSnapshot();
6161
});
6262

@@ -68,7 +68,7 @@ describe('readme command', function() {
6868
await documentation(['readme index.js -s API --readme-file other.md'], {
6969
cwd: d
7070
});
71-
var actual = fs.readFileSync(path.join(d, 'other.md'), 'utf8');
71+
const actual = fs.readFileSync(path.join(d, 'other.md'), 'utf8');
7272
expect(actual).toMatchSnapshot();
7373
});
7474

@@ -110,7 +110,7 @@ describe('readme command', function() {
110110
}
111111
});
112112

113-
var badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input');
113+
const badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input');
114114
test('errors on invalid syntax', async function() {
115115
try {
116116
await documentation(

__tests__/bin-watch-serve.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var path = require('path');
2-
var os = require('os');
3-
var get = require('./utils').get;
4-
var spawn = require('child_process').spawn;
5-
var fs = require('fs');
6-
var pEvent = require('p-event');
1+
const path = require('path');
2+
const os = require('os');
3+
const get = require('./utils').get;
4+
const spawn = require('child_process').spawn;
5+
const fs = require('fs');
6+
const pEvent = require('p-event');
77

88
function documentation(args, options) {
99
if (!options) {
@@ -29,17 +29,17 @@ function normalize(result) {
2929
const timeout = 20000;
3030

3131
test('harness', function() {
32-
var docProcess = documentation(['serve', 'fixture/simple.input.js']);
32+
const docProcess = documentation(['serve', 'fixture/simple.input.js']);
3333
expect(docProcess).toBeTruthy();
3434
docProcess.kill();
3535
});
3636

3737
test(
3838
'provides index.html',
3939
function() {
40-
var docProcess = documentation(['serve', 'fixture/simple.input.js']);
40+
const docProcess = documentation(['serve', 'fixture/simple.input.js']);
4141
return pEvent(docProcess.stdout, 'data').then(function(data) {
42-
var portNumber = data
42+
const portNumber = data
4343
.toString()
4444
.match(/documentation.js serving on port (\d+)/);
4545
expect(portNumber).toBeTruthy();
@@ -55,13 +55,13 @@ test(
5555
test(
5656
'accepts port argument',
5757
function() {
58-
var docProcess = documentation([
58+
const docProcess = documentation([
5959
'serve',
6060
'fixture/simple.input.js',
6161
'--port=4004'
6262
]);
6363
return pEvent(docProcess.stdout, 'data').then(function(data) {
64-
var portNumber = data
64+
const portNumber = data
6565
.toString()
6666
.match(/documentation.js serving on port (\d+)/);
6767
expect(portNumber).toBeTruthy();
@@ -77,11 +77,11 @@ test(
7777
test(
7878
'--watch',
7979
function(done) {
80-
var tmpFile = path.join(os.tmpdir(), '/simple.js');
80+
const tmpFile = path.join(os.tmpdir(), '/simple.js');
8181
fs.writeFileSync(tmpFile, '/** a function */function apples() {}');
82-
var docProcess = documentation(['serve', tmpFile, '--watch']);
82+
const docProcess = documentation(['serve', tmpFile, '--watch']);
8383
pEvent(docProcess.stdout, 'data').then(function(data) {
84-
var portNumber = data
84+
const portNumber = data
8585
.toString()
8686
.match(/documentation.js serving on port (\d+)/);
8787
expect(portNumber).toBeTruthy();
@@ -108,14 +108,14 @@ test(
108108
test(
109109
'--watch',
110110
function(done) {
111-
var tmpDir = os.tmpdir();
112-
var a = path.join(tmpDir, '/simple.js');
113-
var b = path.join(tmpDir, '/required.js');
111+
const tmpDir = os.tmpdir();
112+
const a = path.join(tmpDir, '/simple.js');
113+
const b = path.join(tmpDir, '/required.js');
114114
fs.writeFileSync(a, 'require("./required")');
115115
fs.writeFileSync(b, '/** soup */function soup() {}');
116-
var docProcess = documentation(['serve', a, '--watch']);
116+
const docProcess = documentation(['serve', a, '--watch']);
117117
docProcess.stdout.once('data', function(data) {
118-
var portNumber = data
118+
const portNumber = data
119119
.toString()
120120
.match(/documentation.js serving on port (\d+)/);
121121
expect(portNumber).toBeTruthy();
@@ -142,12 +142,12 @@ test(
142142
test(
143143
'error page',
144144
function() {
145-
var tmpDir = os.tmpdir();
146-
var a = path.join(tmpDir, '/simple.js');
145+
const tmpDir = os.tmpdir();
146+
const a = path.join(tmpDir, '/simple.js');
147147
fs.writeFileSync(a, '**');
148-
var docProcess = documentation(['serve', a, '--watch']);
148+
const docProcess = documentation(['serve', a, '--watch']);
149149
return pEvent(docProcess.stdout, 'data').then(function(data) {
150-
var portNumber = data
150+
const portNumber = data
151151
.toString()
152152
.match(/documentation.js serving on port (\d+)/);
153153
expect(portNumber).toBeTruthy();

__tests__/bin.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* global jasmine */
22

3-
var path = require('path'),
4-
os = require('os'),
5-
exec = require('child_process').exec,
6-
tmp = require('tmp'),
7-
fs = require('fs-extra');
3+
const path = require('path');
4+
const os = require('os');
5+
const exec = require('child_process').exec;
6+
const tmp = require('tmp');
7+
const fs = require('fs-extra');
88

99
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
1010

@@ -160,9 +160,9 @@ describe('invalid arguments', function() {
160160
});
161161

162162
test('--config', async function() {
163-
var dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
163+
const dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
164164
fs.mkdirSync(dst);
165-
var outputIndex = path.join(dst, 'index.html');
165+
const outputIndex = path.join(dst, 'index.html');
166166
const data = await documentation(
167167
[
168168
'build -c fixture/html/documentation.yml -f html fixture/html/nested.input.js -o ' +
@@ -171,7 +171,7 @@ test('--config', async function() {
171171
{},
172172
false
173173
);
174-
var output = fs.readFileSync(outputIndex, 'utf8');
174+
const output = fs.readFileSync(outputIndex, 'utf8');
175175
expect(output).toMatchSnapshot();
176176
});
177177

@@ -185,7 +185,11 @@ describe('lint command', function() {
185185
try {
186186
await documentation(['lint fixture/lint/lint.input.js'], {}, false);
187187
} catch (err) {
188-
var data = err.stderr.toString().split('\n').slice(2).join('\n');
188+
const data = err.stderr
189+
.toString()
190+
.split('\n')
191+
.slice(2)
192+
.join('\n');
189193
expect(data).toMatchSnapshot();
190194
}
191195
});
@@ -284,7 +288,7 @@ test('--infer-private flag', async function() {
284288
});
285289

286290
test('write to file', async function() {
287-
var dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
291+
const dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
288292

289293
const data = await documentation(
290294
['build --shallow fixture/internal.input.js -o ' + dst],
@@ -296,7 +300,10 @@ test('write to file', async function() {
296300
});
297301

298302
test('write to html', async function() {
299-
var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
303+
const dstDir = path.join(
304+
os.tmpdir(),
305+
(Date.now() + Math.random()).toString()
306+
);
300307
fs.mkdirSync(dstDir);
301308

302309
const data = await documentation(
@@ -309,7 +316,10 @@ test('write to html', async function() {
309316
});
310317

311318
test('write to html with custom theme', async function() {
312-
var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
319+
const dstDir = path.join(
320+
os.tmpdir(),
321+
(Date.now() + Math.random()).toString()
322+
);
313323
fs.mkdirSync(dstDir);
314324

315325
const data = await documentation(
@@ -325,9 +335,12 @@ test('write to html with custom theme', async function() {
325335
});
326336

327337
test('write to html, highlightAuto', function() {
328-
var fixture = 'fixture/auto_lang_hljs/multilanguage.input.js',
329-
config = 'fixture/auto_lang_hljs/config.yml',
330-
dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
338+
const fixture = 'fixture/auto_lang_hljs/multilanguage.input.js';
339+
const config = 'fixture/auto_lang_hljs/config.yml';
340+
const dstDir = path.join(
341+
os.tmpdir(),
342+
(Date.now() + Math.random()).toString()
343+
);
331344

332345
fs.mkdirSync(dstDir);
333346

@@ -336,7 +349,7 @@ test('write to html, highlightAuto', function() {
336349
{},
337350
false
338351
).then(() => {
339-
var result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8');
352+
const result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8');
340353
expect(
341354
result.indexOf('<span class="hljs-number">42</span>') > 0
342355
).toBeTruthy();
@@ -371,10 +384,10 @@ test('build --document-exported', async function() {
371384
});
372385

373386
test('build large file without error (no deoptimized styling error)', function() {
374-
var dstFile =
387+
const dstFile =
375388
path.join(os.tmpdir(), (Date.now() + Math.random()).toString()) + '.js';
376-
var contents = '';
377-
for (var i = 0; i < 4e4; i++) {
389+
let contents = '';
390+
for (let i = 0; i < 4e4; i++) {
378391
contents += '/* - */\n';
379392
}
380393
fs.writeFileSync(dstFile, contents, 'utf8');

__tests__/format_type.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*eslint max-len: 0 */
22

3-
var _formatType = require('../src/output/util/format_type'),
4-
LinkerStack = require('../src/output/util/linker_stack'),
5-
remark = require('remark'),
6-
parse = require('doctrine-temporary-fork').parse;
3+
const _formatType = require('../src/output/util/format_type');
4+
const LinkerStack = require('../src/output/util/linker_stack');
5+
const remark = require('remark');
6+
const parse = require('doctrine-temporary-fork').parse;
77

88
function stringify(children) {
99
return remark().stringify({
@@ -13,8 +13,8 @@ function stringify(children) {
1313
}
1414

1515
test('formatType', function() {
16-
var linkerStack = new LinkerStack({});
17-
var formatType = _formatType.bind(undefined, linkerStack.link);
16+
const linkerStack = new LinkerStack({});
17+
const formatType = _formatType.bind(undefined, linkerStack.link);
1818
[
1919
['Foo', 'Foo'],
2020
['null', 'null'],

__tests__/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var documentation = require('../src/');
2-
var os = require('os');
3-
var path = require('path');
4-
var fs = require('fs');
1+
const documentation = require('../src/');
2+
const os = require('os');
3+
const path = require('path');
4+
const fs = require('fs');
55

66
function inputs(contents) {
7-
var dirEntry = os.tmpdir();
8-
var paths = {};
9-
for (var filename in contents) {
7+
const dirEntry = os.tmpdir();
8+
const paths = {};
9+
for (const filename in contents) {
1010
paths[filename] = path.join(dirEntry, '/', filename);
1111
fs.writeFileSync(paths[filename], contents[filename]);
1212
}
@@ -22,7 +22,7 @@ function cleanup(comments) {
2222
}
2323

2424
test('lint', async function() {
25-
var { paths } = inputs({
25+
const { paths } = inputs({
2626
'index.js': '/** hi */var name = 1;'
2727
});
2828

@@ -31,7 +31,7 @@ test('lint', async function() {
3131
});
3232

3333
test('build', async function() {
34-
var { paths } = inputs({
34+
const { paths } = inputs({
3535
'index.js': '/** hi */var name = 1;'
3636
});
3737

@@ -47,7 +47,7 @@ test('build', async function() {
4747
});
4848

4949
test('expandInputs', async function() {
50-
var { paths } = inputs({
50+
const { paths } = inputs({
5151
'index.js': '/** hi */var name = 1;'
5252
});
5353

__tests__/lib/filter_access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var filterAccess = require('../../src/filter_access');
1+
const filterAccess = require('../../src/filter_access');
22

33
test('filterAccess ignore', function() {
44
expect(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy