question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Capitalization inconsistency with `yarn rw g page` generator

See original GitHub issue

Reproducible 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
cannikincommented, Oct 18, 2021

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 with fooPage 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:

pascalcase("ABTest") # => "ABTest"

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:

pascalcase(paramCase("ABTest")) # => "AbTest"

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 with FOOBARPage (which is what would happen without that extra paramCase). The list of test cases checks that all of these inputs all become FooBarPage:

  • FooBar
  • fooBar
  • foo-bar
  • foo_bar
  • FOO_BAR

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 extra paramCase call in the filename generation. Everyone okay with that?

1reaction
aggmoulikcommented, Oct 19, 2021

Well, I am with the community I just want to share my views. I will update the PR.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found