mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.5k stars 764 forks source link

Why `_` isn't removed when sanitizing identifiers #904

Closed qeude closed 2 months ago

qeude commented 2 months ago

👋 Hi!

I was just wondering why _ was explicitly removed from disallowedCharacters.

I'm asking because it creates weird variables and methods names such as this: key home_page.title would become R.string.localizable.home_pageTitle while it would be more elegant and Swifty to have R.string.localizable.homePageTitle.

It could be great to at least have a configuration (like proposed here) to allow that if we don't want that behavior as a default one.

Thanks!

mac-cain13 commented 2 months ago

Because it's an allowed character in variable names in Swift. R.swift tries to just take over your original asset name as the variable name used, only characters that aren't allowed to be used are cleaned up. When we need to do cleanup we do some formatting of the variable name to make sure things are still readable/logical.

I can see how homePageTitle reads nicer in code, but I think it having a setting for it would be a bit overkill. I feel the maintenance load such settings bring to the codebase don't outweigh the benefit. I would advise to rename the localisable string key instead if possible.