-
Notifications
You must be signed in to change notification settings - Fork 136
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
Creating a component with hyphens generates an error #26
Comments
Isn't that a complexity you would not want to maintain in the future? Personally, I cant see any problem with current implementation, as React Components name should be CamelCased by default. Besides I can see a lot of possibilities that such a thing can lead to subtle bugs in the future. |
@jelly8173 actually, React Components should be PascalCase not camelCase. The PR I created is solving that kind of bugs, since it's always forcing the component to have PascalCase no matter what kind of notation you use. You can take a look at my implementation, I think it's not so complex after all, it basically parse the string via regex in one single function. |
@fsgreco yeah, I checked your implementation and spotted a bug there -- 1 useless conversion of first letter lowercase and then uppercase, so you already showed that this is simple but somehow a complex problem 🤣 I think that any "covert" substitutions and conversions are bad things as program working as a black box may issue unpredictable results, so better give some error messages like: "React components should be PascalCase", because that is the thing, they should be and programmer must not be allowed to make typos like "aNewReactComponent" or "some-new-react-component". BTW, what if I make a typo and your version that eats everything accepts it immediately? I would need to delete newly created component and start again! |
It seems to me more like an excess of zeal than a bug, but if you can point it out better (or better still provide me the solution I will be more than happy to fix it) :)
Yeah this is an alternative solution indeed. My PR deliberately choose to be more "error prone" because in that way it took less burden from the developer, no matter what name I gave I know it will be PascalCase.
This is a problem that also the actual implementation has. Actually at the moment it's worse (as I explained in the first message) with the actual state of the CLI a developer can do a typo like this: "new-component aCamelCaseComponent" or this "new-component a_component_with_underscores" and the component will be generated with that typo, so one need to delete and start again as you just pointed out. |
At the moment if we give a name with hyphens the CLI returns an error.
For example, at the moment this :
will return this kind of error:
At the same time this commands will work, but will create the folder, the file and the function with the name provided:
I think this is a problem that could be easily solved
I'm already working on a fix to try to standardize any of this examples to a PascalCase convention.
Will send you a Pull Request as soon as I finish testing it.
The text was updated successfully, but these errors were encountered: