Skip to content

Commit f086978

Browse files
authored
Only run Prettier if project does not define Prettier config (#10)
1 parent 59c8b68 commit f086978

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

bin/cli.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ for (let i = 0; i < args.length; i++) {
4545
}
4646
}
4747

48+
function hasPrettierConfig(targetDir) {
49+
const possibleConfigs = [
50+
".prettierrc",
51+
".prettierrc.json",
52+
".prettierrc.js",
53+
".prettierrc.yml",
54+
".prettierrc.yaml",
55+
".prettierrc.toml",
56+
"prettier.config.js",
57+
".prettierrc.config.js",
58+
];
59+
60+
// Check for Prettier config files
61+
for (const config of possibleConfigs) {
62+
if (fs.existsSync(path.join(targetDir, config))) {
63+
return true;
64+
}
65+
}
66+
67+
return false;
68+
}
69+
4870
async function runPrettier(targetDir, dryRun) {
4971
try {
5072
// Get Prettier config from this package
@@ -94,7 +116,9 @@ async function runPrettier(targetDir, dryRun) {
94116
sortTsConfigFile(tsconfigPath, options);
95117

96118
// Run Prettier on all files
97-
await runPrettier(targetDir, options.dryRun);
119+
if (!hasPrettierConfig(targetDir)) {
120+
await runPrettier(targetDir, options.dryRun);
121+
}
98122

99123
if (options.dryRun) {
100124
console.info("Dry run completed. No files were modified.");

0 commit comments

Comments
 (0)