Skip to content

Commit 8b88c38

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
tools: lint for object literal spacing
There has been occasional nits for spacing in object literals in PRs but the project does not lint for it and it is not always handled consistently in the existing code, even on adjacent lines of a file. This change enables a linting rule requiring no space between the key and the colon, and requiring at least one space (but allowing for more so property values can be lined up if desired) between the colon and the value. This appears to be the most common style used in the current code base. Example code the complies with lint rule: myObj = { foo: 'bar' }; Examples that do not comply with the lint rule: myObj = { foo : 'bar' }; myObj = { foo:'bar' }; PR-URL: #6592 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 96b5aa8 commit 8b88c38

36 files changed

+151
-150
lines changed

.eslintrc

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ rules:
5757
comma-spacing: 2
5858
eol-last: 2
5959
indent: [2, 2, {SwitchCase: 1}]
60+
key-spacing: [2, {mode: "minimum"}]
6061
keyword-spacing: 2
6162
max-len: [2, 80, 2]
6263
new-parens: 2

benchmark/path/format.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ function main(conf) {
1818
ext: '.html',
1919
name: 'index'
2020
} : {
21-
root : '/',
22-
dir : '/home/user/dir',
23-
base : 'index.html',
24-
ext : '.html',
25-
name : 'index'
21+
root: '/',
22+
dir: '/home/user/dir',
23+
base: 'index.html',
24+
ext: '.html',
25+
name: 'index'
2626
};
2727

2828
// Force optimization before starting the benchmark

lib/_http_server.js

+61-61
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,67 @@ const httpSocketSetup = common.httpSocketSetup;
1616
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
1717

