Skip to content

Commit 7699758

Browse files
authored
fix: improve plugin search logic to prevent infinite recursion (#255)
1 parent 259a230 commit 7699758

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/utils.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,25 @@ async function formatCode(
277277
}
278278

279279
const findPluginByParser = (parserName: string, options: ParserOptions) => {
280-
const tsPlugin = options.plugins.find((plugin) => {
280+
const plugins = options.plugins ?? [];
281+
282+
// Only consider plugins that appear *before* prettier-plugin-jsdoc.
283+
// Plugins that appear after us typically wrap our parser; delegating to them
284+
// from our parse/preprocess hooks can create infinite recursion.
285+
const jsdocIndex = plugins.findIndex((plugin) => {
286+
return (
287+
typeof plugin === "object" &&
288+
plugin !== null &&
289+
!(plugin instanceof URL) &&
290+
(plugin as any).name &&
291+
(plugin as any).name === "prettier-plugin-jsdoc"
292+
);
293+
});
294+
295+
const searchPlugins =
296+
jsdocIndex === -1 ? plugins : plugins.slice(0, jsdocIndex);
297+
298+
const tsPlugin = searchPlugins.find((plugin) => {
281299
return (
282300
typeof plugin === "object" &&
283301
plugin !== null &&

0 commit comments

Comments
 (0)