-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: replace custom assert.fail lint rule #12287
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 |
---|---|---|
|
@@ -110,6 +110,9 @@ rules: | |
}, { | ||
selector: "ThrowStatement > CallExpression[callee.name=/Error$/]", | ||
message: "Use new keyword when throwing an Error." | ||
}, { | ||
selector: "CallExpression[callee.object.name='assert'][callee.property.name='fail'][arguments.length=1]", | ||
message: "assert.fail() message should be third argument" | ||
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. This is really clear if you did 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. This rule came out of fixing a bunch of actual misuse in the code base. In every single case, it was |
||
}] | ||
no-tabs: 2 | ||
no-trailing-spaces: 2 | ||
|
@@ -142,7 +145,6 @@ rules: | |
|
||
# Custom rules in tools/eslint-rules | ||
align-multiline-assignment: 2 | ||
assert-fail-single-argument: 2 | ||
assert-throws-arguments: [2, { requireTwo: false }] | ||
no-unescaped-regexp-dot: 2 | ||
|
||
|
This file was deleted.
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.
Is there a valid use-case for a two argument
assert.fail
?Also if
assert.fail(null, null, "message")
is a valid use-case, we should probably document that.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.
This came out of specific errors in the code base. I'm unaware of anyone ever misusing
assert.fail()
with two arguments in core, and once you are checking for that, the lint message you have to supply gets a lot trickier.I don't like ramping up non-standard lint rules to be more strict to catch hypothetical problems because as you make the rules more and more strict, you end up generating false positives. But if we were to do that, I'd say let's do it in a different pull request. This one is replacing a custom rule with identical functionality using built-in ESLint capabilities. I'd rather not alter the functionality at the same time.
assert.fail()
is an unfortunate API IMO. As far as I can tell, if you supply a truthy value for the third argument, the first two arguments and the fourth argument are all ignored. (I'm not looking at the code so maybe there's an edge case in there where that's not true. I doubt it, though.) And the first two arguments don't make a lot of sense without the fourth argument.So....the useful signatures are
assert.fail(value, value, falsy, value)
orassert.fail(ignored, ignored, message)
.It's a mess IMO but this lint rule was designed to catch just the one exceedingly common misuse.
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, PR incoming soon to make the API less confusing. :-D
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.
Thanks for the detail, definitely not really related to this PR anyway.
Yeah, I find the idea that you have to have the third argument as
falsy
to actually use the fourth argument a bit hard to wrap my head around.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.
PR to make API less confusing: #12293