Skip to content
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

feat: add no-manual-cleanup rule #72

Merged
merged 4 commits into from
Jan 30, 2020
Merged

feat: add no-manual-cleanup rule #72

merged 4 commits into from
Jan 30, 2020

Conversation

thomaslombart
Copy link
Collaborator

Closes #63

@thomaslombart thomaslombart self-assigned this Jan 29, 2020
README.md Outdated
@@ -142,6 +144,7 @@ To enable this configuration use the `extends` property in your
| [no-debug](docs/rules/no-debug.md) | Disallow the use of `debug` | ![angular-badge][] ![react-badge][] ![vue-badge][] | |
| [no-dom-import](docs/rules/no-dom-import.md) | Disallow importing from DOM Testing Library | ![angular-badge][] ![react-badge][] ![vue-badge][] | ![fixable-badge][] |
| [no-get-by-for-checking-element-not-present](docs/rules/no-get-by-for-checking-element-not-present) | Disallow the use of `getBy*` queries when checking elements are not present | | |
| [no-manual-cleanup](docs/rules/no-manual-cleanup.md) | Disallow the use of `cleanup` | ![react-badge][] ![vue-badge][] | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should enable this rule for any shareable config for reasons explained in the original issue.

},
messages: {
noManualCleanup:
"`cleanup` is performed automatically after each test by {{library}}, you don't need manual cleanups.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not right: the automatic cleanup is performed depending on your testing framework, not on your testing library package. This rule should just mention that manual cleanups are dissalowed as the testing framework taking care of it automatically.

Copy link
Collaborator Author

@thomaslombart thomaslombart Jan 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's true the automatic cleanup is performed depending on the testing framework, not all testing libraries package have a cleanup method, like Angular's testing library.

It does not make sense for me to make this rule fire even if the testing library package doesn't have a cleanup method.

I agree this rule should be removed from shareable configs as we don't know the test runner used though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough about short-circuiting when importing from a testing library package without cleanup, but still the error message is wrong as the one handling the automatic cleanup is the testing framework (e.g. jest), not testing library package (e.g. @testing-library/angular).

(Damn, "testing library" and "testing framework" are not making easier this discussion).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll fix it too, thanks for the feedback! 👍

By the way, there are some rules like no-debug where we don't support frameworks like Svelte Testing Library, we should probably open a new issue to include them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually one of the reasons I don't like to write code for checking specific testing library packages as if a new one comes up tomorrow we could have to update rules. I prefer to leave them agnostic from any package, specially those not enabled by default, so users can set them up under their responsibility. Of course, we should mention in proper rule doc which are those testing library packages supposed to be compatible with the rule for clarification.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that we have shareable configs for Angular, Vue, etc. But we are not adding any support for Svelte, Preact, etc. I think we should extend the rules that already work with specific packages (such as no-debug, or no-dom-import) to other potential testing libraries 🙂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah of course 🤦‍♂️

And probably we should open an issue about including more frameworks for sure!

@thomaslombart thomaslombart marked this pull request as ready for review January 29, 2020 17:37
@thomaslombart thomaslombart changed the title feat: start no-manual-cleanup rule feat: add no-manual-cleanup rule Jan 29, 2020
Copy link
Member

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome implementation for this rule and nice bunch of tests! Just asked for an additional doc reference.


## Further Reading

- [cleanup API in React Testing Library](https://testing-library.com/docs/react-testing-library/api#cleanup)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add skipping auto cleanup here:
Skipping Auto Cleanup

@Belco90 Belco90 merged commit 050cd4f into master Jan 30, 2020
@Belco90 Belco90 deleted the feat/no-manual-cleanup branch January 30, 2020 18:08
@Belco90
Copy link
Member

Belco90 commented Jan 30, 2020

🎉 This PR is included in version 2.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule: Disallow manual cleanups
2 participants