803 B
803 B
Add isSupported function support for languages API (#17331 by @JounQin, #17490 by @fisker)
Previously, languages API for custom plugins only supported inferring parser based on the file basename or extension.
Prettier main added isSupported: (options: { filepath: string }) => boolean function to allow plugin check if file is supported based on the full path (eg: files in a specific directory).
:::note
Prettier can not ensure that filepath exists on disk.
When using from APIs(eg: prettier.format()), Prettier can not ensure it's a valid path either.
:::
If no isSupported provided, it just behaves the same way as before.
export const languages = [
{
name: "foo",
parsers: ["foo"],
isSupported: ({ filepath }) => filepath.includes(".foo"),
},
];