eslint-plugin-testing-library icon indicating copy to clipboard operation
eslint-plugin-testing-library copied to clipboard

ESLint plugin Testing Library v4

Open Belco90 opened this issue 6 years ago • 35 comments

I'd like to keep everything planned for v4 update here, so it's easier for everyone involved to organize pending work. This was started in #165.

Changes planned for v4:

  • [x] new rule: no-container - #171, #177
  • [x] new rule: render-result-naming-convention - #170, #200
  • [x] new rule: prefer-user-event - #162, #192
  • [x] new rule: no-promise-in-fire-event - #166, #180
  • [x] new rule: no-wait-for-side-effects - #134, #196
  • [x] new rule: no-node-access - #190
  • [x] new rule: no-wait-for-multiple-assertions - #133, #189
  • [x] BREAKING CHANGE: enable no-wait-for-empty-callback in config presets - #168
  • [x] BREAKING CHANGE: enable prefer-screen-queries in config presets - #169
  • [x] BREAKING CHANGE: rename recommended config to dom - #182, #184
  • [x] BREAKING CHANGE: move rules settings to ESLint shared config - #198
  • [x] ci: migrate CI to GitHub Actions

Extra:

  • [x] Cleanup after all rules are migrated: #303
  • [x] Update README with shared settings: #317
  • [X] Update README to explain "aggressive mode", its motivation and how to restrict its scope: #312
  • [x] Update rules docs to delete references to removed options
  • [x] Update CONTRIBUTING to mention new rules creation + detection helper + realistic test cases: #321
  • [X] Write migrating to v4 guide: #312
  • [x] Prepare release notes

Future Improvements:

  • Allow multiple utils modules on Shared Settings: #315
  • New rule: no-unnecessary-act - #259

Thanks to @gndelia @timdeschryver @nickmccurdy @thebinaryfelix @renatoagds for your work on this one!

Belco90 avatar Jun 22 '20 10:06 Belco90

Do you think we need to wait for those 4 new rules for releasing v4? I think render-result-naming-convention and prefer-user-event are necessary, but we could release prefer-user-event and no-multiple-assertions-wait-for in a later step?

Belco90 avatar Jun 22 '20 10:06 Belco90

We could also assign issues from the milestone.

nickserv avatar Jun 22 '20 10:06 nickserv

Yeah I just felt I needed a place to see everything together but also be able to discuss what's needed and coordinate this better.

Belco90 avatar Jun 22 '20 10:06 Belco90

Do you think we need to wait for those 4 new rules for releasing v4? I think render-result-naming-convention and prefer-user-event are necessary, but we could release prefer-user-event and no-multiple-assertions-wait-for in a later step?

I guess that depends on if we want to make them recommended, and I think they probably should be. As long as it doesn't take too longer to work on them, waiting to release them would reduce the number of breaking releases and potentially make upgrading easier. Alternatively we could make the migration more gradual and maybe release rules in 4.x but only recommend them in 5.x.

nickserv avatar Jun 22 '20 10:06 nickserv

Mmm I wasn't thinking about releasing new rules included in config presets as major. I see including rules in preset as a major only when they existed before, but not if they are gonna be completely new rules. Again, I don't know how we should address this.

Belco90 avatar Jun 22 '20 10:06 Belco90

Both adding an existing rule and adding a new rule to a config change the config to make more use cases fail, which I see as a breaking change either way. So I think we'd either need to wait for these to be in v4 or have them in a future major release if we don't enable them in v4, but I was asking more about how we'd release the rules themselves and change the configs.

nickserv avatar Jun 22 '20 11:06 nickserv

Maybe we should make suggestions about new features warn rather than error to make it easier for users to migrate.

Relevant discussions:

  • https://github.com/testing-library/eslint-plugin-testing-library/pull/192#issuecomment-652529480
  • https://github.com/facebook/create-react-app/pull/8963#issuecomment-652398748

nickserv avatar Jul 01 '20 16:07 nickserv

Maybe we should make suggestions about new features warn rather than error to make it easier for users to migrate.

Relevant discussions:

