Skip to content

Commit 66f27cd

Browse files
committed
fix: derive valid identifiers from filenames of any casing
1 parent 8526737 commit 66f27cd

7 files changed

Lines changed: 144 additions & 97 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ Controls whether TypeScript component snippets name their props type `Props` or
121121

122122
Controls how component snippets derive their name. `directoryForIndex` uses the parent directory for an `index.*` file, so `Button/index.tsx` becomes `Button`; other filenames still use their basename.
123123

124+
Either way the name is converted to PascalCase, so `delete-modal.tsx` becomes `DeleteModal`. Separators such as `-`, `_`, and `.` are dropped, and names that are already PascalCase are left unchanged.
125+
126+
Redux slice snippets are not components, so they are only renamed when the filename would not be a valid identifier: `user-slice.ts` becomes `userSlice`, while `UserSlice.ts` is left alone.
127+
124128
### `componentWrapper`
125129

126130
**Type:** `string`

‎src/helpers/snippetPlaceholders.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const propsPlaceholders = {
1212
} as const;
1313

1414
const componentNamePlaceholders = {
15-
filename: Mappings.FileName,
16-
directoryForIndex: Mappings.DirectoryNameForIndex,
15+
filename: Mappings.ComponentFileName,
16+
directoryForIndex: Mappings.ComponentDirectoryNameForIndex,
1717
} as const;
1818

1919
export const replaceSnippetPlaceholders = (
@@ -48,6 +48,7 @@ export const replaceSnippetPlaceholders = (
4848
.replaceAll(Placeholders.TypeState, statePlaceholder)
4949
.replaceAll(Placeholders.ComponentProps, propsName)
5050
.replaceAll(Placeholders.ComponentName, componentNamePlaceholder)
51+
.replaceAll(Placeholders.SliceName, Mappings.SliceFileName)
5152
.replaceAll(Placeholders.FileName, Mappings.FileName)
5253
.replaceAll(Placeholders.ComponentWrapper, componentWrapperPlaceholder)
5354
.replaceAll(Placeholders.FirstTab, Mappings.FirstTab)

0 commit comments

Comments
 (0)