Capitalization inconsistency with `yarn rw g page` generator
See original GitHub issueReproducible by doing:
yarn rw g page ABTest
Which will add the following line to Routes.tsx
<Route path="/ab-test" page={ABTestPage} name="abTest" />
But will generate directory pages/AbTestPage with AbTestPage.tsx , stories, jest files with the b uncapitalized
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:14 (11 by maintainers)
Top Results From Across the Web
Merge branch 'main' into gh-3568 · redwoodjs/redwood@403e517 ...
Fix: Capitalization inconsistency with yarn rw g page generator #5681. Sign in to view logs · Sign in to view logs. Workflow file ......
Read more >Command Line Interface | RedwoodJS Docs
Generating a model automatically runs yarn rw record init as well. generate page. Generates a page component and updates the routes. yarn redwood...
Read more >Capitalize My Title
Automatically capitalize & convert case of text to Title Case (in AP, APA, Chicago, MLA), sentence case, UPPERCASE, lowercase, and more.
Read more >Command Line Interface Guidelines
An open-source guide to help you write better command-line programs, taking traditional UNIX principles and updating them for the modern day.
Read more >Effective Go - The Go Programming Language
type T struct { name string // name of the object value int // its value } ... The code reads well if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So obviously creating files and routes manually you can use any capitalization you want and you’re good to go.
The problem is the generators because we want to follow component naming convention and make them
PascalCasePage
. We can’t just accept the user’s casing because we could end up withfooPage
or anything else. That means running it through the pascalcase package, and in this case it looks like it actually has the behavior we want, because:It looks like the problem is in the code that converts the string entered on the command line to the filename. It actually does two conversions:
The param-case package turns everything lowercase first, then turns any special characters into dashes.
I’m sure there’s a reason we did this, and it was probably to make sure that if you did something like
yarn rw g page FOO_BAR
you wouldn’t end up withFOOBARPage
(which is what would happen without that extraparamCase
). The list of test cases checks that all of these inputs all becomeFooBarPage
:I double checked Rails behavior (of course) and using the generators actually removes multiple capitals in a row to end up with true PascalCase:
ABtest => AbTestController
.I’m okay with keeping the user’s intended capitalization (after running through
pascalcase
). The number of people generating with an all-caps name is probably pretty low, and if they do want that, who are we to stop them? So, that means we would leave the route generation as-is and remove the extraparamCase
call in the filename generation. Everyone okay with that?Well, I am with the community I just want to share my views. I will update the PR.