* [#192 (comment)](https://github.com/testing-library/eslint-plugin-testing-library/pull/192#issuecomment-652529480)

* [facebook/create-react-app#8963 (comment)](https://github.com/facebook/create-react-app/pull/8963#issuecomment-652398748)

I guess the candidates for that would be:

  • prefer-user-event
  • no-side-effects-wait-for (when implemented)
  • no-multiple-assertions-wait-for

Any other rule I'm missing?

Belco90 avatar Jul 02 '20 07:07 Belco90

@Belco90 Maybe no-container too? Looks like something good to have as default in CRA.

renatoagds avatar Jul 02 '20 14:07 renatoagds

@Belco90 Maybe no-container too? Looks like something good to have as default in CRA.

We don't really need to worry about if a rule should be enabled for CRA or not, as CRA will enable them manually. In our shareable configs is more about "should we enable a rule as error for a brand new Testing Library feature"? Probably better a warning for them as @nickmccurdy pointed so we can help users migrating their Testing Library framework codebase for future updates without harming them.

So regarding no-container, I'd set that one as error in our shareable configs.

Belco90 avatar Jul 03 '20 16:07 Belco90

Something else I would like to discuss: I'm close to finish render-result-naming-convention rule and I had to use again the rule option for custom render functions. I'm gonna leave it like that, but it's the 3rd or 4th time we need to do this, so I think we should use v4 to introduce the breaking change to move that to ESLint global config.

I have some ideas about how to implement it, I don't think it would be complicated. As we have some utils functions already checking if a node is a render method, we can check directly on that one if there are some custom functions set in the plugin. Then we just need to remove the options from each rule, update the set up in the tests and all of them should pass.

Thoughts?

Belco90 avatar Jul 03 '20 16:07 Belco90

I think it'd be really useful to have that generic configuration/functionality for the v4.

Either way, I think it's not a breaking change, but rather an opt-in (Extend the functionality to allow custom functions to be the imported ones), so in case we finish everything else but this, the worst case we can go out with v4 without it, if we can't delay it.

but I would love to have it as part of this release, and I think it will be very helpful for all those who use a custom render function (that I believe it's a lot of devs)

gndelia avatar Jul 03 '20 16:07 gndelia

I think it would be useful too. Would also avoid repetitions by the user in the rules configs.

Either way, I think it's not a breaking change, but rather an opt-in

I think if we remove the config option from each rule to read it just from a global config, the user would have to rewrite their configs. That's what makes it a breaking change, right?

thebinaryfelix avatar Jul 03 '20 17:07 thebinaryfelix

I think if we remove the config option from each rule to read it just from a global config, the user would have to rewrite their configs. That's what makes it a breaking change, right?

Exactly, this is why it would be a breaking change

Belco90 avatar Jul 03 '20 17:07 Belco90

I See. The rules I've worked with did not have that config, so I wasn't sure it was implemented and released in any. In that case, yeah, we should consider it as part of the v4, or we will have to release the v5 really soon

gndelia avatar Jul 03 '20 17:07 gndelia

Guys, looking at the v4 milestone, I would suggest something more. It's not required for v4 release, but probably we could start to ship it in v4 branch.

We could start to map fixable actions for the current rules that we support. We have a few ones that implements, but I think that's a path to improve.

What do you guys think about?

renatoagds avatar Jul 08 '20 03:07 renatoagds

Any specific suggestions?

nickserv avatar Jul 08 '20 03:07 nickserv

Guys, looking at the v4 milestone, I would suggest something more. It's not required for v4 release, but probably we could start to ship it in v4 branch.

We could start to map fixable actions for the current rules that we support. We have a few ones that implements, but I think that's a path to improve.

What do you guys think about?

Sounds good. I think we can do this even after v4 release. It seems it can be related to that mechanism @nickmccurdy wanted to add to autogenerate the shareable configs columns?

Belco90 avatar Jul 11 '20 09:07 Belco90

I think @renatoagds was referring to implementing fix support in more rules. According to the readme, three rules have it so far. We could map the fix flag in each rule to the readme though.

nickserv avatar Jul 11 '20 09:07 nickserv

Ah sorry, I understood something else. Add fix code to current rules can be done at any time actually.

I'm sorry I'm not really active lately. I'm swamped at work and dealing with some other personal projects. I hope I have some spare time next week to push v4 of the plugin!

Belco90 avatar Jul 11 '20 10:07 Belco90