-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tools: lint for function argument alignment #6268
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,43 +81,54 @@ assert.equal(Buffer.from('ff').indexOf(Buffer.from('f'), 1, 'ucs2'), -1); | |
// test hex encoding | ||
assert.equal( | ||
Buffer.from(b.toString('hex'), 'hex') | ||
.indexOf('64', 0, 'hex'), 3); | ||
.indexOf('64', 0, 'hex'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't multiline method calls be indented with 2 spaces ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @targos asked:
(Deleted my previous inaccurate response.) This is a bug in ESLint. As @nzakas comments in that issue:
(That comment is from August.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @targos I've made an effort to enforce indentation in cases like this and submitted the PR upstream. eslint/eslint#5940 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And, in case you're curious, that rule finds 110 instances of mis-aligned chained properties in 18 files (3 in lib and 15 in test). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I don't think it's really going to fly in this project. There's going to definitely be people that will prefer this: var a = foo.bar()
.baz()
.bip()
.bap(); ...instead of: var a = foo.bar()
.baz()
.bip()
.bap(); It may be possible to write a rule smart enough to distinguish between that and other cases where it may make sense to indent-by-two rather than align, but I suspect there will be many edge cases. Indentation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solution might be to write a rule enforcing alignment (as in the first example in the previous comment). |
||
3); | ||
assert.equal( | ||
Buffer.from(b.toString('hex'), 'hex') | ||
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'), 3); | ||
.indexOf(Buffer.from('64', 'hex'), 0, 'hex'), | ||
3); | ||
|
||
// test base64 encoding | ||
assert.equal( | ||
Buffer.from(b.toString('base64'), 'base64') | ||
.indexOf('ZA==', 0, 'base64'), 3); | ||
.indexOf('ZA==', 0, 'base64'), | ||
3); | ||
assert.equal( | ||
Buffer.from(b.toString('base64'), 'base64') | ||
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'), 3); | ||
.indexOf(Buffer.from('ZA==', 'base64'), 0, 'base64'), | ||
3); | ||
|
||
// test ascii encoding | ||
assert.equal( | ||
Buffer.from(b.toString('ascii'), 'ascii') | ||
.indexOf('d', 0, 'ascii'), 3); | ||
.indexOf('d', 0, 'ascii'), | ||
3); | ||
assert.equal( | ||
Buffer.from(b.toString('ascii'), 'ascii') | ||
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), 3); | ||
.indexOf(Buffer.from('d', 'ascii'), 0, 'ascii'), | ||
3); | ||
|
||
// test binary encoding | ||
assert.equal( | ||
Buffer.from(b.toString('binary'), 'binary') | ||
.indexOf('d', 0, 'binary'), 3); | ||
.indexOf('d', 0, 'binary'), | ||
3); | ||
assert.equal( | ||
Buffer.from(b.toString('binary'), 'binary') | ||
.indexOf(Buffer.from('d', 'binary'), 0, 'binary'), 3); | ||
.indexOf(Buffer.from('d', 'binary'), 0, 'binary'), | ||
3); | ||
assert.equal( | ||
Buffer.from('aa\u00e8aa', 'binary') | ||
.indexOf('\u00e8', 'binary'), 2); | ||
.indexOf('\u00e8', 'binary'), | ||
2); | ||
assert.equal( | ||
Buffer.from('\u00e8', 'binary') | ||
.indexOf('\u00e8', 'binary'), 0); | ||
.indexOf('\u00e8', 'binary'), | ||
0); | ||
assert.equal( | ||
Buffer.from('\u00e8', 'binary') | ||
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'), 0); | ||
.indexOf(Buffer.from('\u00e8', 'binary'), 'binary'), | ||
0); | ||
|
||
|
||
// test optional offset with passed encoding | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was moving the arrow a line down necessary here for the rule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't the only option, but yes. Moving it meant that the next line didn't have to be indented so much that it exceeded the 80-character limit on line length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally not a fan of moving the first argument down if it can be avoided but can live with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell There are certainly other options, like assigning the function to a variable so you can just do
assert.throws(foo,...)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, the previous indentation is, in my opinion at least, unfriendly to the reader:
I think moving the arrow function down one line is worth getting code that is easier to understand at a glance: