Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,25 @@ async function formatCode(
}

const findPluginByParser = (parserName: string, options: ParserOptions) => {
const tsPlugin = options.plugins.find((plugin) => {
const plugins = options.plugins ?? [];

// Only consider plugins that appear *before* prettier-plugin-jsdoc.
// Plugins that appear after us typically wrap our parser; delegating to them
// from our parse/preprocess hooks can create infinite recursion.
const jsdocIndex = plugins.findIndex((plugin) => {
return (
typeof plugin === "object" &&
plugin !== null &&
!(plugin instanceof URL) &&
(plugin as any).name &&
(plugin as any).name === "prettier-plugin-jsdoc"
);
});

const searchPlugins =
jsdocIndex === -1 ? plugins : plugins.slice(0, jsdocIndex);

const tsPlugin = searchPlugins.find((plugin) => {
return (
typeof plugin === "object" &&
plugin !== null &&
Expand Down