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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Michaël Zasso 2016-12-10 11:08:56 +01:00 committed by James M Snell
parent 9fd79c9f5b
commit 966e5cfb81
12 changed files with 42 additions and 43 deletions

View File

@ -94,7 +94,7 @@ rules:
no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}] no-multiple-empty-lines: [2, {max: 2, maxEOF: 0, maxBOF: 0}]
no-tabs: 2 no-tabs: 2
no-trailing-spaces: 2 no-trailing-spaces: 2
operator-linebreak: [2, after, {overrides: {'?': ignore, ':': ignore}}] operator-linebreak: [2, after]
quotes: [2, single, avoid-escape] quotes: [2, single, avoid-escape]
semi: 2 semi: 2
semi-spacing: 2 semi-spacing: 2

View File

@ -7,9 +7,9 @@ exports.PORT = process.env.PORT || 12346;
function AutocannonBenchmarker() { function AutocannonBenchmarker() {
this.name = 'autocannon'; this.name = 'autocannon';
this.autocannon_exe = process.platform === 'win32' this.autocannon_exe = process.platform === 'win32' ?
? 'autocannon.cmd' 'autocannon.cmd' :
: 'autocannon'; 'autocannon';
const result = child_process.spawnSync(this.autocannon_exe, ['-h']); const result = child_process.spawnSync(this.autocannon_exe, ['-h']);
this.present = !(result.error && result.error.code === 'ENOENT'); this.present = !(result.error && result.error.code === 'ENOENT');
} }

View File

@ -876,9 +876,9 @@ function fromListPartial(n, list, hasStrings) {
ret = list.shift(); ret = list.shift();
} else { } else {
// result spans more than one buffer // result spans more than one buffer
ret = (hasStrings ret = (hasStrings ?
? copyFromBufferString(n, list) copyFromBufferString(n, list) :
: copyFromBuffer(n, list)); copyFromBuffer(n, list));
} }
return ret; return ret;
} }

View File

@ -426,13 +426,12 @@ function REPLServer(prompt,
self.lines.level = []; self.lines.level = [];
// Figure out which "complete" function to use. // Figure out which "complete" function to use.
self.completer = (typeof options.completer === 'function') self.completer = (typeof options.completer === 'function') ?
? options.completer options.completer : completer;
: completer;
function completer(text, cb) { function completer(text, cb) {
complete.call(self, text, self.editorMode complete.call(self, text, self.editorMode ?
? self.completeOnEditorMode(cb) : cb); self.completeOnEditorMode(cb) : cb);
} }
Interface.call(this, { Interface.call(this, {

View File

@ -381,9 +381,9 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
} }
var firstIdx = (questionIdx !== -1 && var firstIdx = (questionIdx !== -1 &&
(hashIdx === -1 || questionIdx < hashIdx) (hashIdx === -1 || questionIdx < hashIdx) ?
? questionIdx questionIdx :
: hashIdx); hashIdx);
if (firstIdx === -1) { if (firstIdx === -1) {
if (rest.length > 0) if (rest.length > 0)
this.pathname = rest; this.pathname = rest;

View File

@ -777,9 +777,9 @@ Buffer.from(Buffer.allocUnsafe(0), 0, 0);
assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}'); assert.strictEqual(string, '{"type":"Buffer","data":[116,101,115,116]}');
assert.deepStrictEqual(buffer, JSON.parse(string, (key, value) => { assert.deepStrictEqual(buffer, JSON.parse(string, (key, value) => {
return value && value.type === 'Buffer' return value && value.type === 'Buffer' ?
? Buffer.from(value.data) Buffer.from(value.data) :
: value; value;
})); }));
} }

View File

@ -40,9 +40,9 @@ function assertWrongList(value) {
}); });
} }
const random10 = common.hasCrypto const random10 = common.hasCrypto ?
? require('crypto').randomBytes(10) require('crypto').randomBytes(10) :
: Buffer.alloc(10, 1); Buffer.alloc(10, 1);
const empty = Buffer.alloc(0); const empty = Buffer.alloc(0);
assert.notDeepStrictEqual(random10, empty); assert.notDeepStrictEqual(random10, empty);

View File

@ -127,10 +127,10 @@ function makeReq(path, port, error, host, ca) {
} }
var req = https.get(options); var req = https.get(options);
expectResponseCount++; expectResponseCount++;
var server = port === server1.address().port ? server1 var server = port === server1.address().port ? server1 :
: port === server2.address().port ? server2 port === server2.address().port ? server2 :
: port === server3.address().port ? server3 port === server3.address().port ? server3 :
: null; null;
if (!server) throw new Error('invalid port: ' + port); if (!server) throw new Error('invalid port: ' + port);
server.expectCount++; server.expectCount++;

View File

@ -11,9 +11,9 @@ var asyncTest = (function() {
var currentTest = null; var currentTest = null;
function fail(error) { function fail(error) {
var stack = currentTest var stack = currentTest ?
? error.stack + '\nFrom previous event:\n' + currentTest.stack error.stack + '\nFrom previous event:\n' + currentTest.stack :
: error.stack; error.stack;
if (currentTest) if (currentTest)
process.stderr.write('\'' + currentTest.description + '\' failed\n\n'); process.stderr.write('\'' + currentTest.description + '\' failed\n\n');

View File

@ -182,19 +182,19 @@ const testBattery = {
), ),
toASCII: (test) => assert.strictEqual( toASCII: (test) => assert.strictEqual(
punycode.toASCII(test.decoded), punycode.toASCII(test.decoded),
regexNonASCII.test(test.decoded) regexNonASCII.test(test.decoded) ?
? `xn--${test.encoded}` `xn--${test.encoded}` :
: test.decoded test.decoded
), ),
toUnicode: (test) => assert.strictEqual( toUnicode: (test) => assert.strictEqual(
punycode.toUnicode( punycode.toUnicode(
regexNonASCII.test(test.decoded) regexNonASCII.test(test.decoded) ?
? `xn--${test.encoded}` `xn--${test.encoded}` :
: test.decoded test.decoded
), ),
regexNonASCII.test(test.decoded) regexNonASCII.test(test.decoded) ?
? test.decoded.toLowerCase() test.decoded.toLowerCase() :
: test.decoded test.decoded
) )
}; };

View File

@ -463,9 +463,9 @@ function isWarned(emitter) {
}); });
{ {
const expected = terminal const expected = terminal ?
? ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] ['\u001b[1G', '\u001b[0J', '$ ', '\u001b[3G'] :
: ['$ ']; ['$ '];
let counter = 0; let counter = 0;
const output = new Writable({ const output = new Writable({

View File

@ -108,9 +108,9 @@ module.exports = {
}, },
create(context) { create(context) {
const overrideSet = new Set(context.options.length const overrideSet = new Set(context.options.length ?
? context.options[0].override || [] context.options[0].override || [] :
: []); []);
/** /**
* Reports a node * Reports a node