Skip to content

Commit

Permalink
tools: lint for object literal spacing
Browse files Browse the repository at this point in the history
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 <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
Trott authored and Myles Borins committed Jul 14, 2016
1 parent 96b5aa8 commit 8b88c38
Show file tree
Hide file tree
Showing 36 changed files with 151 additions and 150 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ rules:
comma-spacing: 2
eol-last: 2
indent: [2, 2, {SwitchCase: 1}]
key-spacing: [2, {mode: "minimum"}]
keyword-spacing: 2
max-len: [2, 80, 2]
new-parens: 2
Expand Down
10 changes: 5 additions & 5 deletions benchmark/path/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ function main(conf) {
ext: '.html',
name: 'index'
} : {
root : '/',
dir : '/home/user/dir',
base : 'index.html',
ext : '.html',
name : 'index'
root: '/',
dir: '/home/user/dir',
base: 'index.html',
ext: '.html',
name: 'index'
};

// Force optimization before starting the benchmark
Expand Down
122 changes: 61 additions & 61 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,67 @@ const httpSocketSetup = common.httpSocketSetup;
const OutgoingMessage = require('_http_outgoing').OutgoingMessage;

const STATUS_CODES = exports.STATUS_CODES = {
100 : 'Continue',
101 : 'Switching Protocols',
102 : 'Processing', // RFC 2518, obsoleted by RFC 4918
200 : 'OK',
201 : 'Created',
202 : 'Accepted',
203 : 'Non-Authoritative Information',
204 : 'No Content',
205 : 'Reset Content',
206 : 'Partial Content',
207 : 'Multi-Status', // RFC 4918
208 : 'Already Reported',
226 : 'IM Used',
300 : 'Multiple Choices',
301 : 'Moved Permanently',
302 : 'Found',
303 : 'See Other',
304 : 'Not Modified',
305 : 'Use Proxy',
307 : 'Temporary Redirect',
308 : 'Permanent Redirect', // RFC 7238
400 : 'Bad Request',
401 : 'Unauthorized',
402 : 'Payment Required',
403 : 'Forbidden',
404 : 'Not Found',
405 : 'Method Not Allowed',
406 : 'Not Acceptable',
407 : 'Proxy Authentication Required',
408 : 'Request Timeout',
409 : 'Conflict',
410 : 'Gone',
411 : 'Length Required',
412 : 'Precondition Failed',
413 : 'Payload Too Large',
414 : 'URI Too Long',
415 : 'Unsupported Media Type',
416 : 'Range Not Satisfiable',
417 : 'Expectation Failed',
418 : 'I\'m a teapot', // RFC 2324
421 : 'Misdirected Request',
422 : 'Unprocessable Entity', // RFC 4918
423 : 'Locked', // RFC 4918
424 : 'Failed Dependency', // RFC 4918
425 : 'Unordered Collection', // RFC 4918
426 : 'Upgrade Required', // RFC 2817
428 : 'Precondition Required', // RFC 6585
429 : 'Too Many Requests', // RFC 6585
431 : 'Request Header Fields Too Large', // RFC 6585
500 : 'Internal Server Error',
501 : 'Not Implemented',
502 : 'Bad Gateway',
503 : 'Service Unavailable',
504 : 'Gateway Timeout',
505 : 'HTTP Version Not Supported',
506 : 'Variant Also Negotiates', // RFC 2295
507 : 'Insufficient Storage', // RFC 4918
508 : 'Loop Detected',
509 : 'Bandwidth Limit Exceeded',
510 : 'Not Extended', // RFC 2774
511 : 'Network Authentication Required' // RFC 6585
100: 'Continue',
101: 'Switching Protocols',
102: 'Processing', // RFC 2518, obsoleted by RFC 4918
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-Authoritative Information',
204: 'No Content',
205: 'Reset Content',
206: 'Partial Content',
207: 'Multi-Status', // RFC 4918
208: 'Already Reported',
226: 'IM Used',
300: 'Multiple Choices',
301: 'Moved Permanently',
302: 'Found',
303: 'See Other',
304: 'Not Modified',
305: 'Use Proxy',
307: 'Temporary Redirect',
308: 'Permanent Redirect', // RFC 7238
400: 'Bad Request',
401: 'Unauthorized',
402: 'Payment Required',
403: 'Forbidden',
404: 'Not Found',
405: 'Method Not Allowed',
406: 'Not Acceptable',
407: 'Proxy Authentication Required',
408: 'Request Timeout',
409: 'Conflict',
410: 'Gone',
411: 'Length Required',
412: 'Precondition Failed',
413: 'Payload Too Large',
414: 'URI Too Long',
415: 'Unsupported Media Type',
416: 'Range Not Satisfiable',
417: 'Expectation Failed',
418: 'I\'m a teapot', // RFC 2324
421: 'Misdirected Request',
422: 'Unprocessable Entity', // RFC 4918
423: 'Locked', // RFC 4918
424: 'Failed Dependency', // RFC 4918
425: 'Unordered Collection', // RFC 4918
426: 'Upgrade Required', // RFC 2817
428: 'Precondition Required', // RFC 6585
429: 'Too Many Requests', // RFC 6585
431: 'Request Header Fields Too Large', // RFC 6585
500: 'Internal Server Error',
501: 'Not Implemented',
502: 'Bad Gateway',
503: 'Service Unavailable',
504: 'Gateway Timeout',
505: 'HTTP Version Not Supported',
506: 'Variant Also Negotiates', // RFC 2295
507: 'Insufficient Storage', // RFC 4918
508: 'Loop Detected',
509: 'Bandwidth Limit Exceeded',
510: 'Not Extended', // RFC 2774
511: 'Network Authentication Required' // RFC 6585
};

