-
Notifications
You must be signed in to change notification settings - Fork 148
Allow destructuring from screen with prefer-screen-queries #143
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
Comments
Hey Joe! Thanks for opening this issue. Interesting one. The rule shouldn't complain in that case, so I'm adding the label "bug" here. |
not sure this is a bug. The point of the rule is using screen imported to avoid destructuring- not the origin of the methods. If the methods come from screen or the returned value from the only exception that applies is |
I didn't think about it in that way. That makes sense, I think you are completely right @gndelia |
This is a good point, and I think the second example in my original comment is a better example - i.e. destructuring all the needed queries from The way the rule is currently worded/implemented does imply that the origin of the methods is important and that the point of the rule is not just avoiding destructuring - otherwise wouldn't the following be acceptable?
|
from what I understand in kent c dodds post about using screen
as I see it, your second example should be triggered by the linter as "incorrect", according to the rule. The only allowed scenarios to query should be |
I understand, that makes sense. There are benefits to using queries from Additionally, there are benefits to preferring not destructuring queries out, as you are able to change the queries you are using without having to keep the destructure up to date - but this can be achieved by both It feels like two separate concerns to me - perhaps we should have two rules, e.g. |
Ok so based on "The benefit of using screen is you no longer need to keep the render call destructure up-to-date as you add/remove the queries you need" I think it's clear one of the main points of using Having said that, I understand @joe-reed's point. It's completely fine to destructure The main point of the rule is to encourage using To wrap up my thoughts around this: the goal of this rule is use Happy to clarify this in the rule doc tho. We can link that section from KCD's common mistake post and include some conclusions from this discussion. |
It's clearly one of the benefits as mentioned in the blog post, but not the only benefit, otherwise why use
In my opinion it would be useful to be able to only allow developers to use queries from It seems a shame to say that if you do want to destructure from |
I understand your point, and it's a fair point to be honest. Let me think about it again, but I'm not sure about relaxing this rule for allowing destructuring |
@joe-reed just exploring other possibilities. What do you think about making this rule configurable? So by default it works like it is but you could relax it by passing |
How I see it it's still invalid while destructuring screen, and the point made by Kent is still valid (alltough it's not as big as a pain as with render).
So every time a new query is used, you will still need to add it to the destructure. |
That's certainly an option. Having an additional rule for disallowing destructuring does have the benefit that if a team prefers to use queries from
I agree that the best option is to have the combination of using preferring queries from Then developers would be free to choose from
|
Ok so after thinking about this, my final position it's to not implementing this option. The main point of this ESLint plugin is helping users "to follow best practices and anticipate common mistakes". Using getting queries from |
Having said that, I'm happy to update the rule description to cover why it won't allow you to destructure queries from |
It would be great if
prefer-screen-queries
could allow destructuring fromscreen
, for example:or
The text was updated successfully, but these errors were encountered: