Skip to content

Commit

Permalink
Eslint add new rules - no-var and prefer-const
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-redFox committed Jan 24, 2018
1 parent c1611ca commit 7d74060
Show file tree
Hide file tree
Showing 86 changed files with 784 additions and 743 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Expand Up @@ -8,6 +8,8 @@
"flowtype"
],
"rules": {
"no-var": 2,
"prefer-const": 2,
"no-use-before-define": [2, "nofunc"],
"camelcase": 2,
"no-lonely-if": 2,
Expand Down
30 changes: 15 additions & 15 deletions __tests__/bin-readme.js
@@ -1,8 +1,8 @@
var path = require('path'),
os = require('os'),
exec = require('child_process').exec,
tmp = require('tmp'),
fs = require('fs-extra');
const path = require('path');
const os = require('os');
const exec = require('child_process').exec;
const tmp = require('tmp');
const fs = require('fs-extra');

function documentation(args, options, parseJSON) {
return new Promise((resolve, reject) => {
Expand All @@ -23,13 +23,13 @@ function documentation(args, options, parseJSON) {
}

describe('readme command', function() {
var fixtures = path.join(__dirname, 'fixture/readme');
var sourceFile = path.join(fixtures, 'index.js');
var d;
var removeCallback;
const fixtures = path.join(__dirname, 'fixture/readme');
const sourceFile = path.join(fixtures, 'index.js');
let d;
let removeCallback;

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

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

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

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

Expand Down Expand Up @@ -110,7 +110,7 @@ describe('readme command', function() {
}
});

var badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input');
const badFixturePath = path.join(__dirname, 'fixture/bad/syntax.input');
test('errors on invalid syntax', async function() {
try {
await documentation(
Expand Down
46 changes: 23 additions & 23 deletions __tests__/bin-watch-serve.js
@@ -1,9 +1,9 @@
var path = require('path');
var os = require('os');
var get = require('./utils').get;
var spawn = require('child_process').spawn;
var fs = require('fs');
var pEvent = require('p-event');
const path = require('path');
const os = require('os');
const get = require('./utils').get;
const spawn = require('child_process').spawn;
const fs = require('fs');
const pEvent = require('p-event');

function documentation(args, options) {
if (!options) {
Expand All @@ -29,17 +29,17 @@ function normalize(result) {
const timeout = 20000;

test('harness', function() {
var docProcess = documentation(['serve', 'fixture/simple.input.js']);
const docProcess = documentation(['serve', 'fixture/simple.input.js']);
expect(docProcess).toBeTruthy();
docProcess.kill();
});

test(
'provides index.html',
function() {
var docProcess = documentation(['serve', 'fixture/simple.input.js']);
const docProcess = documentation(['serve', 'fixture/simple.input.js']);
return pEvent(docProcess.stdout, 'data').then(function(data) {
var portNumber = data
const portNumber = data
.toString()
.match(/documentation.js serving on port (\d+)/);
expect(portNumber).toBeTruthy();
Expand All @@ -55,13 +55,13 @@ test(
test(
'accepts port argument',
function() {
var docProcess = documentation([
const docProcess = documentation([
'serve',
'fixture/simple.input.js',
'--port=4004'
]);
return pEvent(docProcess.stdout, 'data').then(function(data) {
var portNumber = data
const portNumber = data
.toString()
.match(/documentation.js serving on port (\d+)/);
expect(portNumber).toBeTruthy();
Expand All @@ -77,11 +77,11 @@ test(
test(
'--watch',
function(done) {
var tmpFile = path.join(os.tmpdir(), '/simple.js');
const tmpFile = path.join(os.tmpdir(), '/simple.js');
fs.writeFileSync(tmpFile, '/** a function */function apples() {}');
var docProcess = documentation(['serve', tmpFile, '--watch']);
const docProcess = documentation(['serve', tmpFile, '--watch']);
pEvent(docProcess.stdout, 'data').then(function(data) {
var portNumber = data
const portNumber = data
.toString()
.match(/documentation.js serving on port (\d+)/);
expect(portNumber).toBeTruthy();
Expand All @@ -108,14 +108,14 @@ test(
test(
'--watch',
function(done) {
var tmpDir = os.tmpdir();
var a = path.join(tmpDir, '/simple.js');
var b = path.join(tmpDir, '/required.js');
const tmpDir = os.tmpdir();
const a = path.join(tmpDir, '/simple.js');
const b = path.join(tmpDir, '/required.js');
fs.writeFileSync(a, 'require("./required")');
fs.writeFileSync(b, '/** soup */function soup() {}');
var docProcess = documentation(['serve', a, '--watch']);
const docProcess = documentation(['serve', a, '--watch']);
docProcess.stdout.once('data', function(data) {
var portNumber = data
const portNumber = data
.toString()
.match(/documentation.js serving on port (\d+)/);
expect(portNumber).toBeTruthy();
Expand All @@ -142,12 +142,12 @@ test(
test(
'error page',
function() {
var tmpDir = os.tmpdir();
var a = path.join(tmpDir, '/simple.js');
const tmpDir = os.tmpdir();
const a = path.join(tmpDir, '/simple.js');
fs.writeFileSync(a, '**');
var docProcess = documentation(['serve', a, '--watch']);
const docProcess = documentation(['serve', a, '--watch']);
return pEvent(docProcess.stdout, 'data').then(function(data) {
var portNumber = data
const portNumber = data
.toString()
.match(/documentation.js serving on port (\d+)/);
expect(portNumber).toBeTruthy();
Expand Down
51 changes: 32 additions & 19 deletions __tests__/bin.js
@@ -1,10 +1,10 @@
/* global jasmine */

var path = require('path'),
os = require('os'),
exec = require('child_process').exec,
tmp = require('tmp'),
fs = require('fs-extra');
const path = require('path');
const os = require('os');
const exec = require('child_process').exec;
const tmp = require('tmp');
const fs = require('fs-extra');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

Expand Down Expand Up @@ -160,9 +160,9 @@ describe('invalid arguments', function() {
});

test('--config', async function() {
var dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
const dst = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
fs.mkdirSync(dst);
var outputIndex = path.join(dst, 'index.html');
const outputIndex = path.join(dst, 'index.html');
const data = await documentation(
[
'build -c fixture/html/documentation.yml -f html fixture/html/nested.input.js -o ' +
Expand All @@ -171,7 +171,7 @@ test('--config', async function() {
{},
false
);
var output = fs.readFileSync(outputIndex, 'utf8');
const output = fs.readFileSync(outputIndex, 'utf8');
expect(output).toMatchSnapshot();
});

Expand All @@ -185,7 +185,11 @@ describe('lint command', function() {
try {
await documentation(['lint fixture/lint/lint.input.js'], {}, false);
} catch (err) {
var data = err.stderr.toString().split('\n').slice(2).join('\n');
const data = err.stderr
.toString()
.split('\n')
.slice(2)
.join('\n');
expect(data).toMatchSnapshot();
}
});
Expand Down Expand Up @@ -284,7 +288,7 @@ test('--infer-private flag', async function() {
});

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

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

test('write to html', async function() {
var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
const dstDir = path.join(
os.tmpdir(),
(Date.now() + Math.random()).toString()
);
fs.mkdirSync(dstDir);

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

test('write to html with custom theme', async function() {
var dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
const dstDir = path.join(
os.tmpdir(),
(Date.now() + Math.random()).toString()
);
fs.mkdirSync(dstDir);

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

test('write to html, highlightAuto', function() {
var fixture = 'fixture/auto_lang_hljs/multilanguage.input.js',
config = 'fixture/auto_lang_hljs/config.yml',
dstDir = path.join(os.tmpdir(), (Date.now() + Math.random()).toString());
const fixture = 'fixture/auto_lang_hljs/multilanguage.input.js';
const config = 'fixture/auto_lang_hljs/config.yml';
const dstDir = path.join(
os.tmpdir(),
(Date.now() + Math.random()).toString()
);

fs.mkdirSync(dstDir);

Expand All @@ -336,7 +349,7 @@ test('write to html, highlightAuto', function() {
{},
false
).then(() => {
var result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8');
const result = fs.readFileSync(path.join(dstDir, 'index.html'), 'utf8');
expect(
result.indexOf('<span class="hljs-number">42</span>') > 0
).toBeTruthy();
Expand Down Expand Up @@ -371,10 +384,10 @@ test('build --document-exported', async function() {
});

test('build large file without error (no deoptimized styling error)', function() {
var dstFile =
const dstFile =
path.join(os.tmpdir(), (Date.now() + Math.random()).toString()) + '.js';
var contents = '';
for (var i = 0; i < 4e4; i++) {
let contents = '';
for (let i = 0; i < 4e4; i++) {
contents += '/* - */\n';
}
fs.writeFileSync(dstFile, contents, 'utf8');
Expand Down
12 changes: 6 additions & 6 deletions __tests__/format_type.js
@@ -1,9 +1,9 @@
/*eslint max-len: 0 */

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

function stringify(children) {
return remark().stringify({
Expand All @@ -13,8 +13,8 @@ function stringify(children) {
}

test('formatType', function() {
var linkerStack = new LinkerStack({});
var formatType = _formatType.bind(undefined, linkerStack.link);
const linkerStack = new LinkerStack({});
const formatType = _formatType.bind(undefined, linkerStack.link);
[
['Foo', 'Foo'],
['null', 'null'],
Expand Down
20 changes: 10 additions & 10 deletions __tests__/index.js
@@ -1,12 +1,12 @@
var documentation = require('../src/');
var os = require('os');
var path = require('path');
var fs = require('fs');
const documentation = require('../src/');
const os = require('os');
const path = require('path');
const fs = require('fs');

function inputs(contents) {
var dirEntry = os.tmpdir();
var paths = {};
for (var filename in contents) {
const dirEntry = os.tmpdir();
const paths = {};
for (const filename in contents) {
paths[filename] = path.join(dirEntry, '/', filename);
fs.writeFileSync(paths[filename], contents[filename]);
}
Expand All @@ -22,7 +22,7 @@ function cleanup(comments) {
}

test('lint', async function() {
var { paths } = inputs({
const { paths } = inputs({
'index.js': '/** hi */var name = 1;'
});

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

test('build', async function() {
var { paths } = inputs({
const { paths } = inputs({
'index.js': '/** hi */var name = 1;'
});

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

test('expandInputs', async function() {
var { paths } = inputs({
const { paths } = inputs({
'index.js': '/** hi */var name = 1;'
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/lib/filter_access.js
@@ -1,4 +1,4 @@
var filterAccess = require('../../src/filter_access');
const filterAccess = require('../../src/filter_access');

test('filterAccess ignore', function() {
expect(
Expand Down

0 comments on commit 7d74060

Please sign in to comment.