Skip to content

Commit edb29b8

Browse files
Trottevanlucas
authored andcommitted
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 6806ebb commit edb29b8

36 files changed

+143
-142
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rules:
5858
comma-spacing: 2
5959
eol-last: 2
6060
indent: [2, 2, {SwitchCase: 1}]
61+
key-spacing: [2, {mode: "minimum"}]
6162
keyword-spacing: 2
6263
max-len: [2, 80, 2]
6364
new-parens: 2

lib/_http_server.js

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,68 @@ const httpSocketSetup = common.httpSocketSetup;
1515
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
1616

1717
const STATUS_CODES = exports.STATUS_CODES = {
18-
100 : 'Continue',
19-
101 : 'Switching Protocols',
20-
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
21-
200 : 'OK',
22-
201 : 'Created',
23-
202 : 'Accepted',
24-
203 : 'Non-Authoritative Information',
25-
204 : 'No Content',
26-
205 : 'Reset Content',
27-
206 : 'Partial Content',
28-
207 : 'Multi-Status', // RFC 4918
29-
208 : 'Already Reported',
30-
226 : 'IM Used',
31-
300 : 'Multiple Choices',
32-
301 : 'Moved Permanently',
33-
302 : 'Found',
34-
303 : 'See Other',
35-
304 : 'Not Modified',
36-
305 : 'Use Proxy',
37-
307 : 'Temporary Redirect',
38-
308 : 'Permanent Redirect', // RFC 7238
39-
400 : 'Bad Request',
40-
401 : 'Unauthorized',
41-
402 : 'Payment Required',
42-
403 : 'Forbidden',
43-
404 : 'Not Found',
44-
405 : 'Method Not Allowed',
45-
406 : 'Not Acceptable',
46-
407 : 'Proxy Authentication Required',
47-
408 : 'Request Timeout',
48-
409 : 'Conflict',
49-
410 : 'Gone',
50-
411 : 'Length Required',
51-
412 : 'Precondition Failed',
52-
413 : 'Payload Too Large',
53-
414 : 'URI Too Long',
54-
415 : 'Unsupported Media Type',
55-
416 : 'Range Not Satisfiable',
56-
417 : 'Expectation Failed',
57-
418 : 'I\'m a teapot', // RFC 2324
58-
421 : 'Misdirected Request',
59-
422 : 'Unprocessable Entity', // RFC 4918
60-
423 : 'Locked', // RFC 4918
61-
424 : 'Failed Dependency', // RFC 4918
62-
425 : 'Unordered Collection', // RFC 4918
63-
426 : 'Upgrade Required', // RFC 2817
64-
428 : 'Precondition Required', // RFC 6585
65-
429 : 'Too Many Requests', // RFC 6585
66-
431 : 'Request Header Fields Too Large', // RFC 6585
67-
451 : 'Unavailable For Legal Reasons',
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
18+
100: 'Continue',
19+
101: 'Switching Protocols',
20+
102: 'Processing', // RFC 2518, obsoleted by RFC 4918
21+
200: 'OK',
22+
201: 'Created',
23+
202: 'Accepted',
24+
203: 'Non-Authoritative Information',
25+
204: 'No Content',
26+
205: 'Reset Content',
27+
206: 'Partial Content',
28+
207: 'Multi-Status', // RFC 4918
29+
208: 'Already Reported',
30+
226: 'IM Used',
31+
300: 'Multiple Choices',
32+
301: 'Moved Permanently',
33+
302: 'Found',
34+
303: 'See Other',
35+
304: 'Not Modified',
36+
305: 'Use Proxy',
37+
307: 'Temporary Redirect',
38+
308: 'Permanent Redirect', // RFC 7238
39+
400: 'Bad Request',
40+
401: 'Unauthorized',
41+
402: 'Payment Required',
42+
403: 'Forbidden',
43+
404: 'Not Found',
44+
405: 'Method Not Allowed',
45+
406: 'Not Acceptable',
46+
407: 'Proxy Authentication Required',
47+
408: 'Request Timeout',
48+
409: 'Conflict',
49+
410: 'Gone',
50+
411: 'Length Required',
51+
412: 'Precondition Failed',
52+
413: 'Payload Too Large',
53+
414: 'URI Too Long',
54+
415: 'Unsupported Media Type',
55+
416: 'Range Not Satisfiable',
56+
417: 'Expectation Failed',
57+
418: 'I\'m a teapot', // RFC 2324
58+
421: 'Misdirected Request',
59+
422: 'Unprocessable Entity', // RFC 4918
60+
423: 'Locked', // RFC 4918
61+
424: 'Failed Dependency', // RFC 4918
62+
425: 'Unordered Collection', // RFC 4918
63+
426: 'Upgrade Required', // RFC 2817
64+
428: 'Precondition Required', // RFC 6585
65+
429: 'Too Many Requests', // RFC 6585
66+
431: 'Request Header Fields Too Large', // RFC 6585
67+
451: 'Unavailable For Legal Reasons',
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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,19 @@ exports.inspect = inspect;
151151

152152
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
153153
inspect.colors = {
154-
'bold' : [1, 22],
155-
'italic' : [3, 23],
156-
'underline' : [4, 24],
157-
'inverse' : [7, 27],
158-
'white' : [37, 39],
159-
'grey' : [90, 39],
160-
'black' : [30, 39],
161-
'blue' : [34, 39],
162-
'cyan' : [36, 39],
163-
'green' : [32, 39],
164-
'magenta' : [35, 39],
165-
'red' : [31, 39],
166-
'yellow' : [33, 39]
154+
'bold': [1, 22],
155+
'italic': [3, 23],
156+
'underline': [4, 24],
157+
'inverse': [7, 27],
158+
'white': [37, 39],
159+
'grey': [90, 39],
160+
'black': [30, 39],
161+
'blue': [34, 39],
162+
'cyan': [36, 39],
163+
'green': [32, 39],
164+
'magenta': [35, 39],
165+
'red': [31, 39],
166+
'yellow': [33, 39]
167167
};
168168

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

test/doctool/test-doctool-json.js

Lines changed: 5 additions & 5 deletions
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ console.log(custom_inspect);
4141
// test console.dir()
4242
console.dir(custom_inspect);
4343
console.dir(custom_inspect, { showHidden: false });
44-
console.dir({ foo : { bar : { baz : true } } }, { depth: 0 });
45-
console.dir({ foo : { bar : { baz : true } } }, { depth: 1 });
44+
console.dir({ foo: { bar: { baz: true } } }, { depth: 0 });
45+
console.dir({ foo: { bar: { baz: true } } }, { depth: 1 });
4646

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

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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-http-chunk-problem.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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.deepStrictEqual(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) {

test/parallel/test-http-response-multi-content-length.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ server.listen(common.PORT, common.mustCall(() => {
3333
// case, the error handler must be called because the client
3434
// is not allowed to accept multiple content-length headers.
3535
http.get(
36-
{port:common.PORT, headers:{'x-num': n}},
36+
{port: common.PORT, headers: {'x-num': n}},
3737
(res) => {
3838
assert(false, 'client allowed multiple content-length headers.');
3939
}

test/parallel/test-http-response-multiheaders.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ server.listen(common.PORT, common.mustCall(function() {
5656
// value should be reported for the header fields listed
5757
// in the norepeat array.
5858
http.get(
59-
{port:common.PORT, headers:{'x-num': n}},
59+
{port: common.PORT, headers: {'x-num': n}},
6060
common.mustCall(function(res) {
6161
if (++count === 2) server.close();
6262
for (const name of norepeat) {

test/parallel/test-http-response-splitting.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const server = http.createServer((req, res) => {
2929
break;
3030
case 1:
3131
assert.throws(common.mustCall(() => {
32-
res.writeHead(200, {'foo' : x});
32+
res.writeHead(200, {'foo': x});
3333
}));
3434
break;
3535
case 2:
3636
assert.throws(common.mustCall(() => {
37-
res.writeHead(200, {'foo' : y});
37+
res.writeHead(200, {'foo': y});
3838
}));
3939
break;
4040
default:

0 commit comments

Comments
 (0)