Uh oh!
There was an error while loading. Please reload this page.
tools: lint for function argument alignment - #6268
Conversation
Trott
commented
Apr 19, 2016
Not sure if folks will like this one or not, but this is the other thing I always get nits about (hi, @bnoordhuis!). So rather than keep messing it up every time the rest of my life and spending valuable time force pushing to fix it, maybe the linter can tell me when I've messed it up and no one has to know. |
94c16d3 to
9f9cb35Comparejasnell
commented
Apr 19, 2016
I'm generally +1 on this. LGTM but let's here from others. |
220e717 to
716614fCompareTrott
commented
Apr 21, 2016
rebased, force pushed... |
Trott
commented
Apr 21, 2016
Only failure in CI is a known problem test that @cjihrig has a pending pull request that fixes it. |
Trott
commented
Apr 21, 2016
/bump @nodejs/collaborators Any enthusiastic endorsements or horrified objections to this? |
There was a problem hiding this comment.
the alignment seems wrong to me here
There was a problem hiding this comment.
@tergos do you mean wrong as in you disagree with it personally?
There was a problem hiding this comment.
I'm not sure. It looks wrong to me because both strings are not aligned to each other
There was a problem hiding this comment.
@targos Simplifying a bit, this is what the above code boils down to:
func1(arg1String,arg2Func(function(){returnfoo;},innerArgString));I wonder if the real obstacle to readability is the string concatenation (which makes it look like two string arguments when it's just one).
Also, the final closing parenthesis might make more sense on its own line.
Would removing the concatenation and moving the parenthesis help? Or is the issue something else?
There was a problem hiding this comment.
@targos@benjamingr I've rebased, rewritten these lines to hopefully conform more to expectations, and force pushed. Here's what they look like now:
// Legacy APIfunctiondefineLegacyGetter(legacyName,tlsName){functionwrapped(){returnrequire('tls')[tlsName];}constmsg=`crypto.${legacyName} is deprecated. Use tls.${tlsName} instead.`;exports.__defineGetter__(legacyName,internalUtil.deprecate(wrapped,msg));}defineLegacyGetter('createCredentials','createSecureContext');defineLegacyGetter('Credentials','SecureContext');targos
commented
Apr 21, 2016
I'm also +1 on the change. I think it improves readability. |
claudiorodriguez
commented
Apr 21, 2016
+1 on this change - I remember seeing different styles all around, sticking to a single one and enforcing it with linting will definitely help readability while switching files. |
benjamingr
commented
Apr 21, 2016
+1 and generally LGTM. |
There was a problem hiding this comment.
Was moving the arrow a line down necessary here for the rule?
There was a problem hiding this comment.
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.
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.
@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.
By the way, the previous indentation is, in my opinion at least, unfriendly to the reader:
assert.throws(()=>{assert.doesNotThrow(makeBlock(thrower,Error),'user message');},/Gotunwantedexception.usermessage/,'a.doesNotThrow ignores user message');I think moving the arrow function down one line is worth getting code that is easier to understand at a glance:
assert.throws(()=>{assert.doesNotThrow(makeBlock(thrower,Error),'user message');},/Gotunwantedexception.usermessage/,'a.doesNotThrow ignores user message');benjamingr
commented
Apr 21, 2016
This is going through a lot of code though, I wonder if we can't do this more incrementally. |
Trott
commented
Apr 21, 2016
@targos asked:
Not yet, but that was the plan. There's a loophole in the implementation (for a common case with timers) that will probably be deemed larger than it needs to be. I suspect that if the upstream project wants the rule, they will want that tightened up a bit, which would be nice. |
Trott
commented
Apr 21, 2016
Do you mean multiple PRs? Or just split this PR into more commits? Or... |
716614f to
277aa63CompareTrott
commented
Apr 23, 2016
Rule proposed upstream: eslint/eslint#5946 |
277aa63 to
76a7bc4CompareIn preparation for a lint rule that will enforce alignment of arguments in function calls that span multiple lines, align them in files where they are not currently aligned.
In function calls that span multiple lines, apply a custom lint rule to enforce argument alignment. With this rule, the following code will be flagged as an error by the linter because the arguments on the second line start in a different column than on the first line: myFunction(a, b, c, d); The following code will not be flagged as an error by the linter: myFunction(a, b, c, d);
76a7bc4 to
74adfbcCompare7da4fd4 to
c7066fbCompareTrott
commented
Apr 26, 2016
I'm going to close this in favor of #6390 which is a more lenient version of this rule and therefore has a smaller (and hopefully uncontroversial) changeset. |
Checklist
Affected core subsystem(s)
tools benchmark lib test
Description of change