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

tools: eslint object curly spacing #14162

Closed
wants to merge 6 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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test/fixtures
test/disabled
test/tmp*/
tools/eslint
tools/icu
node_modules
benchmark/tmp/
doc/**/*.js
7 changes: 4 additions & 3 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,17 @@ rules:
}]
no-tabs: error
no-trailing-spaces: error
object-curly-spacing: [error, always]
Copy link
Member

Choose a reason for hiding this comment

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

You can reduce the churn slightly and conform more closely to the house style by doing this instead:

  object-curly-spacing: [error, always, {objectsInObjects: false}]

That flags 2144 problems in the current code base, instead of the 2183 flagged with the PR as it is. That's not a huge reduction, but every little bit helps to make backporting less awful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

99% of these changes were made using eslint --fix automatically. Except for ~30 cases where the insertion of spaces then caused the line to grow longer than 80 characters, which I cleaned up manually following my own stylistic judgement and ensuring eslint passes.

Copy link
Member

Choose a reason for hiding this comment

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

In general it's useful to do the automatic ones as one commit, and then the manual ones as a separate one. They'll get squashed on landing, but it means people can review the ones that weren't just an eslint --fix (which are probably the more interesting ones).

one-var-declaration-per-line: error
operator-linebreak: [error, after]
quotes: [error, single, avoid-escape]
semi: error
semi-spacing: error
space-before-blocks: [error, always]
space-before-function-paren: [error, {
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
anonymous: never,
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unrelated and should be done in another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done in response to: #14162 (comment)

I understand it's not 100% the same property but opening another PR seems a little bureaucratic. It's a purely aesthetic change in line with the comment.

Copy link
Contributor

@aqrln aqrln Jul 21, 2017

Choose a reason for hiding this comment

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

@sebdeckers "bureaucratic" rules have their reasons ;) One of them is that keeping commits logically separated makes backporting a lot easier. Most of the changes from this PR are probably going to have numerous conflicts with release branches, while this one would have been cherry-picked cleanly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @aqrln in the general case, but in this case since it's most probably gonna be backported by cherry picking just the rules change, then running eslint --fix, hopefully this wouldn't cause a mess 🙏

named: never,
asyncArrow: always
}]
space-in-parens: [error, never]
space-infix-ops: error
Expand Down
2 changes: 1 addition & 1 deletion benchmark/_test-double-benchmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
const http = require('http');

