-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix unused import in generator cell test template #5827
Conversation
✅ Deploy Preview for redwoodjs-docs canceled.
|
Hi again @Philzen! This import is something I've been aware of, but I wonder if its not worth removing this import? I would instead add the unused screen imports to the page and component generators probably. Generators often produce code that doesn't pass linting, and thats totally okay, if it serves another purpose - in this case, giving people a hint that screen can be imported from the package. |
Well, that's actually redwood's very own linting rules 🤷 ... and thus makes my code tab red 😢
I beg to differ – personally my level of trust in a framework degrades if it generates code that doesn't pass its own linting rules, that's a contradiction of sorts.
Yes there is a clear, unambiguous hint where screen needs to imported from if required. redwood/packages/cli/src/commands/generate/cell/__tests__/__snapshots__/cell.test.js.snap Lines 115 to 119 in 2513813
IMHO there is absolutely no advantage to keeping an unused import lying around in generated files – which may or may not ever be used – or is there? |
@jtoar refresh my memory, was |
@dthyresson No I don't think so. Just went through the blame, and it was added quite some time ago: #290. But the template code that uses screen has long since been removed: #1397. One thing I find odd is that I only see |
@Philzen I've merged main into this branch. I think you've expressed distaste at that before, so sorry that I went ahead and did that! I just want to make sure checks pass on main, and I don' think anymore code changes need to be made. |
@jtoar no worries, as those ugly update merge commits are squashed anyway on merge to It's only a nuisance if there were changes requested and i need to add additional (fixup) commits, b/c with merge strategy my commits are buried deep down in the history, while i am used to see my unmerged work always on top. So imho we're doing contributors a favor when there are still changes requested to use the rebase button to pull in the recent updates from |
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.
Approving just to get this off my "needs review" list, but still open to discuss @dac09 if you disagree with my comment earlier
That's cool with me – IMHO this is a clear improvement to the test template. 👍 |
Oh, i just realized #6058 has been cancelled / not merged. The successor #5985 (which is still a draft) doesn't seem to fix #5060. @dac09 maybe reopen & merge this PR for the time being? Then we could close #5060 and move on w/o the generator producing red squiggles in generated tests 😉 |
So we discussed the generated tests on a team meeting. We decided we're not going to use We did not however (iirc) decide if we should still leave the screen import in there or not. I'll reopen this PR for now. |
We have this comment further down in the file I know we said on the meeting that we sometimes generate unused code to educate our users on how to use the code, to discover features etc. In these files I think that generated comment is enough to show the users how to write tests. So I think we can remove the unused import. @dac09 What do you think? Is the comment enough? |
Oh yeah, that is a darn good reason for not using screen in the test template that @cannikin brought up there, i did not think of that catch 🤦♂️, thanks for sharing.
Cheers @Tobbe – just wanted to add that @jtoar confirmed that this only seems to apply to typescript generated tests, not js. So should the team decide to keep it in this should be at least harmonized with the JS behaviour. I'd like to add that i strongly feel we should strive to ensure the generator never produces code that does not follow the linting rules – as it produces red squiggles in the IDE. Such a behaviour adds uncertainty to the DX (i'm speaking from my own experience and other Redwood beginners have also expressed that) and what's worse, it could degrade the perceived quality / stability of the (awesome!) project and its (awesome!) generators. |
I understand Philzen - I don't think we'll ever really see eye to eye on this in all honesty - but I'll try and explain my position anyway. 1. Generators do not produce code that you just run and then deploy. 2. Its impossible to make sure generators work for all projects, across all prisma schemas, across all auth providers, across all deployment targets Linting errors are just stylistic opinions - which ofcourse in your project you decide how severe or lenient you want to be. 3. Unused variables in some templates |
Just needs a test-project rebuild. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 13d74d3. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
@dac09 no need for conflict. I simply did an interactive rebase on main, and added a commit to update the fixtures. I believe you can simply merge this one. |
From the root of your local copy of the RW framework, it should be:
|
Cheers @jtoar – So since yesterday i learned about fixtures and snapshot by nagging you guys from the core team ;) I briefly checked https://redwoodjs.com/docs/contributing-walkthrough and https://redwoodjs.com/docs/contributing for "snapshot" but couldn't find any info. Should we maybe take a note / issue to add this info to the PR process documentation? On the other hand, this has the potential to scare newbies away, but i guess it's "no CI pain, no gain" 😉 |
This is what I usually do when I need to update the snapshots (I use auth in the example, but obviously adjust to your needs)
|
Sure, and i don't believe we have to. Currently, all of these issues i worked on were out-of-the-box, mint-configuration eslint generator violations. Talking about my project – no it's actually not (yet) that different – we're using the default linting rules shipped in the ESLint-package (although we'll soon improve upon them and i am also planning to suggest some for Redwood 🧐). As soon as a user goes down the road to customize them, they will be more advanced, and expect one or the other red squiggle, as they will be knowing what they are doing. But then they're out of the woods and of course we don't need to cater for their customized environments.
I simply believe it would be a great win if we could just add |
Closes #5060