Skip to content

Commit 0259ae9

Browse files
authored
Merge pull request #5 from kingston/kingston/fix-prettier-formatting
fix: Add check to make sure we don't attempt to format invalid files
1 parent 8bd9838 commit 0259ae9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'workspace-meta': patch
3+
---
4+
5+
Fix prettier formatter to only format files that Prettier can parse. The formatter now uses Prettier's `getFileInfo` API to check if a file has an inferred parser before attempting to format it, preventing errors on unsupported file types.

CLAUDE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ pnpm prettier:write
130130
# Build package
131131
pnpm build
132132
```
133+
134+
## Changesets
135+
136+
If you are adding a new feature or changing an existing feature, please also add a new Changeset for it in the `.changeset/` directory of the form (keeping things to patch changes for now):
137+
138+
```markdown
139+
---
140+
'package-name': patch
141+
---
142+
143+
Description of the feature or change
144+
```

src/helpers/prettier-formatter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ export async function prettierFormatter(
2626
throw new Error('Prettier is not available');
2727
}
2828

29+
// Check if Prettier can parse this file
30+
const fileInfo = await prettier.getFileInfo(filename);
31+
if (!fileInfo.inferredParser) {
32+
// Prettier doesn't know how to format this file type
33+
return content;
34+
}
35+
2936
// Resolve prettier config for the file
3037
const options = await prettier.resolveConfig(filename);
3138

0 commit comments

Comments
 (0)