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

Scaffold breaks with some custom Prettier configs #3027

Closed
zackdotcomputer opened this issue Jul 10, 2021 · 3 comments · Fixed by #3040
Closed

Scaffold breaks with some custom Prettier configs #3027

zackdotcomputer opened this issue Jul 10, 2021 · 3 comments · Fixed by #3040
Labels
bug/confirmed We have confirmed this is a bug topic/generators-&-scaffolds

Comments

@zackdotcomputer
Copy link
Contributor

#2609 changed scaffold.js to resolve #2546. Part of that change is detecting whether Set is already imported into Routes.{tsx|ts|js}. It does this using a regex over the file here:

const [redwoodRouterImport, importStart, spacing, importContent, importEnd] =
  routesContent.match(/(import {)(\s*)([^]*)(} from '@redwoodjs\/router')/) ||
  []
const routerImports = importContent.replace(/\s/g, '').split(',')

However #351 added in support for custom prettier configs. With the default settings, this all works fine. But, if you prefer " to ' and enforce that with prettier using singleQuote: false,, then this causes the regex to fail because it has a hard-coded expectation for '.

✖ Adding set import...
    → Cannot read property 'replace' of undefined

It's possible the fix here is as simple as changing the two ' in the regex to ('|"), but I am worried I'm being naive because I'm still getting used to the Redwood ecosystem. I also worry that even if that simple solution works in this case that there might be other issues lurking in the generators that assume a code-style that may no longer actually be enforced.

@zackdotcomputer
Copy link
Contributor Author

fwiw even after reverting to single-quotes to fix this, the generator also removes the ; from the end of the import even if your prettier requests it. Strange since the rest of the generator seems to respect prettier.

@jtoar jtoar added topic/generators-&-scaffolds bug/confirmed We have confirmed this is a bug labels Jul 13, 2021
@jtoar
Copy link
Contributor

jtoar commented Jul 13, 2021

It's possible the fix here is as simple as changing the two ' in the regex to ('|"), but I am worried I'm being naive because I'm still getting used to the Redwood ecosystem.

Don't be worried at all, you already did some great investigative work here! And even provided all the right links so that readers like me could get all the context they needed in no time 🚀

I don't think your fix is unreasonable at all—it's an import, and that's always going to have single or double quotes right?

I also worry that even if that simple solution works in this case that there might be other issues lurking in the generators that assume a code-style that may no longer actually be enforced.

This is a totally valid concern, and the code powering our generators definitely has a lot of technical debt. It's way overdue for a refactor. I'm not sure when we'll exactly get around to it; there's a lot of features we want to add, mainly customizability. I wouldn't worry about possible bugs that may be lurking and haven't reared their head yet (that's something we'll be 100% focused on during the v1 rc). Reporting issues just like you're doing is already more than enough!

Also the issue about linting you mentioned sounds similar to #1551.

@zackdotcomputer
Copy link
Contributor Author

👍 always trying to be a good open source citizen and come in with a bit of understanding for the problem I'm reporting.

I'll get a PR open for that regex swap and pray I don't awaken any undisturbed monsters lurking in the generators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug topic/generators-&-scaffolds
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants