-
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
Conversation
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
9f9cb35
Compare
I'm generally +1 on this. LGTM but let's here from others. |
220e717
to
716614f
Compare
rebased, force pushed... |
Only failure in CI is a known problem test that @cjihrig has a pending pull request that fixes it. |
/bump @nodejs/collaborators Any enthusiastic endorsements or horrified objections to this? |
internalUtil.deprecate(function() { | ||
return require('tls').createSecureContext; | ||
}, 'crypto.createCredentials is deprecated. ' + | ||
'Use tls.createSecureContext instead.')); |
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.
the alignment seems wrong to me here
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.
@tergos do you mean wrong as in you disagree with it personally?
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 not sure. It looks wrong to me because both strings are not aligned to each other
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.
@targos Simplifying a bit, this is what the above code boils down to:
func1(arg1String,
arg2Func(function() {
return foo;
}, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 API
function defineLegacyGetter(legacyName, tlsName) {
function wrapped() {
return require('tls')[tlsName];
}
const msg = `crypto.${legacyName} is deprecated. Use tls.${tlsName} instead.`;
exports.__defineGetter__(legacyName, internalUtil.deprecate(wrapped, msg));
}
defineLegacyGetter('createCredentials', 'createSecureContext');
defineLegacyGetter('Credentials', 'SecureContext');
I'm also +1 on the change. I think it improves readability. |
+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. |
+1 and generally LGTM. |
}, /Got unwanted exception. user message/, | ||
'a.doesNotThrow ignores user message'); | ||
assert.throws( | ||
() => { |
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:
assert.throws(() => {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
}, /Got unwanted exception. user message/,
'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');
},
/Got unwanted exception. user message/,
'a.doesNotThrow ignores user message'
);
This is going through a lot of code though, I wonder if we can't do this more incrementally. |
@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. |
Do you mean multiple PRs? Or just split this PR into more commits? Or... |
716614f
to
277aa63
Compare
Rule proposed upstream: eslint/eslint#5946 |
277aa63
to
76a7bc4
Compare
In 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
74adfbc
Compare
7da4fd4
to
c7066fb
Compare
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