diff --git a/.changeset/many-otters-applaud.md b/.changeset/many-otters-applaud.md new file mode 100644 index 0000000..08e44a7 --- /dev/null +++ b/.changeset/many-otters-applaud.md @@ -0,0 +1,7 @@ +--- +"prettier-plugin-embed": patch +--- + +Fix wrong options fallback behaviors: + +- Empty list of tags and comments shouldn't fallback to identifiers in options. diff --git a/src/embedded/css/options.ts b/src/embedded/css/options.ts index 91d39ad..f7568b6 100644 --- a/src/embedded/css/options.ts +++ b/src/embedded/css/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -42,7 +43,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded CSS language.", }, @@ -50,7 +51,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded CSS language.", }, diff --git a/src/embedded/es/options.ts b/src/embedded/es/options.ts index d19a39d..537ef31 100644 --- a/src/embedded/es/options.ts +++ b/src/embedded/es/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -59,7 +60,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.", }, @@ -67,7 +68,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.", }, diff --git a/src/embedded/glsl/options.ts b/src/embedded/glsl/options.ts index 5028652..51882be 100644 --- a/src/embedded/glsl/options.ts +++ b/src/embedded/glsl/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded GLSL language. This option requires the `prettier-plugin-glsl` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded GLSL language. This option requires the `prettier-plugin-glsl` plugin.", }, diff --git a/src/embedded/graphql/options.ts b/src/embedded/graphql/options.ts index 830bba4..d238413 100644 --- a/src/embedded/graphql/options.ts +++ b/src/embedded/graphql/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded GraphQL language.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded GraphQL language.", }, diff --git a/src/embedded/html/options.ts b/src/embedded/html/options.ts index 6060503..e54b488 100644 --- a/src/embedded/html/options.ts +++ b/src/embedded/html/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -42,7 +43,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded HTML language.", }, @@ -50,7 +51,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded HTML language.", }, diff --git a/src/embedded/index.ts b/src/embedded/index.ts index 8ec2a9b..5dada7a 100644 --- a/src/embedded/index.ts +++ b/src/embedded/index.ts @@ -14,5 +14,6 @@ export { makeIdentifiersOptionName, makeCommentsOptionName, makeTagsOptionName, + fallbackIndicator, type AutocompleteStringList, } from "./utils.js"; diff --git a/src/embedded/ini/options.ts b/src/embedded/ini/options.ts index aaa81e4..04cf0b8 100644 --- a/src/embedded/ini/options.ts +++ b/src/embedded/ini/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded INI language. This option requires the `prettier-plugin-ini` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded INI language. This option requires the `prettier-plugin-ini` plugin.", }, diff --git a/src/embedded/java/options.ts b/src/embedded/java/options.ts index 7ce0b76..03909d4 100644 --- a/src/embedded/java/options.ts +++ b/src/embedded/java/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Java language. This option requires the `prettier-plugin-java` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Java language. This option requires the `prettier-plugin-java` plugin.", }, diff --git a/src/embedded/json/options.ts b/src/embedded/json/options.ts index f5cf4a7..dd1ccc5 100644 --- a/src/embedded/json/options.ts +++ b/src/embedded/json/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -43,7 +44,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded JSON language.", }, @@ -51,7 +52,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded JSON language.", }, diff --git a/src/embedded/jsonata/options.ts b/src/embedded/jsonata/options.ts index 5586d68..5a91fad 100644 --- a/src/embedded/jsonata/options.ts +++ b/src/embedded/jsonata/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded JSONata language. This option requires the `@stedi/prettier-plugin-jsonata` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded JSONata language. This option requires the `@stedi/prettier-plugin-jsonata` plugin.", }, diff --git a/src/embedded/latex/options.ts b/src/embedded/latex/options.ts index 3390f80..373c5de 100644 --- a/src/embedded/latex/options.ts +++ b/src/embedded/latex/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -46,7 +47,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded LaTeX language. This option requires the `prettier-plugin-latex` plugin.", }, @@ -54,7 +55,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded LaTeX language. This option requires the `prettier-plugin-latex` plugin.", }, diff --git a/src/embedded/markdown/options.ts b/src/embedded/markdown/options.ts index 76f23d3..e83b93e 100644 --- a/src/embedded/markdown/options.ts +++ b/src/embedded/markdown/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -42,7 +43,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Markdown language.", }, @@ -50,7 +51,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Markdown language.", }, diff --git a/src/embedded/nginx/options.ts b/src/embedded/nginx/options.ts index 7c06612..9ea9ab4 100644 --- a/src/embedded/nginx/options.ts +++ b/src/embedded/nginx/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded NGINX language. This option requires the `prettier-plugin-nginx` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded NGINX language. This option requires the `prettier-plugin-nginx` plugin.", }, diff --git a/src/embedded/noop/options.ts b/src/embedded/noop/options.ts index 26d2978..8b1d38c 100644 --- a/src/embedded/noop/options.ts +++ b/src/embedded/noop/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import type { EmbeddedDefaultComment, EmbeddedDefaultTag } from "../types.js"; import { type AutocompleteStringList, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -31,7 +32,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that prevent their subsequent template literals from being identified as embedded languages and thus from being formatted.", }, @@ -39,7 +40,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that prevent their subsequent template literals from being identified as embedded languages and thus from being formatted.", }, diff --git a/src/embedded/pegjs/options.ts b/src/embedded/pegjs/options.ts index fbc1b82..6e94d3b 100644 --- a/src/embedded/pegjs/options.ts +++ b/src/embedded/pegjs/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Pegjs language. This option requires the `prettier-plugin-pegjs` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Pegjs language. This option requires the `prettier-plugin-pegjs` plugin.", }, diff --git a/src/embedded/php/options.ts b/src/embedded/php/options.ts index c42638d..3c88104 100644 --- a/src/embedded/php/options.ts +++ b/src/embedded/php/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded PHP language. This option requires the `@prettier/plugin-php` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded PHP language. This option requires the `@prettier/plugin-php` plugin.", }, diff --git a/src/embedded/prisma/options.ts b/src/embedded/prisma/options.ts index c9e243a..d7ecb81 100644 --- a/src/embedded/prisma/options.ts +++ b/src/embedded/prisma/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Prisma language. This option requires the `prettier-plugin-prisma` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Prisma language. This option requires the `prettier-plugin-prisma` plugin.", }, diff --git a/src/embedded/properties/options.ts b/src/embedded/properties/options.ts index 527198e..8483b47 100644 --- a/src/embedded/properties/options.ts +++ b/src/embedded/properties/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Properties language. This option requires the `prettier-plugin-properties` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Properties language. This option requires the `prettier-plugin-properties` plugin.", }, diff --git a/src/embedded/pug/options.ts b/src/embedded/pug/options.ts index 0e022a4..980e66f 100644 --- a/src/embedded/pug/options.ts +++ b/src/embedded/pug/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Pug language. This option requires the `@prettier/plugin-pug` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Pug language. This option requires the `@prettier/plugin-pug` plugin.", }, diff --git a/src/embedded/ruby/options.ts b/src/embedded/ruby/options.ts index dce8c1a..9d2fc00 100644 --- a/src/embedded/ruby/options.ts +++ b/src/embedded/ruby/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -42,7 +43,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Ruby language. This option requires the `@prettier/plugin-ruby` plugin.", }, @@ -50,7 +51,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Ruby language. This option requires the `@prettier/plugin-ruby` plugin.", }, diff --git a/src/embedded/sh/options.ts b/src/embedded/sh/options.ts index 0ee7f49..37a7e35 100644 --- a/src/embedded/sh/options.ts +++ b/src/embedded/sh/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded Shell language. This option requires the `prettier-plugin-sh` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded Shell language. This option requires the `prettier-plugin-sh` plugin.", }, diff --git a/src/embedded/sql/options.ts b/src/embedded/sql/options.ts index a4ac52a..a474b28 100644 --- a/src/embedded/sql/options.ts +++ b/src/embedded/sql/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -53,7 +54,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded SQL language. This option requires the `prettier-plugin-sql` plugin or the `prettier-plugin-sql-cst` plugin.", }, @@ -61,7 +62,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded SQL language. This option requires the `prettier-plugin-sql` plugin or the `prettier-plugin-sql-cst` plugin.", }, diff --git a/src/embedded/toml/options.ts b/src/embedded/toml/options.ts index d424c31..4840dc2 100644 --- a/src/embedded/toml/options.ts +++ b/src/embedded/toml/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded TOML language. This option requires the `prettier-plugin-toml` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded TOML language. This option requires the `prettier-plugin-toml` plugin.", }, diff --git a/src/embedded/ts/options.ts b/src/embedded/ts/options.ts index 21a2b23..aeb145d 100644 --- a/src/embedded/ts/options.ts +++ b/src/embedded/ts/options.ts @@ -2,6 +2,7 @@ import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, @@ -49,7 +50,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded TypeScript language.", }, @@ -57,7 +58,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded TypeScript language.", }, diff --git a/src/embedded/utils.ts b/src/embedded/utils.ts index 18ff7a4..77488fc 100644 --- a/src/embedded/utils.ts +++ b/src/embedded/utils.ts @@ -170,3 +170,5 @@ export type NormalizeOptions = OmitIndexSignature<{ ? T[k] : UnionToIntersection[k]; }>; + +export const fallbackIndicator = "9ff2b366e8ca4c97b9aed1a29b5b94ed"; diff --git a/src/embedded/xml/options.ts b/src/embedded/xml/options.ts index 744562c..be488ec 100644 --- a/src/embedded/xml/options.ts +++ b/src/embedded/xml/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded XML language. This option requires the `@prettier/plugin-xml` plugin.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded XML language. This option requires the `@prettier/plugin-xml` plugin.", }, diff --git a/src/embedded/yaml/options.ts b/src/embedded/yaml/options.ts index 8cc146d..c082ea6 100644 --- a/src/embedded/yaml/options.ts +++ b/src/embedded/yaml/options.ts @@ -2,6 +2,7 @@ import type { SupportOptions } from "prettier"; import { type AutocompleteStringList, type StringListToInterfaceKey, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -37,7 +38,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded YAML language.", }, @@ -45,7 +46,7 @@ export const options = { category: "Embed", type: "string", array: true, - default: [{ value: [] }], + default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded YAML language.", }, diff --git a/src/utils.ts b/src/utils.ts index 196d4d3..81f1d37 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -13,6 +13,7 @@ import { type EmbeddedLanguage, type EmbeddedTag, embeddedEmbedders, + fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeTagsOptionName, @@ -324,61 +325,56 @@ export function createCommentsInOptionsGenerator( options: Options, comment: string, ) { - // lazy-evaluated - const isCommentNotExcluded = (() => { - let result: boolean | undefined = undefined; - return () => { - if (result === undefined) { - result = !( - options.noEmbeddedIdentificationByComment?.includes(comment) ?? false - ); - } - return result; - }; - })(); + const isCommentExcluded = + options.noEmbeddedIdentificationByComment?.includes(comment) ?? false; + if (isCommentExcluded) { + return function* ( + _: EmbeddedLanguage, + ): Generator {}; + } return function* (embeddedLanguage: EmbeddedLanguage) { - const commentsInOptions = - options[makeCommentsOptionName(embeddedLanguage)] ?? []; - - // fallback to identifiers if no comments in options - if (commentsInOptions.length === 0 && isCommentNotExcluded()) { + const commentsInOptions = options[ + makeCommentsOptionName(embeddedLanguage) + ] ?? [fallbackIndicator]; + // fallback to identifiers + if (commentsInOptions[0] === fallbackIndicator) { yield* options[makeIdentifiersOptionName(embeddedLanguage)] ?? []; } else { - yield* commentsInOptions; + yield* commentsInOptions ?? []; } }; } export function createTagsInOptionsGenerator(options: Options, tag?: string) { + // simple identifier tag if (typeof tag === "string") { - // lazy-evaluated - const isTagNotExcluded = (() => { - let result: boolean | undefined = undefined; - return () => { - if (result === undefined) { - result = !( - options.noEmbeddedIdentificationByTag?.includes(tag) ?? false - ); - } - return result; - }; - })(); + const isTagExcluded = + options.noEmbeddedIdentificationByTag?.includes(tag) ?? false; + if (isTagExcluded) { + return function* ( + _: EmbeddedLanguage, + ): Generator {}; + } return function* (embeddedLanguage: EmbeddedLanguage) { - const tagsInOptions = options[makeTagsOptionName(embeddedLanguage)] ?? []; - - // fallback to identifiers if no tags in options - if (tagsInOptions.length === 0 && isTagNotExcluded()) { + const tagsInOptions = options[makeTagsOptionName(embeddedLanguage)] ?? [ + fallbackIndicator, + ]; + // fallback to identifiers + if (tagsInOptions[0] === fallbackIndicator) { yield* options[makeIdentifiersOptionName(embeddedLanguage)] ?? []; } else { - yield* tagsInOptions; + yield* tagsInOptions ?? []; } }; } + // complex expression tag return function* (embeddedLanguage: EmbeddedLanguage) { - const tagsInOptions = options[makeTagsOptionName(embeddedLanguage)] ?? []; + const tagsInOptions = options[makeTagsOptionName(embeddedLanguage)] ?? [ + fallbackIndicator, + ]; - // fallback to identifiers if no tags in options - if (tagsInOptions.length === 0) { + // fallback to identifiers + if (tagsInOptions[0] === fallbackIndicator) { const { noEmbeddedIdentificationByTag } = options; for (const identifier of options[ makeIdentifiersOptionName(embeddedLanguage)