Skip to content

Commit

Permalink
test: adjust indentation for stricter linting
Browse files Browse the repository at this point in the history
ESLint 4.x has stricter linting than previous versions. We are currently
using the legacy indentation rules in the test directory. This commit
changes the indentation of files to comply with the stricter 4.x linting
and enable stricter linting in the test directory.

Backport-PR-URL: nodejs#14522
Backport-Reviewed-By: Anna Henningsen <[email protected]>

PR-URL: nodejs#14431
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Vse Mozhet Byt <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
  • Loading branch information
Trott committed Aug 15, 2017
1 parent d7dba1b commit b6342f5
Show file tree
Hide file tree
Showing 76 changed files with 580 additions and 560 deletions.
10 changes: 10 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
## Test-specific linter rules

rules:
# Stylistic Issues
# http://eslint.org/docs/rules/#stylistic-issues
indent: [error, 2, {ArrayExpression: first,
CallExpression: {arguments: first},
FunctionDeclaration: {parameters: first},
FunctionExpression: {parameters: first},
MemberExpression: off,
ObjectExpression: first,
SwitchCase: 1}]
indent-legacy: off
# ECMAScript 6
# http://eslint.org/docs/rules/#ecmascript-6
no-var: 2
Expand Down
4 changes: 2 additions & 2 deletions test/debugger/test-debugger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function doTest(cb, done) {
c.end();
c.on('end', function() {
console.error(
'>>> killing node process %d\n\n',
nodeProcess.pid);
'>>> killing node process %d\n\n',
nodeProcess.pid);
nodeProcess.kill();
done();
});
Expand Down
26 changes: 13 additions & 13 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function send(socket, message, id, callback) {
for (let i = 0; i < messageBuf.length; i++)
messageBuf[i] = messageBuf[i] ^ (1 << (i % 4));
socket.write(
Buffer.concat([wsHeaderBuf.slice(0, maskOffset + 4), messageBuf]),
callback);
Buffer.concat([wsHeaderBuf.slice(0, maskOffset + 4), messageBuf]),
callback);
}

