jlevy / jlevy/repren

Support dash-separated names in --preserve-case

Open
#45 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
374
Forks
39
Avg merge
3m
Merged PRs (30d)
1

Description

## 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`:

```python
# 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-component` → `new-widget`

**Expected behavior:** Should also generate:
- `my-component` → `new-widget` (kebab-case)
- `my_component` → `new_widget` (snake_case)
- `myComponent` → `newWidget` (camelCase)
- `MyComponent` → `NewWidget` (PascalCase)
- `MY_COMPONENT` → `NEW_WIDGET` (SCREAMING_SNAKE)

## Suggestion

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

```python
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.