Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
lib: use consistent indentation for ternaries
In anticipation of stricter linting for indentation issues, modify
ternary operators in lib that do not conform with the expected ESLint
settings.
  • Loading branch information
Trott committed Jul 7, 2017
commit 49336e1b88d0cd7df49dce7976aa4990359a567e
4 changes: 1 addition & 3 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,7 @@ 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;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

'use strict';

module.exports = ('NODE_UNIQUE_ID' in process.env) ?
require('internal/cluster/child') :
require('internal/cluster/master');
module.exports = require(`internal/cluster/${
Copy link
Copy Markdown
Contributor

@mscdex mscdex Jul 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly a fan of this multi-line inline substitution stuff. Can't we just set it to a variable and use the variable name instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Yes, I did it, but I did not feel good about it. Will fix.

'NODE_UNIQUE_ID' in process.env ? 'child' : 'master'
}`);
5 changes: 2 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,8 @@ function FSWatcher() {
if (status < 0) {
self._handle.close();
const error = !filename ?
errnoException(status, 'Error watching file for changes:') :
errnoException(status,
`Error watching file ${filename} for changes:`);
errnoException(status, 'Error watching file for changes:') :
errnoException(status, `Error watching file ${filename} for changes:`);
error.filename = filename;
self.emit('error', error);
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@
get: function() {
if (!console) {
console = originalConsole === undefined ?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe parans around the conditional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

NativeModule.require('console') :
installInspectorConsole(originalConsole);
NativeModule.require('console') :
installInspectorConsole(originalConsole);
}
return console;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ function _validateStdio(stdio, sync) {
} else if (getHandleWrapType(stdio) || getHandleWrapType(stdio.handle) ||
getHandleWrapType(stdio._handle)) {
var handle = getHandleWrapType(stdio) ?
stdio :
getHandleWrapType(stdio.handle) ? stdio.handle : stdio._handle;
stdio :
getHandleWrapType(stdio.handle) ? stdio.handle : stdio._handle;

acc.push({
type: 'wrap',
Expand Down
12 changes: 6 additions & 6 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
this.query = Object.create(null);
}

var firstIdx = (questionIdx !== -1 &&
(hashIdx === -1 || questionIdx < hashIdx) ?
questionIdx :
hashIdx);
var firstIdx =
questionIdx !== -1 && (hashIdx === -1 || questionIdx < hashIdx) ?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: assign the condition to a variable, and fit it in one line (useQuestionIdx)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done.

questionIdx :
hashIdx;
if (firstIdx === -1) {
if (rest.length > 0)
this.pathname = rest;
Expand Down Expand Up @@ -586,8 +586,8 @@ Url.prototype.format = function format() {
host = auth + this.host;
} else if (this.hostname) {
host = auth + (this.hostname.indexOf(':') === -1 ?
this.hostname :
'[' + this.hostname + ']');
this.hostname :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was once asked to explain this snippet in a job interview 😵
Maybe break after the open paran into an indented block:

host = auth + (
  this.hostname.indexOf(':') === -1 ?
  this.hostname :
  '[' + this.hostname + ']'
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is tricky to fix that way because the custom align-multiline-assignment rule seems to conflict with the newer indent stuff. I'd been thinking it might be good to remove that custom rule anyway, but I don't want to do it ahead of time.

There are some other ways to make this code clearer, but they will require benchmarks to confirm that they don't adversely affect performance. Stay tuned.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously my comment can be deffered, or replaced with a TODO

'[' + this.hostname + ']');
if (this.port) {
host += ':' + this.port;
}
Expand Down