const kOnExecute = HTTPParser.kOnExecute | 0;
Expand Down
26 changes: 13 additions & 13 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ exports.inspect = inspect;

// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
inspect.colors = {
'bold' : [1, 22],
'italic' : [3, 23],
'underline' : [4, 24],
'inverse' : [7, 27],
'white' : [37, 39],
'grey' : [90, 39],
'black' : [30, 39],
'blue' : [34, 39],
'cyan' : [36, 39],
'green' : [32, 39],
'magenta' : [35, 39],
'red' : [31, 39],
'yellow' : [33, 39]
'bold': [1, 22],
'italic': [3, 23],
'underline': [4, 24],
'inverse': [7, 27],
'white': [37, 39],
'grey': [90, 39],
'black': [30, 39],
'blue': [34, 39],
'cyan': [36, 39],
'green': [32, 39],
'magenta': [35, 39],
'red': [31, 39],
'yellow': [33, 39]
};

// Don't use 'blue' not visible on cmd.exe
Expand Down
10 changes: 5 additions & 5 deletions test/doctool/test-doctool-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var testData = [
'source': 'foo',
'modules': [ { 'textRaw': 'Sample Markdown',
'name': 'sample_markdown',
'modules': [ { 'textRaw':'Seussian Rhymes',
'modules': [ { 'textRaw': 'Seussian Rhymes',
'name': 'seussian_rhymes',
'desc': '<ol>\n<li>fish</li>\n<li><p>fish</p>\n</li>\n<li>' +
'<p>Red fish</p>\n</li>\n<li>Blue fish</li>\n</ol>\n',
Expand All @@ -32,7 +32,7 @@ var testData = [
{
'file': common.fixturesDir + '/order_of_end_tags_5873.md',
'json': {
'source':'foo',
'source': 'foo',
'modules': [ {
'textRaw': 'Title',
'name': 'title',
Expand All @@ -41,8 +41,8 @@ var testData = [
'name': 'subsection',
'classMethods': [ {
'textRaw': 'Class Method: Buffer.from(array)',
'type':'classMethod',
'name':'from',
'type': 'classMethod',
'name': 'from',
'signatures': [ {
'params': [ {
'textRaw': '`array` {Array} ',
Expand All @@ -51,7 +51,7 @@ var testData = [
} ]
},
{
'params' : [ {
'params': [ {
'name': 'array'
} ]
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ console.log(custom_inspect);
// test console.dir()
console.dir(custom_inspect);
console.dir(custom_inspect, { showHidden: false });
console.dir({ foo : { bar : { baz : true } } }, { depth: 0 });
console.dir({ foo : { bar : { baz : true } } }, { depth: 1 });
console.dir({ foo: { bar: { baz: true } } }, { depth: 0 });
console.dir({ foo: { bar: { baz: true } } }, { depth: 1 });

// test console.trace()
console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo');
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-crypto-binary-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ var rsaKeyPem = fs.readFileSync(common.fixturesDir + '/test_rsa_privkey.pem',

// PFX tests
assert.doesNotThrow(function() {
tls.createSecureContext({pfx:certPfx, passphrase:'sample'});
tls.createSecureContext({pfx: certPfx, passphrase: 'sample'});
});

assert.throws(function() {
tls.createSecureContext({pfx:certPfx});
tls.createSecureContext({pfx: certPfx});
}, 'mac verify failure');

assert.throws(function() {
tls.createSecureContext({pfx:certPfx, passphrase:'test'});
tls.createSecureContext({pfx: certPfx, passphrase: 'test'});
}, 'mac verify failure');

assert.throws(function() {
tls.createSecureContext({pfx:'sample', passphrase:'test'});
tls.createSecureContext({pfx: 'sample', passphrase: 'test'});
}, 'not enough data');

// Test HMAC
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ assert.throws(function() {

// PFX tests
assert.doesNotThrow(function() {
tls.createSecureContext({pfx:certPfx, passphrase:'sample'});
tls.createSecureContext({pfx: certPfx, passphrase: 'sample'});
});

assert.throws(function() {
tls.createSecureContext({pfx:certPfx});
tls.createSecureContext({pfx: certPfx});
}, 'mac verify failure');

assert.throws(function() {
tls.createSecureContext({pfx:certPfx, passphrase:'test'});
tls.createSecureContext({pfx: certPfx, passphrase: 'test'});
}, 'mac verify failure');

assert.throws(function() {
tls.createSecureContext({pfx:'sample', passphrase:'test'});
tls.createSecureContext({pfx: 'sample', passphrase: 'test'});
}, 'not enough data');


Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-domain-http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var server = http.createServer(function(req, res) {
serverCaught++;
console.log('horray! got a server error', er);
// try to send a 500. If that fails, oh well.
res.writeHead(500, {'content-type':'text/plain'});
res.writeHead(500, {'content-type': 'text/plain'});
res.end(er.stack || er.message || 'Unknown error');
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-domain-top-level-error-handler-throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (process.argv[2] === 'child') {
var fork = require('child_process').fork;
var assert = require('assert');

var child = fork(process.argv[1], ['child'], {silent:true});
var child = fork(process.argv[1], ['child'], {silent: true});
var stderrOutput = '';
if (child) {
child.stderr.on('data', function onStderrData(data) {
Expand Down
12 changes: 6 additions & 6 deletions test/parallel/test-fs-realpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,12 @@ function test_lying_cache_liar(cb) {
// this should not require *any* stat calls, since everything
// checked by realpath will be found in the cache.
console.log('test_lying_cache_liar');
var cache = { '/foo/bar/baz/bluff' : '/foo/bar/bluff',
'/1/2/3/4/5/6/7' : '/1',
'/a' : '/a',
'/a/b' : '/a/b',
'/a/b/c' : '/a/b',
'/a/b/d' : '/a/b/d' };
var cache = { '/foo/bar/baz/bluff': '/foo/bar/bluff',
'/1/2/3/4/5/6/7': '/1',
'/a': '/a',
'/a/b': '/a/b',
'/a/b/c': '/a/b',
'/a/b/d': '/a/b/d' };
if (common.isWindows) {
var wc = {};
Object.keys(cache).forEach(function(k) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-chunk-problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (process.argv[2] === 'request') {
const http = require('http');
const options = {
port: common.PORT,
path : '/'
path: '/'
};

http.get(options, (res) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-pipe-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ common.refreshTmpDir();
server.listen(common.PIPE, function() {
var req = http.request({
socketPath: common.PIPE,
headers: {'Content-Length':'1'},
headers: {'Content-Length': '1'},
method: 'POST',
path: '/'
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ server.listen(common.PORT, () => {
// The callback should not be called because the server is sending
// both a Content-Length header and a Transfer-Encoding: chunked
// header, which is a violation of the HTTP spec.
const req = http.get({port:common.PORT}, (res) => {
const req = http.get({port: common.PORT}, (res) => {
assert.fail(null, null, 'callback should not be called');
});
req.on('error', common.mustCall((err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-reject-cr-no-lf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const server = net.createServer((socket) => {
server.listen(common.PORT, () => {
// The callback should not be called because the server is sending a
// header field that ends only in \r with no following \n
const req = http.get({port:common.PORT}, (res) => {
const req = http.get({port: common.PORT}, (res) => {
assert.fail(null, null, 'callback should not be called');
});
req.on('error', common.mustCall((err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-response-domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function test() {

var req = http.get({
socketPath: common.PIPE,
headers: {'Content-Length':'1'},
headers: {'Content-Length': '1'},
method: 'POST',
path: '/'
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-timeout-with-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const options = {
};

const server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Length':'2'});
res.writeHead(200, {'Content-Length': '2'});
res.write('*');
setTimeout(function() { res.end('*'); }, common.platformTimeout(100));
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-expect-continue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function handler(req, res) {
assert.equal(sent_continue, true, 'Full response sent before 100 Continue');
console.error('Server sending full response...');
res.writeHead(200, {
'Content-Type' : 'text/plain',
'ABCD' : '1'
'Content-Type': 'text/plain',
'ABCD': '1'
});
res.end(test_res_body);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-remove-header-stays-removed.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ process.on('exit', function() {
server.listen(common.PORT, function() {
http.get({ port: common.PORT }, function(res) {
assert.equal(200, res.statusCode);
assert.deepEqual(res.headers, { date : 'coffee o clock' });
assert.deepStrictEqual(res.headers, { date: 'coffee o clock' });

res.setEncoding('ascii');
res.on('data', function(chunk) {
Expand Down
Loading

0 comments on commit 8b88c38

Please sign in to comment.