Skip to content

Commit c94db33

Browse files
43081jbenmccannAdrianGonz97
authored
fix(prettier): skip non-JSON prettierrc config (#527)
Co-authored-by: Ben McCann <[email protected]> Co-authored-by: AdrianGonz97 <[email protected]>
1 parent 701626c commit c94db33

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/pretty-emus-breathe.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix: warn on an unparsable `.prettierrc` config file

packages/addons/prettier/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ export default defineAddon({
2424
});
2525

2626
sv.file('.prettierrc', (content) => {
27-
const { data, generateCode } = parseJson(content);
27+
let data, generateCode;
28+
try {
29+
({ data, generateCode } = parseJson(content));
30+
} catch {
31+
log.warn(
32+
`A ${colors.yellow('.prettierrc')} config already exists and cannot be parsed as JSON. Skipping initialization.`
33+
);
34+
return content;
35+
}
2836
if (Object.keys(data).length === 0) {
2937
// we'll only set these defaults if there is no pre-existing config
3038
data.useTabs = true;

0 commit comments

Comments
 (0)