Skip to content

Support dash-separated names in --preserve-case #45

Description

@jlevy

Summary

The --preserve-case feature generates case variants for camelCase and underscore_separated names, but does not handle dash-separated (kebab-case) names like my-component or some-value.

Details

There is a TODO at line 688 of repren.py:

# TODO: Could handle dash-separated names as well.

The _split_name() function currently checks for underscores first, then falls back to camelCase splitting. Dash-separated names (common in CSS class names, HTML attributes, CLI flags, file names, and package names) are not recognized — the entire string is treated as one word.

Example

With --preserve-case --from my-component --to new-widget:

Current behavior: Only matches literal my-componentnew-widget

Expected behavior: Should also generate:

  • my-componentnew-widget (kebab-case)
  • my_componentnew_widget (snake_case)
  • myComponentnewWidget (camelCase)
  • MyComponentNewWidget (PascalCase)
  • MY_COMPONENTNEW_WIDGET (SCREAMING_SNAKE)

Suggestion

Extend _split_name() to detect - as a separator, similar to _:

if "_" in name:
    return "_", name.split("_")
elif "-" in name:
    return "-", name.split("-")
else:
    # CamelCase splitting...

Then update all_case_variants() to also generate the dash-separated variant.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions