Skip to content

Commit

Permalink
fix: language plugin check
Browse files Browse the repository at this point in the history
Disable language plugin check because of false positives and edge cases across platforms.
The original check mechanism also prevents loading custom plugins.
  • Loading branch information
Sec-ant committed Feb 20, 2024
1 parent 595744c commit 442be39
Show file tree
Hide file tree
Showing 18 changed files with 8 additions and 74 deletions.
7 changes: 7 additions & 0 deletions .changeset/angry-countries-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"prettier-plugin-embed": patch
---

Fix language plugin check false positives.

`throwIfPluginIsNotFound` is discarded. Detailed explanation can be found at https://github.com/Sec-ant/prettier-plugin-embed/issues/84#issuecomment-1953844934.
3 changes: 0 additions & 3 deletions src/embedded/glsl/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-glsl", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/ini/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-ini", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/java/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-java", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
7 changes: 0 additions & 7 deletions src/embedded/jsonata/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,12 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound(
"@stedi/prettier-plugin-jsonata",
options,
commentOrTag,
);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/latex/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-latex", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/nginx/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-nginx", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/pegjs/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-pegjs", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/php/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("@prettier/plugin-php", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/prisma/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-prisma", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/properties/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-properties", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/pug/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("@prettier/plugin-pug", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/ruby/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("@prettier/plugin-ruby", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/sh/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-sh", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/sql/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -26,8 +25,6 @@ export const embedder: Embedder<Options> = async (

const plugin = resolvedOptions.embeddedSqlPlugin ?? "prettier-plugin-sql";

throwIfPluginIsNotFound(plugin, resolvedOptions, commentOrTag);

const { node } = path;

const { createPlaceholder, placeholderRegex } = preparePlaceholder();
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/toml/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("prettier-plugin-toml", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down
23 changes: 1 addition & 22 deletions src/embedded/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/embedded/xml/embedder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
preparePlaceholder,
printTemplateExpressions,
simpleRehydrateDoc,
throwIfPluginIsNotFound,
} from "../utils.js";
import { language } from "./language.js";

Expand All @@ -18,8 +17,6 @@ export const embedder: Embedder<Options> = async (
options,
{ commentOrTag, embeddedOverrideOptions },
) => {
throwIfPluginIsNotFound("@prettier/plugin-xml", options, commentOrTag);

const resolvedOptions = {
...options,
...embeddedOverrideOptions,
Expand Down

0 comments on commit 442be39

Please sign in to comment.