From 130e8e565a7a32487b851703d3280d314075b175 Mon Sep 17 00:00:00 2001 From: Ze-Zheng Wu Date: Tue, 20 Feb 2024 11:16:30 +0800 Subject: [PATCH] fix: language plugin check Disable language plugin check because of false positives and edge cases across platforms. The original check mechanism also prevents loading custom plugins. --- src/embedded/glsl/embedder.ts | 3 --- src/embedded/ini/embedder.ts | 3 --- src/embedded/java/embedder.ts | 3 --- src/embedded/jsonata/embedder.ts | 7 ------- src/embedded/latex/embedder.ts | 3 --- src/embedded/nginx/embedder.ts | 3 --- src/embedded/pegjs/embedder.ts | 3 --- src/embedded/php/embedder.ts | 3 --- src/embedded/prisma/embedder.ts | 3 --- src/embedded/properties/embedder.ts | 3 --- src/embedded/pug/embedder.ts | 3 --- src/embedded/ruby/embedder.ts | 3 --- src/embedded/sh/embedder.ts | 3 --- src/embedded/sql/embedder.ts | 3 --- src/embedded/toml/embedder.ts | 3 --- src/embedded/utils.ts | 23 +---------------------- src/embedded/xml/embedder.ts | 3 --- 17 files changed, 1 insertion(+), 74 deletions(-) diff --git a/src/embedded/glsl/embedder.ts b/src/embedded/glsl/embedder.ts index 9abb89a..26a4aa0 100644 --- a/src/embedded/glsl/embedder.ts +++ b/src/embedded/glsl/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-glsl", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/ini/embedder.ts b/src/embedded/ini/embedder.ts index cdc43f8..a75eb30 100644 --- a/src/embedded/ini/embedder.ts +++ b/src/embedded/ini/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-ini", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/java/embedder.ts b/src/embedded/java/embedder.ts index 382a19e..c92e6f8 100644 --- a/src/embedded/java/embedder.ts +++ b/src/embedded/java/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-java", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/jsonata/embedder.ts b/src/embedded/jsonata/embedder.ts index 7135df5..afce523 100644 --- a/src/embedded/jsonata/embedder.ts +++ b/src/embedded/jsonata/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,12 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound( - "@stedi/prettier-plugin-jsonata", - options, - commentOrTag, - ); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/latex/embedder.ts b/src/embedded/latex/embedder.ts index c514909..71d4d75 100644 --- a/src/embedded/latex/embedder.ts +++ b/src/embedded/latex/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-latex", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/nginx/embedder.ts b/src/embedded/nginx/embedder.ts index 5ca01e5..757e134 100644 --- a/src/embedded/nginx/embedder.ts +++ b/src/embedded/nginx/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-nginx", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/pegjs/embedder.ts b/src/embedded/pegjs/embedder.ts index 8afb56e..d54de0f 100644 --- a/src/embedded/pegjs/embedder.ts +++ b/src/embedded/pegjs/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-pegjs", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/php/embedder.ts b/src/embedded/php/embedder.ts index 8a3f1b9..0182469 100644 --- a/src/embedded/php/embedder.ts +++ b/src/embedded/php/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("@prettier/plugin-php", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/prisma/embedder.ts b/src/embedded/prisma/embedder.ts index 1b7b762..cb2b176 100644 --- a/src/embedded/prisma/embedder.ts +++ b/src/embedded/prisma/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-prisma", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/properties/embedder.ts b/src/embedded/properties/embedder.ts index ad4f460..3c76f3f 100644 --- a/src/embedded/properties/embedder.ts +++ b/src/embedded/properties/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-properties", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/pug/embedder.ts b/src/embedded/pug/embedder.ts index 7470f36..aeb03f9 100644 --- a/src/embedded/pug/embedder.ts +++ b/src/embedded/pug/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("@prettier/plugin-pug", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/ruby/embedder.ts b/src/embedded/ruby/embedder.ts index ddccf0e..0c20d4f 100644 --- a/src/embedded/ruby/embedder.ts +++ b/src/embedded/ruby/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("@prettier/plugin-ruby", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/sh/embedder.ts b/src/embedded/sh/embedder.ts index 5a39bc6..94cd341 100644 --- a/src/embedded/sh/embedder.ts +++ b/src/embedded/sh/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-sh", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/sql/embedder.ts b/src/embedded/sql/embedder.ts index 2a9fc29..f7d884a 100644 --- a/src/embedded/sql/embedder.ts +++ b/src/embedded/sql/embedder.ts @@ -6,7 +6,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -26,8 +25,6 @@ export const embedder: Embedder = async ( const plugin = resolvedOptions.embeddedSqlPlugin ?? "prettier-plugin-sql"; - throwIfPluginIsNotFound(plugin, resolvedOptions, commentOrTag); - const { node } = path; const { createPlaceholder, placeholderRegex } = preparePlaceholder(); diff --git a/src/embedded/toml/embedder.ts b/src/embedded/toml/embedder.ts index b2e19db..67c07e4 100644 --- a/src/embedded/toml/embedder.ts +++ b/src/embedded/toml/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("prettier-plugin-toml", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions, diff --git a/src/embedded/utils.ts b/src/embedded/utils.ts index b045138..18ff7a4 100644 --- a/src/embedded/utils.ts +++ b/src/embedded/utils.ts @@ -1,5 +1,5 @@ import type { Comment, Expression, TemplateLiteral } from "estree"; -import type { AstPath, Doc, Options } from "prettier"; +import type { AstPath, Doc } from "prettier"; import { builders, utils } from "prettier/doc"; import type { LiteralUnion, @@ -69,27 +69,6 @@ export function simpleRehydrateDoc( return contentDoc; } -export function throwIfPluginIsNotFound( - pluginName: string, - options: Options, - commentOrTag: string, -) { - if ( - !( - options.plugins?.some( - (p) => - (p as { name?: string }).name?.match( - new RegExp(`(^|/)${escapeRegExp(pluginName)}($|/)`), - ) ?? false, - ) ?? false - ) - ) { - throw new Error( - `Cannot format embedded language identified by "${commentOrTag}", because plugin "${pluginName}" is not loaded.`, - ); - } -} - export function insertLanguage( languages: string[], language: string, diff --git a/src/embedded/xml/embedder.ts b/src/embedded/xml/embedder.ts index 3aca4b2..3437c33 100644 --- a/src/embedded/xml/embedder.ts +++ b/src/embedded/xml/embedder.ts @@ -5,7 +5,6 @@ import { preparePlaceholder, printTemplateExpressions, simpleRehydrateDoc, - throwIfPluginIsNotFound, } from "../utils.js"; import { language } from "./language.js"; @@ -18,8 +17,6 @@ export const embedder: Embedder = async ( options, { commentOrTag, embeddedOverrideOptions }, ) => { - throwIfPluginIsNotFound("@prettier/plugin-xml", options, commentOrTag); - const resolvedOptions = { ...options, ...embeddedOverrideOptions,