1818
const STATUS_CODES = exports.STATUS_CODES = {
19-
100 : 'Continue',
20-
101 : 'Switching Protocols',
21-
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
22-
200 : 'OK',
23-
201 : 'Created',
24-
202 : 'Accepted',
25-
203 : 'Non-Authoritative Information',
26-
204 : 'No Content',
27-
205 : 'Reset Content',
28-
206 : 'Partial Content',
29-
207 : 'Multi-Status', // RFC 4918
30-
208 : 'Already Reported',
31-
226 : 'IM Used',
32-
300 : 'Multiple Choices',
33-
301 : 'Moved Permanently',
34-
302 : 'Found',
35-
303 : 'See Other',
36-
304 : 'Not Modified',
37-
305 : 'Use Proxy',
38-
307 : 'Temporary Redirect',
39-
308 : 'Permanent Redirect', // RFC 7238
40-
400 : 'Bad Request',
41-
401 : 'Unauthorized',
42-
402 : 'Payment Required',
43-
403 : 'Forbidden',
44-
404 : 'Not Found',
45-
405 : 'Method Not Allowed',
46-
406 : 'Not Acceptable',
47-
407 : 'Proxy Authentication Required',
48-
408 : 'Request Timeout',
49-
409 : 'Conflict',
50-
410 : 'Gone',
51-
411 : 'Length Required',
52-
412 : 'Precondition Failed',
53-
413 : 'Payload Too Large',
54-
414 : 'URI Too Long',
55-
415 : 'Unsupported Media Type',
56-
416 : 'Range Not Satisfiable',
57-
417 : 'Expectation Failed',
58-
418 : 'I\'m a teapot', // RFC 2324
59-
421 : 'Misdirected Request',
60-
422 : 'Unprocessable Entity', // RFC 4918
61-
423 : 'Locked', // RFC 4918
62-
424 : 'Failed Dependency', // RFC 4918
63-
425 : 'Unordered Collection', // RFC 4918
64-
426 : 'Upgrade Required', // RFC 2817
65-
428 : 'Precondition Required', // RFC 6585
66-
429 : 'Too Many Requests', // RFC 6585
67-
431 : 'Request Header Fields Too Large', // RFC 6585
68-
500 : 'Internal Server Error',
69-
501 : 'Not Implemented',
70-
502 : 'Bad Gateway',
71-
503 : 'Service Unavailable',
72-
504 : 'Gateway Timeout',
73-
505 : 'HTTP Version Not Supported',
74-
506 : 'Variant Also Negotiates', // RFC 2295
75-
507 : 'Insufficient Storage', // RFC 4918
76-
508 : 'Loop Detected',
77-
509 : 'Bandwidth Limit Exceeded',
78-
510 : 'Not Extended', // RFC 2774
79-
511 : 'Network Authentication Required' // RFC 6585
19+
100: 'Continue',
20+
101: 'Switching Protocols',
21+
102: 'Processing', // RFC 2518, obsoleted by RFC 4918
22+
200: 'OK',
23+
201: 'Created',
24+
202: 'Accepted',
25+
203: 'Non-Authoritative Information',
26+
204: 'No Content',
27+
205: 'Reset Content',
28+
206: 'Partial Content',
29+
207: 'Multi-Status', // RFC 4918
30+
208: 'Already Reported',
31+
226: 'IM Used',
32+
300: 'Multiple Choices',
33+
301: 'Moved Permanently',
34+
302: 'Found',
35+
303: 'See Other',
36+
304: 'Not Modified',
37+
305: 'Use Proxy',
38+
307: 'Temporary Redirect',
39+
308: 'Permanent Redirect', // RFC 7238
40+
400: 'Bad Request',
41+
401: 'Unauthorized',
42+
402: 'Payment Required',
43+
403: 'Forbidden',
44+
404: 'Not Found',
45+
405: 'Method Not Allowed',
46+
406: 'Not Acceptable',
47+
407: 'Proxy Authentication Required',
48+
408: 'Request Timeout',
49+
409: 'Conflict',
50+
410: 'Gone',
51+
411: 'Length Required',
52+
412: 'Precondition Failed',
53+
413: 'Payload Too Large',
54+
414: 'URI Too Long',
55+
415: 'Unsupported Media Type',
56+
416: 'Range Not Satisfiable',
57+
417: 'Expectation Failed',
58+
418: 'I\'m a teapot', // RFC 2324
59+
421: 'Misdirected Request',
60+
422: 'Unprocessable Entity', // RFC 4918
61+
423: 'Locked', // RFC 4918
62+
424: 'Failed Dependency', // RFC 4918
63+
425: 'Unordered Collection', // RFC 4918
64+
426: 'Upgrade Required', // RFC 2817
65+
428: 'Precondition Required', // RFC 6585
66+
429: 'Too Many Requests', // RFC 6585
67+
431: 'Request Header Fields Too Large', // RFC 6585
68+
500: 'Internal Server Error',
69+
501: 'Not Implemented',
70+
502: 'Bad Gateway',
71+
503: 'Service Unavailable',
72+
504: 'Gateway Timeout',
73+
505: 'HTTP Version Not Supported',
74+
506: 'Variant Also Negotiates', // RFC 2295
75+
507: 'Insufficient Storage', // RFC 4918
76+
508: 'Loop Detected',
77+
509: 'Bandwidth Limit Exceeded',
78+
510: 'Not Extended', // RFC 2774
79+
511: 'Network Authentication Required' // RFC 6585
8080
};
8181

8282
const kOnExecute = HTTPParser.kOnExecute | 0;

lib/util.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,19 @@ exports.inspect = inspect;
147147

148148
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
149149
inspect.colors = {
150-
'bold' : [1, 22],
151-
'italic' : [3, 23],
152-
'underline' : [4, 24],
153-
'inverse' : [7, 27],
154-
'white' : [37, 39],
155-
'grey' : [90, 39],
156-
'black' : [30, 39],
157-
'blue' : [34, 39],
158-
'cyan' : [36, 39],
159-
'green' : [32, 39],
160-
'magenta' : [35, 39],
161-
'red' : [31, 39],
162-
'yellow' : [33, 39]
150+
'bold': [1, 22],
151+
'italic': [3, 23],
152+
'underline': [4, 24],
153+
'inverse': [7, 27],
154+
'white': [37, 39],
155+
'grey': [90, 39],
156+
'black': [30, 39],
157+
'blue': [34, 39],
158+
'cyan': [36, 39],
159+
'green': [32, 39],
160+
'magenta': [35, 39],
161+
'red': [31, 39],
162+
'yellow': [33, 39]
163163
};
164164

165165
// Don't use 'blue' not visible on cmd.exe

