-
Notifications
You must be signed in to change notification settings - Fork 27
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
Check for illegal characters when formatting names #35
Check for illegal characters when formatting names #35
Conversation
Thanks! Also, could you move the function to FWIW, if something like this has a tendency to complicate the core code in |
Lol oops! I put the function in the 🤔 Right now, there's no option to customize the Haskell type name. So its definitely going to be a problem if we have any illegal characters there, and we can easily report the error as soon as we have the I've modified the PR to also check datatype constructors. And at this point I recognize that I've got a problem - the formatting options allow you to modify the interface and type names, which happens well after With this patch, anyone that is currently doing Oof. I'd propose to modify the |
Oh right, that's unfortunate. I don't love the idea of a breaking change to the name formatters API, although in hindsight it seems like the As an alternative hack, what about just replacing all invalid characters with underscores at formatting time? :) Or just spitballing here, what about automatically converting invalid chars to an equivalent word, so |
I think our linter complains about trailing A default name formatter that throws an error on an invalid character + tells you how to fix it may be the least invasive solution - we can change the formatter to be something like: defaultNameFormatter str = do
case NonEmpty.nonEmpty str of
Nothing -> error "Name cannot be empty"
Just nameChars -> case checkIllegalNameChars nameChars of
Just badChars -> error $ concat ["The name ", str, " contains illegal characters: ", toList badChars, "\nConsider setting a default name formatter that replaces these characters." ]
Nothing -> str Obviously would want to trace the "how did i get here" so users can backtrack to exactly what failed + which name formatter needs to be invoked. I do think the best choice is moving the formatting options to the
|
Setting the default name formatter to error out as you describe sounds like a good first step. Maybe that would be sufficient to close #34 ? If you get an informative error message at the formatting stage, would you still feel strongly about moving those options to the TH side? |
Yeah, I generally want problems reported ASAP. At least for our codebase, the derivation happens well before code generation, which is a totally separate step. I wouldn't want to introduce a runtime dependency on |
Huh? There's no Just thinking through the implications of moving the formatting options -- it could harm at least one workflow I can imagine. What if you have lots of primed types like |
Yeah, that would require a migration of code - but it shouldn't have to be a hard one. At work we consolidate our default options, so we can easily control what that default is by altering a single value in a single module. Factoring out the duplication in argument passing wouldn't be a huge problem. |
All right, what do you think of the following?
|
Sounds good! I'll make the relevant changes. |
OK, should be ready for review :) |
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.
Looks great! Just a few comments.
…logies/aeson-typescript into mattp/error-on-apostrophes
Sorry, this fell off my radar -- merging now! |
Automatic merge failed, manually rebased and merged in ba5d998 |
This PR checks the type name for illegal characters before generating code.