Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Couldn't find any guides for external contributor PRs, so I'm winging this a bit.
What?
snake_case
functions to be used for components#[component]
macro (very minor change)How?
Added a little function which uses the
convert_case
crate to check whetheritem.sig.ident
issnake_case
, and if so it converts theident
toPascalCase
(referred to ascamelCase
in the docs, but I don't think the distinction matters too much because most people refer to it as that anyway) which is later used to generate theComponent
andComponentProps
structs.The reason it only bothers to convert from
snake_case
is because that's the convention for naming functions in Rust, and converting from other types of casing might lead to some extra edge cases.Why?
snake_case
function names for components (which are then converted toCamelCase
to avoid the structs being confused for html elements) seems reasonable to me; sometimes it's the little things such as having to edit your IDE/cargo fmt
config or dealing with a bunch of warnings when using a specific framework that can put people off.snake_case
function doesn't want to become a component is time that could have been spent learning something more important within the framework.Improvements/Limitations
convert_case
handles acronyms (e.g.does_HTML_stuff
), so in cases like that it might not recognise the function name assnake_case
and no conversion will be done.CamelCase
(_my_component -> MyComponent
,my_component_ -> MyComponent
).I am of course not as well versed in the internals of Leptos as the maintainers, so perhaps there's some reason that this can't be implemented. If that's the case then feel free to reject this PR, but I'd still be interested in understanding why it won't work, just because I'm curious.