function parseWSFrame(buffer, handler) {
Expand All @@ -65,7 +65,7 @@ function parseWSFrame(buffer, handler) {
if (buffer.length < bodyOffset + dataLen)
return 0;
const message = JSON.parse(
buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8'));
buffer.slice(bodyOffset, bodyOffset + dataLen).toString('utf8'));
if (DEBUG)
console.log('[received]', JSON.stringify(message));
handler(message);
Expand Down Expand Up @@ -214,7 +214,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
this.sendAll_(commands, () => {
timeoutId = setTimeout(() => {
common.fail(`Messages without response: ${
Object.keys(this.messages_).join(', ')}`);
Object.keys(this.messages_).join(', ')}`);
}, TIMEOUT);
});
});
Expand All @@ -237,7 +237,7 @@ TestSession.prototype.expectMessages = function(expects) {
if (!(expects instanceof Array)) expects = [ expects ];

const callback = this.createCallbackWithTimeout_(
`Matching response was not received:\n${expects[0]}`);
`Matching response was not received:\n${expects[0]}`);
this.messagefilter_ = (message) => {
if (expects[0](message))
expects.shift();
Expand All @@ -251,8 +251,8 @@ TestSession.prototype.expectMessages = function(expects) {

TestSession.prototype.expectStderrOutput = function(regexp) {
this.harness_.addStderrFilter(
regexp,
this.createCallbackWithTimeout_(`Timed out waiting for ${regexp}`));
regexp,
this.createCallbackWithTimeout_(`Timed out waiting for ${regexp}`));
return this;
};

Expand Down Expand Up @@ -293,10 +293,10 @@ TestSession.prototype.disconnect = function(childDone) {

TestSession.prototype.testHttpResponse = function(path, check) {
return this.enqueue((callback) =>
checkHttpResponse(this.harness_.port, path, (err, response) => {
check.call(this, err, response);
callback();
}));
checkHttpResponse(this.harness_.port, path, (err, response) => {
check.call(this, err, response);
callback();
}));
};


Expand All @@ -310,7 +310,7 @@ function Harness(port, childProcess) {
this.running_ = true;

childProcess.stdout.on('data', makeBufferingDataCallback(
(line) => console.log('[out]', line)));
(line) => console.log('[out]', line)));


childProcess.stderr.on('data', makeBufferingDataCallback((message) => {
Expand Down Expand Up @@ -427,7 +427,7 @@ Harness.prototype.expectShutDown = function(errorCode) {

exports.startNodeForInspectorTest = function(callback) {
const child = spawn(process.execPath,
[ '--inspect', '--debug-brk', mainScript ]);
[ '--inspect', '--debug-brk', mainScript ]);

const timeoutId = timeout('Child process did not start properly', 4);

Expand Down
22 changes: 11 additions & 11 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ function testBreakpointOnStart(session) {
function testSetBreakpointAndResume(session) {
console.log('[test]', 'Setting a breakpoint and verifying it is hit');
const commands = [
{ 'method': 'Debugger.setBreakpointByUrl',
'params': { 'lineNumber': 5,
'url': session.mainScriptPath,
'columnNumber': 0,
'condition': ''
}
},
{ 'method': 'Debugger.resume'},
[ { 'method': 'Debugger.getScriptSource',
'params': { 'scriptId': session.mainScriptId } },
expectMainScriptSource ],
{ 'method': 'Debugger.setBreakpointByUrl',
'params': { 'lineNumber': 5,
'url': session.mainScriptPath,
'columnNumber': 0,
'condition': ''
}
},
{ 'method': 'Debugger.resume'},
[ { 'method': 'Debugger.getScriptSource',
'params': { 'scriptId': session.mainScriptId } },
expectMainScriptSource ],
];
session
.sendInspectorCommands(commands)
Expand Down
6 changes: 3 additions & 3 deletions test/known_issues/test-http-path-contains-unicode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const http = require('http');
const expected = '/café🐶';

assert.strictEqual(
expected,
'/caf\u{e9}\u{1f436}',
'Sanity check that string literal produced the expected string'
expected,
'/caf\u{e9}\u{1f436}',
'Sanity check that string literal produced the expected string'
);

const server = http.createServer(common.mustCall(function(req, res) {
Expand Down
6 changes: 3 additions & 3 deletions test/known_issues/test-vm-proxy-failure-CP.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const assert = require('assert');
const vm = require('vm');

const handler = {
getOwnPropertyDescriptor: (target, prop) => {
throw new Error('whoops');
}
getOwnPropertyDescriptor: (target, prop) => {
throw new Error('whoops');
}
};
const sandbox = new Proxy({foo: 'bar'}, handler);
const context = vm.createContext(sandbox);
Expand Down
2 changes: 1 addition & 1 deletion test/message/throw_in_line_with_tabs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable indent-legacy, no-tabs */
/* eslint-disable indent, no-tabs */
'use strict';
require('../common');

Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ assert.throws(() => {
threw = false;
try {
assert.throws(
function() {
throw ({});
},
Array
function() {
throw ({});
},
Array
);
} catch (e) {
threw = true;
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-buffer-alloc.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ assert.strictEqual('<Buffer 81 a3 66 6f 6f a3 62 61 72>', x.inspect());

// Call .fill() first, stops valgrind warning about uninitialized memory reads.
Buffer.allocUnsafe(3.3).fill().toString();
// throws bad argument error in commit 43cb4ec
// throws bad argument error in commit 43cb4ec
Buffer.alloc(3.3).fill().toString();
assert.strictEqual(Buffer.allocUnsafe(-1).length, 0);
assert.strictEqual(Buffer.allocUnsafe(NaN).length, 0);
Expand Down Expand Up @@ -782,8 +782,8 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0);
'ucs-2',
'utf16le',
'utf-16le' ].forEach(function(enc) {
assert.strictEqual(Buffer.isEncoding(enc), true);
});
assert.strictEqual(Buffer.isEncoding(enc), true);
});

[ 'utf9',
'utf-7',
Expand All @@ -797,8 +797,8 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0);
1,
0,
-1 ].forEach(function(enc) {
assert.strictEqual(Buffer.isEncoding(enc), false);
});
assert.strictEqual(Buffer.isEncoding(enc), false);
});

// GH-5110
{
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-buffer-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function assertWrongList(value) {
}

const random10 = common.hasCrypto
? require('crypto').randomBytes(10)
: Buffer.alloc(10, 1);
? require('crypto').randomBytes(10)
: Buffer.alloc(10, 1);
const empty = Buffer.alloc(0);

assert.notDeepStrictEqual(random10, empty);
Expand All @@ -58,5 +58,5 @@ assert.deepStrictEqual(Buffer.concat([random10, empty, empty]), random10);
assert.deepStrictEqual(Buffer.concat([empty], 100), Buffer.alloc(100));
assert.deepStrictEqual(Buffer.concat([empty], 4096), Buffer.alloc(4096));
assert.deepStrictEqual(
Buffer.concat([random10], 40),
Buffer.concat([random10, Buffer.alloc(30)]));
Buffer.concat([random10], 40),
Buffer.concat([random10, Buffer.alloc(30)]));
58 changes: 29 additions & 29 deletions test/parallel/test-buffer-fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ testBufs('61c8b462c8b563c8b6', 12, 1, 'hex');
// Make sure this operation doesn't go on forever
buf1.fill('yKJh', 'hex');
assert.throws(() =>
buf1.fill('\u0222', 'hex'), /^TypeError: Invalid hex string$/);
buf1.fill('\u0222', 'hex'), /^TypeError: Invalid hex string$/);


// BASE64
Expand Down Expand Up @@ -183,23 +183,23 @@ deepStrictEqualValues(genBuffer(4, [hexBufFill, 1, -1]), [0, 0, 0, 0]);
// Check exceptions
assert.throws(() => buf1.fill(0, -1), /^RangeError: Out of range index$/);
assert.throws(() =>
buf1.fill(0, 0, buf1.length + 1),
buf1.fill(0, 0, buf1.length + 1),
/^RangeError: Out of range index$/);
assert.throws(() => buf1.fill('', -1), /^RangeError: Out of range index$/);
assert.throws(() =>
buf1.fill('', 0, buf1.length + 1),
buf1.fill('', 0, buf1.length + 1),
/^RangeError: Out of range index$/);
assert.throws(() =>
buf1.fill('a', 0, buf1.length, 'node rocks!'),
buf1.fill('a', 0, buf1.length, 'node rocks!'),
/^TypeError: Unknown encoding: node rocks!$/);
assert.throws(() =>
buf1.fill('a', 0, 0, NaN),
buf1.fill('a', 0, 0, NaN),
/^TypeError: encoding must be a string$/);
assert.throws(() =>
buf1.fill('a', 0, 0, null),
buf1.fill('a', 0, 0, null),
/^TypeError: encoding must be a string$/);
assert.throws(() =>
buf1.fill('a', 0, 0, 'foo'), /^TypeError: Unknown encoding: foo$/);
buf1.fill('a', 0, 0, 'foo'), /^TypeError: Unknown encoding: foo$/);


function genBuffer(size, args) {
Expand Down Expand Up @@ -270,10 +270,10 @@ function testBufs(string, offset, length, encoding) {

// Make sure these throw.
assert.throws(() =>
Buffer.allocUnsafe(8).fill('a', -1),
Buffer.allocUnsafe(8).fill('a', -1),
/^RangeError: Out of range index$/);
assert.throws(() =>
Buffer.allocUnsafe(8).fill('a', 0, 9),
Buffer.allocUnsafe(8).fill('a', 0, 9),
/^RangeError: Out of range index$/);

// Make sure this doesn't hang indefinitely.
Expand Down Expand Up @@ -396,36 +396,36 @@ assert.throws(() => {
}, /^RangeError: out of range index$/);

assert.deepStrictEqual(
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
Buffer.from('61006200610062006100620061006200', 'hex'));
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
Buffer.from('61006200610062006100620061006200', 'hex'));

assert.deepStrictEqual(
Buffer.allocUnsafeSlow(15).fill('ab', 'utf16le'),
Buffer.from('610062006100620061006200610062', 'hex'));
Buffer.allocUnsafeSlow(15).fill('ab', 'utf16le'),
Buffer.from('610062006100620061006200610062', 'hex'));

assert.deepStrictEqual(
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
Buffer.from('61006200610062006100620061006200', 'hex'));
Buffer.allocUnsafeSlow(16).fill('ab', 'utf16le'),
Buffer.from('61006200610062006100620061006200', 'hex'));
assert.deepStrictEqual(
Buffer.allocUnsafeSlow(16).fill('a', 'utf16le'),
Buffer.from('61006100610061006100610061006100', 'hex'));
Buffer.allocUnsafeSlow(16).fill('a', 'utf16le'),
Buffer.from('61006100610061006100610061006100', 'hex'));

assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('a', 'utf16le').toString('utf16le'),
'a'.repeat(8));
Buffer.allocUnsafeSlow(16).fill('a', 'utf16le').toString('utf16le'),
'a'.repeat(8));
assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('a', 'latin1').toString('latin1'),
'a'.repeat(16));
Buffer.allocUnsafeSlow(16).fill('a', 'latin1').toString('latin1'),
'a'.repeat(16));
assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('a', 'utf8').toString('utf8'),
'a'.repeat(16));
Buffer.allocUnsafeSlow(16).fill('a', 'utf8').toString('utf8'),
'a'.repeat(16));

assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('Љ', 'utf16le').toString('utf16le'),
'Љ'.repeat(8));
Buffer.allocUnsafeSlow(16).fill('Љ', 'utf16le').toString('utf16le'),
'Љ'.repeat(8));
assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('Љ', 'latin1').toString('latin1'),
'\t'.repeat(16));
Buffer.allocUnsafeSlow(16).fill('Љ', 'latin1').toString('latin1'),
'\t'.repeat(16));
assert.strictEqual(
Buffer.allocUnsafeSlow(16).fill('Љ', 'utf8').toString('utf8'),
'Љ'.repeat(8));
Buffer.allocUnsafeSlow(16).fill('Љ', 'utf8').toString('utf8'),
'Љ'.repeat(8));
12 changes: 6 additions & 6 deletions test/parallel/test-buffer-includes.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ assert(mixedByteStringUcs2.includes('\u03a3', 0, 'ucs2'));
assert(!mixedByteStringUcs2.includes('\u0396', 0, 'ucs2'));

assert.ok(
mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
mixedByteStringUcs2.includes(Buffer.from('bc', 'ucs2'), 0, 'ucs2'));
assert.ok(
mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
mixedByteStringUcs2.includes(Buffer.from('\u03a3', 'ucs2'), 0, 'ucs2'));
assert.ok(
!mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));
!mixedByteStringUcs2.includes(Buffer.from('\u0396', 'ucs2'), 0, 'ucs2'));

twoByteString = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');

Expand Down Expand Up @@ -208,7 +208,7 @@ assert(longBufferString.includes(pattern, 512), 'Long JABACABA..., Second J');

// Search for a non-ASCII string in a pure ASCII string.
const asciiString = Buffer.from(
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
'arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf');
assert(!asciiString.includes('\x2061'));
assert(asciiString.includes('leb', 0));

Expand Down Expand Up @@ -263,11 +263,11 @@ for (let lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
const patternBufferUcs2 =
allCharsBufferUcs2.slice(index, index + length);
assert.ok(
allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));
allCharsBufferUcs2.includes(patternBufferUcs2, 0, 'ucs2'));

const patternStringUcs2 = patternBufferUcs2.toString('ucs2');
assert.ok(
allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
allCharsBufferUcs2.includes(patternStringUcs2, 0, 'ucs2'));
}
}

Expand Down
Loading

0 comments on commit b6342f5

Please sign in to comment.