test/doctool/test-doctool-json.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var testData = [
1717
'source': 'foo',
1818
'modules': [ { 'textRaw': 'Sample Markdown',
1919
'name': 'sample_markdown',
20-
'modules': [ { 'textRaw':'Seussian Rhymes',
20+
'modules': [ { 'textRaw': 'Seussian Rhymes',
2121
'name': 'seussian_rhymes',
2222
'desc': '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' +
2323
'<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n',
@@ -32,7 +32,7 @@ var testData = [
3232
{
3333
'file': common.fixturesDir + '/order_of_end_tags_5873.md',
3434
'json': {
35-
'source':'foo',
35+
'source': 'foo',
3636
'modules': [ {
3737
'textRaw': 'Title',
3838
'name': 'title',
@@ -41,8 +41,8 @@ var testData = [
4141
'name': 'subsection',
4242
'classMethods': [ {
4343
'textRaw': 'Class Method: Buffer.from(array)',
44-
'type':'classMethod',
45-
'name':'from',
44+
'type': 'classMethod',
45+
'name': 'from',
4646
'signatures': [ {
4747
'params': [ {
4848
'textRaw': '`array` {Array} ',
@@ -51,7 +51,7 @@ var testData = [
5151
} ]
5252
},
5353
{
54-
'params' : [ {
54+
'params': [ {
5555
'name': 'array'
5656
} ]
5757
}

test/parallel/test-console.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ console.log(custom_inspect);
3737
// test console.dir()
3838
console.dir(custom_inspect);
3939
console.dir(custom_inspect, { showHidden: false });
40-
console.dir({ foo : { bar : { baz : true } } }, { depth: 0 });
41-
console.dir({ foo : { bar : { baz : true } } }, { depth: 1 });
40+
console.dir({ foo: { bar: { baz: true } } }, { depth: 0 });
41+
console.dir({ foo: { bar: { baz: true } } }, { depth: 1 });
4242

4343
// test console.trace()
4444
console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo');

test/parallel/test-crypto-binary-default.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem',
3030

3131
// PFX tests
3232
assert.doesNotThrow(function() {
33-
tls.createSecureContext({pfx:certPfx, passphrase:'sample'});
33+
tls.createSecureContext({pfx: certPfx, passphrase: 'sample'});
3434
});
3535

3636
assert.throws(function() {
37-
tls.createSecureContext({pfx:certPfx});
37+
tls.createSecureContext({pfx: certPfx});
3838
}, 'mac verify failure');
3939

4040
assert.throws(function() {
41-
tls.createSecureContext({pfx:certPfx, passphrase:'test'});
41+
tls.createSecureContext({pfx: certPfx, passphrase: 'test'});
4242
}, 'mac verify failure');
4343

4444
assert.throws(function() {
45-
tls.createSecureContext({pfx:'sample', passphrase:'test'});
45+
tls.createSecureContext({pfx: 'sample', passphrase: 'test'});
4646
}, 'not enough data');
4747

4848
// Test HMAC

test/parallel/test-crypto.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ assert.throws(function() {
3232

3333
// PFX tests
3434
assert.doesNotThrow(function() {
35-
tls.createSecureContext({pfx:certPfx, passphrase:'sample'});
35+
tls.createSecureContext({pfx: certPfx, passphrase: 'sample'});
3636
});
3737

3838
assert.throws(function() {
39-
tls.createSecureContext({pfx:certPfx});
39+
tls.createSecureContext({pfx: certPfx});
4040
}, 'mac verify failure');
4141

4242
assert.throws(function() {
43-
tls.createSecureContext({pfx:certPfx, passphrase:'test'});
43+
tls.createSecureContext({pfx: certPfx, passphrase: 'test'});
4444
}, 'mac verify failure');
4545

4646
assert.throws(function() {
47-
tls.createSecureContext({pfx:'sample', passphrase:'test'});
47+
tls.createSecureContext({pfx: 'sample', passphrase: 'test'});
4848
}, 'not enough data');
4949

5050

test/parallel/test-domain-http-server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var server = http.createServer(function(req, res) {
2020
serverCaught++;
2121
console.log('horray! got a server error', er);
2222
// try to send a 500. If that fails, oh well.
23-
res.writeHead(500, {'content-type':'text/plain'});
23+
res.writeHead(500, {'content-type': 'text/plain'});
2424
res.end(er.stack || er.message || 'Unknown error');
2525
});
2626

test/parallel/test-domain-top-level-error-handler-throw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if (process.argv[2] === 'child') {
2929
var fork = require('child_process').fork;
3030
var assert = require('assert');
3131

32-
var child = fork(process.argv[1], ['child'], {silent:true});
32+
var child = fork(process.argv[1], ['child'], {silent: true});
3333
var stderrOutput = '';
3434
if (child) {
3535
child.stderr.on('data', function onStderrData(data) {

test/parallel/test-fs-realpath.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,12 @@ function test_lying_cache_liar(cb) {
464464
// this should not require *any* stat calls, since everything
465465
// checked by realpath will be found in the cache.
466466
console.log('test_lying_cache_liar');
467-
var cache = { '/foo/bar/baz/bluff' : '/foo/bar/bluff',
468-
'/1/2/3/4/5/6/7' : '/1',
469-
'/a' : '/a',
470-
'/a/b' : '/a/b',
471-
'/a/b/c' : '/a/b',
472-
'/a/b/d' : '/a/b/d' };
467+
var cache = { '/foo/bar/baz/bluff': '/foo/bar/bluff',
468+
'/1/2/3/4/5/6/7': '/1',
469+
'/a': '/a',
470+
'/a/b': '/a/b',
471+
'/a/b/c': '/a/b',
472+
'/a/b/d': '/a/b/d' };
473473
if (common.isWindows) {
474474
var wc = {};
475475
Object.keys(cache).forEach(function(k) {

test/parallel/test-http-chunk-problem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (process.argv[2] === 'request') {
1111
const http = require('http');
1212
const options = {
1313
port: common.PORT,
14-
path : '/'
14+
path: '/'
1515
};
1616

1717
http.get(options, (res) => {

test/parallel/test-http-client-pipe-end.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ common.refreshTmpDir();
1818
server.listen(common.PIPE, function() {
1919
var req = http.request({
2020
socketPath: common.PIPE,
21-
headers: {'Content-Length':'1'},
21+
headers: {'Content-Length': '1'},
2222
method: 'POST',
2323
path: '/'
2424
});

test/parallel/test-http-client-reject-chunked-with-content-length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server.listen(common.PORT, () => {
1717
// The callback should not be called because the server is sending
1818
// both a Content-Length header and a Transfer-Encoding: chunked
1919
// header, which is a violation of the HTTP spec.
20-
const req = http.get({port:common.PORT}, (res) => {
20+
const req = http.get({port: common.PORT}, (res) => {
2121
assert.fail(null, null, 'callback should not be called');
2222
});
2323
req.on('error', common.mustCall((err) => {

test/parallel/test-http-client-reject-cr-no-lf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const server = net.createServer((socket) => {
1616
server.listen(common.PORT, () => {
1717
// The callback should not be called because the server is sending a
1818
// header field that ends only in \r with no following \n
19-
const req = http.get({port:common.PORT}, (res) => {
19+
const req = http.get({port: common.PORT}, (res) => {
2020
assert.fail(null, null, 'callback should not be called');
2121
});
2222
req.on('error', common.mustCall((err) => {

test/parallel/test-http-client-response-domain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function test() {
3434

3535
var req = http.get({
3636
socketPath: common.PIPE,
37-
headers: {'Content-Length':'1'},
37+
headers: {'Content-Length': '1'},
3838
method: 'POST',
3939
path: '/'
4040
});

test/parallel/test-http-client-timeout-with-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const options = {
1919
};
2020

2121
const server = http.createServer(function(req, res) {
22-
res.writeHead(200, {'Content-Length':'2'});
22+
res.writeHead(200, {'Content-Length': '2'});
2323
res.write('*');
2424
setTimeout(function() { res.end('*'); }, common.platformTimeout(100));
2525
});

test/parallel/test-http-expect-continue.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function handler(req, res) {
1313
assert.equal(sent_continue, true, 'Full response sent before 100 Continue');
1414
console.error('Server sending full response...');
1515
res.writeHead(200, {
16-
'Content-Type' : 'text/plain',
17-
'ABCD' : '1'
16+
'Content-Type': 'text/plain',
17+
'ABCD': '1'
1818
});
1919
res.end(test_res_body);
2020
}

test/parallel/test-http-remove-header-stays-removed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ process.on('exit', function() {
3030
server.listen(common.PORT, function() {
3131
http.get({ port: common.PORT }, function(res) {
3232
assert.equal(200, res.statusCode);
33-
assert.deepEqual(res.headers, { date : 'coffee o clock' });
33+
assert.deepStrictEqual(res.headers, { date: 'coffee o clock' });
3434

3535
res.setEncoding('ascii');
3636
res.on('data', function(chunk) {

0 commit comments

Comments
 (0)