From 05332942e2565fd557cae6b8bc813019494d4f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sat, 10 Dec 2016 11:08:56 +0100 Subject: [PATCH] tools: enforce linebreak after ternary operators This is to be consistent with the other operators and helps understanding the context when the code is grepped. PR-URL: https://github.com/nodejs/node/pull/10213 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Sakthipriyan Vairamani Reviewed-By: Teddy Katz Reviewed-By: James M Snell --- .eslintrc | 2 +- benchmark/_http-benchmarkers.js | 6 +++--- lib/_stream_readable.js | 6 +++--- lib/repl.js | 9 ++++----- lib/url.js | 6 +++--- test/parallel/test-buffer-alloc.js | 6 +++--- test/parallel/test-buffer-concat.js | 6 +++--- test/parallel/test-https-strict.js | 8 ++++---- .../test-promises-unhandled-rejections.js | 6 +++--- test/parallel/test-punycode.js | 18 +++++++++--------- test/parallel/test-readline-interface.js | 6 +++--- .../no-useless-regex-char-class-escape.js | 6 +++--- 12 files changed, 42 insertions(+), 43 deletions(-) diff --git a/.eslintrc b/.eslintrc index 182e783206..0aed06ca55 100644 --- a/.eslintrc +++ b/.eslintrc @@ -94,7 +94,7 @@ rules: no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}] no-tabs: 2 no-trailing-spaces: 2 - operator-linebreak: [2, after, {overrides: {'?': ignore, ':': ignore}}] + operator-linebreak: [2, after] quotes: [2, single, avoid-escape] semi: 2 semi-spacing: 2 diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index 5429bf386d..e096efc71b 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -7,9 +7,9 @@ exports.PORT = process.env.PORT || 12346; function AutocannonBenchmarker() { this.name = 'autocannon'; - this.autocannon_exe = process.platform === 'win32' - ? 'autocannon.cmd' - : 'autocannon'; + this.autocannon_exe = process.platform === 'win32' ? + 'autocannon.cmd' : + 'autocannon'; const result = child_process.spawnSync(this.autocannon_exe, ['-h']); this.present = !(result.error && result.error.code === 'ENOENT'); } diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 0844604d96..d6af8589f3 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -876,9 +876,9 @@ function fromListPartial(n, list, hasStrings) { ret = list.shift(); } else { // result spans more than one buffer - ret = (hasStrings - ? copyFromBufferString(n, list) - : copyFromBuffer(n, list)); + ret = (hasStrings ? + copyFromBufferString(n, list) : + copyFromBuffer(n, list)); } return ret; } diff --git a/lib/repl.js b/lib/repl.js index 2bb25e8ca3..d5060a37ab 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -433,13 +433,12 @@ function REPLServer(prompt, self.lines.level = []; // Figure out which "complete" function to use. - self.completer = (typeof options.completer === 'function') - ? options.completer - : completer; + self.completer = (typeof options.completer === 'function') ? + options.completer : completer; function completer(text, cb) { - complete.call(self, text, self.editorMode - ? self.completeOnEditorMode(cb) : cb); + complete.call(self, text, self.editorMode ? + self.completeOnEditorMode(cb) : cb); } Interface.call(this, { diff --git a/lib/url.js b/lib/url.js index 75f4967ad2..0cc364686c 100644 --- a/lib/url.js +++ b/lib/url.js @@ -381,9 +381,9 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { } var firstIdx = (questionIdx !== -1 && - (hashIdx === -1 || questionIdx < hashIdx) - ? questionIdx - : hashIdx); + (hashIdx === -1 || questionIdx < hashIdx) ? + questionIdx : + hashIdx); if (firstIdx === -1) { if (rest.length > 0) this.pathname = rest; diff --git a/test/parallel/test-buffer-alloc.js b/test/parallel/test-buffer-alloc.js index 4bc18dd1ab..2245c9843a 100644 --- a/test/parallel/test-buffer-alloc.js +++ b/test/parallel/test-buffer-alloc.js @@ -775,9 +775,9 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0); assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}'); assert.deepStrictEqual(buffer, JSON.parse(string, (key, value) => { - return value && value.type === 'Buffer' - ? Buffer.from(value.data) - : value; + return value && value.type === 'Buffer' ? + Buffer.from(value.data) : + value; })); } diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 800f1055aa..b29e00682c 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -39,9 +39,9 @@ function assertWrongList(value) { }); } -const random10 = common.hasCrypto - ? require('crypto').randomBytes(10) - : Buffer.alloc(10, 1); +const random10 = common.hasCrypto ? + require('crypto').randomBytes(10) : + Buffer.alloc(10, 1); const empty = Buffer.alloc(0); assert.notDeepStrictEqual(random10, empty); diff --git a/test/parallel/test-https-strict.js b/test/parallel/test-https-strict.js index e62f8ad015..871d9ef94e 100644 --- a/test/parallel/test-https-strict.js +++ b/test/parallel/test-https-strict.js @@ -127,10 +127,10 @@ function makeReq(path, port, error, host, ca) { } var req = https.get(options); expectResponseCount++; - var server = port === server1.address().port ? server1 - : port === server2.address().port ? server2 - : port === server3.address().port ? server3 - : null; + var server = port === server1.address().port ? server1 : + port === server2.address().port ? server2 : + port === server3.address().port ? server3 : + null; if (!server) throw new Error('invalid port: ' + port); server.expectCount++; diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 3c7a403805..b827dd9e36 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -11,9 +11,9 @@ var asyncTest = (function() { var currentTest = null; function fail(error) { - var stack = currentTest - ? error.stack + '\nFrom previous event:\n' + currentTest.stack - : error.stack; + var stack = currentTest ? + error.stack + '\nFrom previous event:\n' + currentTest.stack : + error.stack; if (currentTest) process.stderr.write('\'' + currentTest.description + '\' failed\n\n'); diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index e869e6a33b..7d969c66ee 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -182,19 +182,19 @@ const testBattery = { ), toASCII: (test) => assert.strictEqual( punycode.toASCII(test.decoded), - regexNonASCII.test(test.decoded) - ? `xn--${test.encoded}` - : test.decoded + regexNonASCII.test(test.decoded) ? + `xn--${test.encoded}` : + test.decoded ), toUnicode: (test) => assert.strictEqual( punycode.toUnicode( - regexNonASCII.test(test.decoded) - ? `xn--${test.encoded}` - : test.decoded + regexNonASCII.test(test.decoded) ? + `xn--${test.encoded}` : + test.decoded ), - regexNonASCII.test(test.decoded) - ? test.decoded.toLowerCase() - : test.decoded + regexNonASCII.test(test.decoded) ? + test.decoded.toLowerCase() : + test.decoded ) }; diff --git a/test/parallel/test-readline-interface.js b/test/parallel/test-readline-interface.js index 08dbdd4882..59b75cd0a8 100644 --- a/test/parallel/test-readline-interface.js +++ b/test/parallel/test-readline-interface.js @@ -463,9 +463,9 @@ function isWarned(emitter) { }); { - const expected = terminal - ? ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] - : ['$ ']; + const expected = terminal ? + ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] : + ['$ ']; let counter = 0; const output = new Writable({ diff --git a/tools/eslint-rules/no-useless-regex-char-class-escape.js b/tools/eslint-rules/no-useless-regex-char-class-escape.js index 934a3fa193..e18077098d 100644 --- a/tools/eslint-rules/no-useless-regex-char-class-escape.js +++ b/tools/eslint-rules/no-useless-regex-char-class-escape.js @@ -108,9 +108,9 @@ module.exports = { }, create(context) { - const overrideSet = new Set(context.options.length - ? context.options[0].override || [] - : []); + const overrideSet = new Set(context.options.length ? + context.options[0].override || [] : + []); /** * Reports a node