Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adjust indentation for stricter linting #14431

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rules:
MemberExpression: off,
ObjectExpression: first,
SwitchCase: 1}]
indent-legacy: 0
indent-legacy: off

# Custom rules in tools/eslint-rules
require-buffer: error
Expand Down
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: error
Expand Down
4 changes: 2 additions & 2 deletions test/addons-napi/test_fatal/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (process.argv[2] === 'child') {
}

const p = child_process.spawnSync(
process.execPath, [ '--napi-modules', __filename, 'child' ]);
process.execPath, [ '--napi-modules', __filename, 'child' ]);
assert.ifError(p.error);
assert.ok(p.stderr.toString().includes(
'FATAL ERROR: test_fatal::Test fatal message'));
'FATAL ERROR: test_fatal::Test fatal message'));
6 changes: 4 additions & 2 deletions test/addons-napi/test_general/testInstanceOf.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ if (typeof Symbol !== 'undefined' && 'hasInstance' in Symbol &&
typeof Symbol.hasInstance === 'symbol') {

function compareToNative(theObject, theConstructor) {
assert.strictEqual(addon.doInstanceOf(theObject, theConstructor),
(theObject instanceof theConstructor));
assert.strictEqual(
addon.doInstanceOf(theObject, theConstructor),
(theObject instanceof theConstructor)
);
}

function MyClass() {}
Expand Down
15 changes: 8 additions & 7 deletions test/async-hooks/init-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ class ActivityCollector {
}

exports = module.exports = function initHooks({
oninit,
onbefore,
onafter,
ondestroy,
allowNoInit,
logid,
logtype } = {}) {
oninit,
Copy link
Contributor

@refack refack Jul 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is very C++, but not my cup of tea.
If there are no objections I'd rather have

exports = module.exports = function initHooks(
  { oninit, onbefore, onafter, ondestroy, allowNoInit, logid, logtype } = {}) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh I'd prefer the form in the PR, because imagine what that variant would look like if I were to add another option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's definatly at it's limit... Although at a later stage we could move the destructuring into the function's body...
Anyway, I'm not strongly opposed to current format.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved readability slightly by adding a new line after logtype...

onbefore,
onafter,
ondestroy,
allowNoInit,
logid,
logtype
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR about whitespace, but could we enforce trailing commas? makes things easier in git when another field is added and only have a 1 line change instead of 2.

Copy link
Contributor

@vsemozhetbyt vsemozhetbyt Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to propose this for the docs, but it seems this lacks approvement:
#12557

} = {}) {
return new ActivityCollector(process.hrtime(), {
oninit,
onbefore,
Expand Down
4 changes: 2 additions & 2 deletions test/async-hooks/test-embedder.api.async-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ assert.throws(() => new AsyncResource('invalid_trigger_id', null),
/^RangeError: triggerAsyncId must be an unsigned integer$/);

assert.strictEqual(
new AsyncResource('default_trigger_id').triggerAsyncId(),
async_hooks.executionAsyncId()
new AsyncResource('default_trigger_id').triggerAsyncId(),
async_hooks.executionAsyncId()
);
Copy link
Contributor

@XadillaX XadillaX Jul 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO I'd prefer to put the ) on the last line. e.g.

assert.strictEqual(
  new AsyncResource('default_trigger_id').triggerAsyncId(),
  async_hooks.executionAsyncId());

But both of them are OK.


// create first custom event 'alcazares' with triggerAsyncId derived
Expand Down
6 changes: 3 additions & 3 deletions test/async-hooks/test-internal-nexttick-default-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ process.on('exit', function() {

const as = hooks.activitiesOfTypes('TickObject');
checkInvocations(as[0], {
init: 1, before: 1, after: 1, destroy: 1
init: 1, before: 1, after: 1, destroy: 1
}, 'when process exits');
checkInvocations(as[1], {
init: 1, before: 1, after: 1, destroy: 1
init: 1, before: 1, after: 1, destroy: 1
}, 'when process exits');
checkInvocations(as[2], {
init: 1, before: 1, after: 1, destroy: 1
init: 1, before: 1, after: 1, destroy: 1
}, 'when process exits');
});
112 changes: 56 additions & 56 deletions test/common/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,53 +100,53 @@ function parseDNSPacket(buffer) {
.replace(/(.{4}(?!$))/g, '$1:');
break;
case types.TXT:
{
let position = offset;
rr.entries = [];
while (position < offset + dataLength) {
const txtLength = buffer[offset];
rr.entries.push(buffer.toString('utf8',
position + 1,
position + 1 + txtLength));
position += 1 + txtLength;
}
assert.strictEqual(position, offset + dataLength);
break;
{
let position = offset;
rr.entries = [];
while (position < offset + dataLength) {
const txtLength = buffer[offset];
rr.entries.push(buffer.toString('utf8',
position + 1,
position + 1 + txtLength));
position += 1 + txtLength;
}
assert.strictEqual(position, offset + dataLength);
break;
}
case types.MX:
{
rr.priority = buffer.readInt16BE(buffer, offset);
offset += 2;
const { nread, domain } = readDomainFromPacket(buffer, offset);
rr.exchange = domain;
assert.strictEqual(nread, dataLength);
break;
}
{
rr.priority = buffer.readInt16BE(buffer, offset);
offset += 2;
const { nread, domain } = readDomainFromPacket(buffer, offset);
rr.exchange = domain;
assert.strictEqual(nread, dataLength);
break;
}
case types.NS:
case types.CNAME:
case types.PTR:
{
const { nread, domain } = readDomainFromPacket(buffer, offset);
rr.value = domain;
assert.strictEqual(nread, dataLength);
break;
}
{
const { nread, domain } = readDomainFromPacket(buffer, offset);
rr.value = domain;
assert.strictEqual(nread, dataLength);
break;
}
case types.SOA:
{
const mname = readDomainFromPacket(buffer, offset);
const rname = readDomainFromPacket(buffer, offset + mname.nread);
rr.nsname = mname.domain;
rr.hostmaster = rname.domain;
const trailerOffset = offset + mname.nread + rname.nread;
rr.serial = buffer.readUInt32BE(trailerOffset);
rr.refresh = buffer.readUInt32BE(trailerOffset + 4);
rr.retry = buffer.readUInt32BE(trailerOffset + 8);
rr.expire = buffer.readUInt32BE(trailerOffset + 12);
rr.minttl = buffer.readUInt32BE(trailerOffset + 16);
{
const mname = readDomainFromPacket(buffer, offset);
const rname = readDomainFromPacket(buffer, offset + mname.nread);
rr.nsname = mname.domain;
rr.hostmaster = rname.domain;
const trailerOffset = offset + mname.nread + rname.nread;
rr.serial = buffer.readUInt32BE(trailerOffset);
rr.refresh = buffer.readUInt32BE(trailerOffset + 4);
rr.retry = buffer.readUInt32BE(trailerOffset + 8);
rr.expire = buffer.readUInt32BE(trailerOffset + 12);
rr.minttl = buffer.readUInt32BE(trailerOffset + 16);

assert.strictEqual(trailerOffset + 20, dataLength);
break;
}
assert.strictEqual(trailerOffset + 20, dataLength);
break;
}
default:
throw new Error(`Unknown RR type ${rr.type}`);
}
Expand Down Expand Up @@ -253,23 +253,23 @@ function writeDNSPacket(parsed) {
case 'NS':
case 'CNAME':
case 'PTR':
{
const domain = writeDomainName(rr.exchange || rr.value);
rdLengthBuf[0] += domain.length;
buffers.push(domain);
break;
}
{
const domain = writeDomainName(rr.exchange || rr.value);
rdLengthBuf[0] += domain.length;
buffers.push(domain);
break;
}
case 'SOA':
{
const mname = writeDomainName(rr.nsname);
const rname = writeDomainName(rr.hostmaster);
rdLengthBuf[0] = mname.length + rname.length + 20;
buffers.push(mname, rname);
buffers.push(new Uint32Array([
rr.serial, rr.refresh, rr.retry, rr.expire, rr.minttl
]));
break;
}
{
const mname = writeDomainName(rr.nsname);
const rname = writeDomainName(rr.hostmaster);
rdLengthBuf[0] = mname.length + rname.length + 20;
buffers.push(mname, rname);
buffers.push(new Uint32Array([
rr.serial, rr.refresh, rr.retry, rr.expire, rr.minttl
]));
break;
}
default:
throw new Error(`Unknown RR type ${rr.type}`);
}
Expand Down
24 changes: 12 additions & 12 deletions test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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 sendEnd(socket) {
Expand Down Expand Up @@ -74,7 +74,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 @@ -238,7 +238,7 @@ TestSession.prototype.sendInspectorCommands = function(commands) {
this.sendAll_(commands, () => {
timeoutId = setTimeout(() => {
assert.fail(`Messages without response: ${
Object.keys(this.messages_).join(', ')}`);
Object.keys(this.messages_).join(', ')}`);
}, TIMEOUT);
});
});
Expand Down Expand Up @@ -282,7 +282,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 @@ -296,8 +296,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 @@ -350,10 +350,10 @@ TestSession.prototype.assertClosed = function() {

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


Expand All @@ -366,7 +366,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
22 changes: 11 additions & 11 deletions test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,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
4 changes: 2 additions & 2 deletions test/inspector/test-not-blocked-on-idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const helper = require('./inspector-helper.js');
function shouldShutDown(session) {
session
.sendInspectorCommands([
{ 'method': 'Debugger.enable' },
{ 'method': 'Debugger.pause' },
{ 'method': 'Debugger.enable' },
{ 'method': 'Debugger.pause' },
])
.disconnect(true);
}
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
Expand Up @@ -19,7 +19,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

/* 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 @@ -501,10 +501,10 @@ assert.throws(() => {
let threw = false;
try {
assert.throws(
function() {
throw ({}); // eslint-disable-line no-throw-literal
},
Array
function() {
throw ({}); // eslint-disable-line no-throw-literal
},
Array
);
} catch (e) {
threw = true;
Expand Down
Loading