-
Notifications
You must be signed in to change notification settings - Fork 49
Add no-inline-assertions
rule
#262
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
Conversation
no-inline-assertion
rule (Fixes #152)no-inline-assertions
rule (Fixes #152)
I think the 2nd example fall under the arrow-body-style rule of eslint. IMO, this |
Agree. I was worrying about I suggest there be an exception: When there is an empty test body test("something", (t) => {}); we should not fail as it may be an IDE auto-completed scaffold. And developer may leave it as is when writing test to drive development. |
no-inline-assertions
rule (Fixes #152)no-inline-assertions
rule (Fixes #152)
4c3b778
to
8e14e81
Compare
I agree, no body is not an inline body. You forgot to add the rule to recommended config in index.js. |
That's not an inline arrow function. And no.
That's not an inline arrow function. And no, I think this would be a better fit for the
That's not an inline arrow function. And no. |
I disagree. That's better handled by normal ESLint style rules. The point here is to handle an inline arrow function, meaning |
no-inline-assertions
rule (Fixes #152)no-inline-assertions
rule
rules/no-inline-assertions.js
Outdated
function report({node, context}) { | ||
context.report({ | ||
node, | ||
message: 'Assertions should not be called from an inline function.' |
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 would be more correct:
message: 'Assertions should not be called from an inline function.' | |
message: 'The test implementation should not be just an assertion in an inline arrow function.' |
But would be nice to find a way to shorten the above slightly.
Per https://tc39.es/ecma262/#prod-ConciseBody, we should alias our definition of "inline arrow function" to "arrow function with concise body", and then we can clearly state that And the error message could be
If we agree that |
👍
👍 |
@sindresorhus Just pushed a new version and revised test cases. |
docs/rules/no-inline-assertions.md
Outdated
@@ -0,0 +1,19 @@ | |||
# Ensure no assertions are called from inline functions | |||
|
|||
Prevent assertions being called from an inline function, to make it clear that it does not return. |
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 is repeating the title too much. It should also use the wording "test implementation".
Can you make the rule auto-fixable? |
Co-Authored-By: Sindre Sorhus <[email protected]>
Good idea, it could be autofixable and I would look into it later. Anyway I have fixed the writing issues. |
4160751
to
69144d8
Compare
@sindresorhus I have pushed a simple fixer. The fixer wraps I tend to keep the fixer as minimal as possible, which means the other ESLint style rules, i.e. |
You need to mark it as being fixable in the readme and the rule docs. |
👍 Yup. That's the correct way to do it. |
Not resolved yet. |
This looks good now. Thanks for working on this rule :) |
Update (2019-06-13): I have pushed
no-inline-assertions
rule implementation, see the docs and test cases. This rule will failAny
MemberExpression
as the arrow function bodyAnd any
BlockStatement
within the same line(2019-06-12)
This is an early-stage design discussion, as I have the following question regards to this rule. I would also put up my thoughts and any community input is welcome.
Background: Recap of #152
The
no-inline-assertions
was originally proposed at #152, where Sindre listed two examplePass
Failure
Question on extra examples
While the example above is unambiguous, there is more question to be addressed after I ponder for a while.
Here are my thoughts on these cases,
On the first, I think it should be failed as an inline arrow function with block statement is still inline.
On the second one, I think there should be a separate rule, e.g.
no-return-assertions
to take care of this. Otherwise we will have also to fail the following casewhich is, of course, not an inline arrow function. So rule
no-inline-assertions
should not be triggered by case 2.On the third one, I think it should be failed as it is still an inline arrow function with assertion calls inside. But I am not an ava user so I can't triage the impact of the third case. Is it common? Or we can neglect this case?
The docs here reflects my thoughts and is suggested to any changes.
Fixes #152