http.get(process.env.path, function() {
console.log(JSON.stringify({throughput: 1}));
console.log(JSON.stringify({ throughput: 1 }));
});
2 changes: 1 addition & 1 deletion benchmark/crypto/aes-gcm-throughput.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
var common = require('../common.js');
var crypto = require('crypto');
var keylen = {'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32};
var keylen = { 'aes-128-gcm': 16, 'aes-192-gcm': 24, 'aes-256-gcm': 32 };
var bench = common.createBenchmark(main, {
n: [500],
cipher: ['aes-128-gcm', 'aes-192-gcm', 'aes-256-gcm'],
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-add-remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var events = require('events');

var bench = common.createBenchmark(main, {n: [25e4]});
var bench = common.createBenchmark(main, { n: [25e4] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-emit-multi-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e6]});
var bench = common.createBenchmark(main, { n: [2e6] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-emit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e6]});
var bench = common.createBenchmark(main, { n: [2e6] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listener-count-on-prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [5e7]});
var bench = common.createBenchmark(main, { n: [5e7] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners-many.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [5e6]});
var bench = common.createBenchmark(main, { n: [5e6] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [5e6]});
var bench = common.createBenchmark(main, { n: [5e6] });

function main(conf) {
var n = conf.n | 0;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/events/ee-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var common = require('../common.js');
var EventEmitter = require('events').EventEmitter;

var bench = common.createBenchmark(main, {n: [2e7]});
var bench = common.createBenchmark(main, { n: [2e7] });

function main(conf) {
var n = conf.n | 0;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/url-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const common = require('../common.js');
const url = require('url');

const inputs = {
slashes: {slashes: true, host: 'localhost'},
file: {protocol: 'file:', pathname: '/foo'},
slashes: { slashes: true, host: 'localhost' },
file: { protocol: 'file:', pathname: '/foo' },
};

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/util/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, {
const inputs = {
'string': ['Hello, my name is %s', 'fred'],
'number': ['Hi, I was born in %d', 1942],
'object': ['An error occurred %j', {msg: 'This is an error', code: 'ERR'}],
'object': ['An error occurred %j', { msg: 'This is an error', code: 'ERR' }],
'unknown': ['hello %a', 'test'],
'no-replace': [1, 2]
};
Expand Down
10 changes: 5 additions & 5 deletions benchmark/util/inspect-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ const bench = common.createBenchmark(main, {

function twoDifferentProxies(n) {
// This one should be slower because we're looking up multiple proxies.
const proxyA = new Proxy({}, {get: () => {}});
const proxyB = new Proxy({}, {get: () => {}});
const proxyA = new Proxy({}, { get: () => {} });
const proxyB = new Proxy({}, { get: () => {} });
bench.start();
for (var i = 0; i < n; i += 1)
util.inspect({a: proxyA, b: proxyB}, {showProxy: true});
util.inspect({ a: proxyA, b: proxyB }, { showProxy: true });
bench.end(n);
}

function oneProxy(n) {
// This one should be a bit faster because of the internal caching.
const proxy = new Proxy({}, {get: () => {}});
const proxy = new Proxy({}, { get: () => {} });
bench.start();
for (var i = 0; i < n; i += 1)
util.inspect({a: proxy, b: proxy}, {showProxy: true});
util.inspect({ a: proxy, b: proxy }, { showProxy: true });
bench.end(n);
}

Expand Down
4 changes: 2 additions & 2 deletions benchmark/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ var util = require('util');

var common = require('../common.js');

var bench = common.createBenchmark(main, {n: [5e6]});
var bench = common.createBenchmark(main, { n: [5e6] });

function main(conf) {
var n = conf.n | 0;

bench.start();
for (var i = 0; i < n; i += 1) {
util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'});
util.inspect({ a: 'a', b: 'b', c: 'c', d: 'd' });
}
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/vm/run-in-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vm = require('vm');

function main(conf) {
const n = +conf.n;
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
const options = conf.breakOnSigint ? { breakOnSigint: true } : {};
const withSigintListener = !!conf.withSigintListener;

process.removeAllListeners('SIGINT');
Expand Down
2 changes: 1 addition & 1 deletion benchmark/vm/run-in-this-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const vm = require('vm');

function main(conf) {
const n = +conf.n;
const options = conf.breakOnSigint ? {breakOnSigint: true} : {};
const options = conf.breakOnSigint ? { breakOnSigint: true } : {};
const withSigintListener = !!conf.withSigintListener;

process.removeAllListeners('SIGINT');
Expand Down
2 changes: 0 additions & 2 deletions doc/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## Docs-specific linter rules

rules:
object-curly-spacing: [error, always]

# ease some restrictions in doc examples
no-restricted-properties: off
no-undef: off
Expand Down
2 changes: 1 addition & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Console.prototype.error = Console.prototype.warn;


Console.prototype.dir = function dir(object, options) {
options = Object.assign({customInspect: false}, options);
options = Object.assign({ customInspect: false }, options);
write(this._ignoreErrors,
this._stdout,
`${util.inspect(object, options)}\n`,
Expand Down
2 changes: 1 addition & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Socket.prototype.send = function(buffer,
this._healthCheck();

if (this._bindState === BIND_STATE_UNBOUND)
this.bind({port: 0, exclusive: true}, null);
this.bind({ port: 0, exclusive: true }, null);

if (list.length === 0)
list.push(Buffer.alloc(0));
Expand Down
2 changes: 1 addition & 1 deletion lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function lookup(hostname, options, callback) {
if (matchedFamily) {
if (all) {
process.nextTick(
callback, null, [{address: hostname, family: matchedFamily}]);
callback, null, [{ address: hostname, family: matchedFamily }]);
} else {
process.nextTick(callback, null, hostname, matchedFamily);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ function statsFromValues() {

// Don't allow mode to accidentally be overwritten.
Object.defineProperties(fs, {
F_OK: {enumerable: true, value: constants.F_OK || 0},
R_OK: {enumerable: true, value: constants.R_OK || 0},
W_OK: {enumerable: true, value: constants.W_OK || 0},
X_OK: {enumerable: true, value: constants.X_OK || 0},
F_OK: { enumerable: true, value: constants.F_OK || 0 },
R_OK: { enumerable: true, value: constants.R_OK || 0 },
W_OK: { enumerable: true, value: constants.W_OK || 0 },
X_OK: { enumerable: true, value: constants.X_OK || 0 },
});

function handleError(val, callback) {
Expand Down
2 changes: 1 addition & 1 deletion lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Session extends EventEmitter {
throw new Error('Session is not connected');
}
const id = this[nextIdSymbol]++;
const message = {id, method};
const message = { id, method };
if (params) {
message['params'] = params;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
// wrap it
source = Module.wrap(source);
// compile the script, this will throw if it fails
new vm.Script(source, {displayErrors: true, filename});
new vm.Script(source, { displayErrors: true, filename });
}

// Below you find a minimal module system, which is used to load the node
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const handleConversion = {
},

got: function(message, handle, emit) {
var socket = new net.Socket({handle: handle});
var socket = new net.Socket({ handle: handle });
socket.readable = socket.writable = true;

// if the socket was created by net.Server we will track the socket
Expand Down Expand Up @@ -584,7 +584,7 @@ function setupChannel(target, channel) {
options);
}

options = Object.assign({swallowErrors: false}, options);
options = Object.assign({ swallowErrors: false }, options);

if (this.connected) {
return this._send(message, handle, options, callback);
Expand All @@ -606,7 +606,7 @@ function setupChannel(target, channel) {

// Support legacy function signature
if (typeof options === 'boolean') {
options = {swallowErrors: options};
options = { swallowErrors: options };
}

// package messages with a handle object
Expand Down Expand Up @@ -840,7 +840,7 @@ function _validateStdio(stdio, sync) {
}

if (stdio === 'ignore') {
acc.push({type: 'ignore'});
acc.push({ type: 'ignore' });
} else if (stdio === 'pipe' || typeof stdio === 'number' && stdio < 0) {
var a = {
type: 'pipe',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/cluster/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const cluster = new EventEmitter();
const intercom = new EventEmitter();
const SCHED_NONE = 1;
const SCHED_RR = 2;
const {isLegalPort} = require('internal/net');
const { isLegalPort } = require('internal/net');

module.exports = cluster;

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/socket_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ class SocketListReceive extends EventEmitter {
}
}

module.exports = {SocketListSend, SocketListReceive};
module.exports = { SocketListSend, SocketListReceive };
4 changes: 2 additions & 2 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ function createClassWrapper(type) {
}
// Mask the wrapper function name and length values
Object.defineProperties(fn, {
name: {value: type.name},
length: {value: type.length}
name: { value: type.name },
length: { value: type.length }
});
Object.setPrototypeOf(fn, type);
fn.prototype = type.prototype;
Expand Down
4 changes: 2 additions & 2 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ Interface.prototype._getDisplayPos = function(str) {
}
var cols = offset % col;
var rows = row + (offset - cols) / col;
return {cols: cols, rows: rows};
return { cols: cols, rows: rows };
};


Expand All @@ -711,7 +711,7 @@ Interface.prototype._getCursorPos = function() {
rows++;
cols = 0;
}
return {cols: cols, rows: rows};
return { cols: cols, rows: rows };
};


Expand Down
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ REPLServer.prototype.parseREPLKeyword = function(keyword, rest) {

REPLServer.prototype.defineCommand = function(keyword, cmd) {
if (typeof cmd === 'function') {
cmd = {action: cmd};
cmd = { action: cmd };
} else if (typeof cmd.action !== 'function') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'action', 'function', cmd.action);
Expand Down
14 changes: 7 additions & 7 deletions test/addons-napi/test_make_callback_recurse/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ function checkDomains() {
const d2 = domain.create();
const d3 = domain.create();

makeCallback({domain: d1}, common.mustCall(function() {
makeCallback({ domain: d1 }, common.mustCall(function() {
assert.strictEqual(d1, process.domain);
makeCallback({domain: d2}, common.mustCall(function() {
makeCallback({ domain: d2 }, common.mustCall(function() {
assert.strictEqual(d2, process.domain);
makeCallback({domain: d3}, common.mustCall(function() {
makeCallback({ domain: d3 }, common.mustCall(function() {
assert.strictEqual(d3, process.domain);
}));
assert.strictEqual(d2, process.domain);
Expand All @@ -119,11 +119,11 @@ function checkDomains() {
const d2 = domain.create();
const d3 = domain.create();

makeCallback({domain: d1}, common.mustCall(function() {
makeCallback({ domain: d1 }, common.mustCall(function() {
assert.strictEqual(d1, process.domain);
makeCallback({domain: d2}, common.mustCall(function() {
makeCallback({ domain: d2 }, common.mustCall(function() {
assert.strictEqual(d2, process.domain);
makeCallback({domain: d3}, common.mustCall(function() {
makeCallback({ domain: d3 }, common.mustCall(function() {
assert.strictEqual(d3, process.domain);
}));
assert.strictEqual(d2, process.domain);
Expand All @@ -139,7 +139,7 @@ function checkDomains() {
d.on('error', common.mustCall(function(e) {
assert.strictEqual(e.message, `throw from domain ${id}`);
}));
makeCallback({domain: d}, function() {
makeCallback({ domain: d }, function() {
throw new Error(`throw from domain ${id}`);
});
throw new Error('UNREACHABLE');
Expand Down
Loading