prettier-plugin-embed 0.2.5 → 0.3.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  <div align="center">
2
2
 
3
- ![prettier-plugin-embed-light](./public/prettier-plugin-embed-wide-light.svg)
3
+ ![prettier-plugin-embed-light](./asset/prettier-plugin-embed-wide-light.svg)
4
4
 
5
5
  # Prettier Plugin Embed
6
6
 
7
- [![npm](https://img.shields.io/npm/v/prettier-plugin-embed)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/prettier-plugin-embed)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![jsDelivr hits (npm scoped)](https://img.shields.io/jsdelivr/npm/hm/prettier-plugin-embed?color=%23ff5627)](https://cdn.jsdelivr.net/npm/prettier-plugin-embed@latest/)
7
+ [![npm version](https://badgen.net/npm/v/prettier-plugin-embed?cache=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![npm downloads](https://badgen.net/npm/dm/prettier-plugin-embed?cache=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest) [![npm license](https://badgen.net/npm/license/prettier-plugin-embed?cache=300)](https://www.npmjs.com/package/prettier-plugin-embed/v/latest)
8
+
9
+ [![github last commit](https://badgen.net/github/last-commit/Sec-ant/prettier-plugin-embed?cache=300)](https://github.com/Sec-ant/prettier-plugin-embed) [![bundlephobia minzipped](https://badgen.net/bundlephobia/minzip/prettier-plugin-embed?cache=300)](https://bundlephobia.com/package/prettier-plugin-embed@latest) [![](https://data.jsdelivr.com/v1/package/npm/prettier-plugin-embed/badge?style=rounded)](https://www.jsdelivr.com/package/npm/prettier-plugin-embed)
8
10
 
9
11
  A Configurable [Prettier](https://prettier.io/) [Plugin](https://prettier.io/docs/en/plugins.html) to Format [Embedded Languages](https://prettier.io/docs/en/options.html#embedded-language-formatting) in `js`/`ts` Files.
10
12
 
@@ -181,7 +183,7 @@ Formatting embedded Ruby code requires [`@prettier/plugin-ruby`](https://github.
181
183
 
182
184
  Formatting embedded SQL code requires [`prettier-plugin-sql`](https://github.com/un-ts/prettier/tree/master/packages/sql#readme) to be loaded as well. And [options](https://github.com/un-ts/prettier/tree/master/packages/sql#parser-options) supported by `prettier-plugin-sql` can therefore be used to further control the formatting behavior.
183
185
 
184
- Note that `prettier-plugin-sql` supports many different SQL dialects, and there's a one-to-one correspondence between the dialects and the identifiers. To support custom identifiers for a specific dialect, put the identifiers after that specific dialect in the identifier list in option `embeddedSqlIdentifiers`.
186
+ Note that `prettier-plugin-sql` supports many different SQL dialects, and there's a one-to-one correspondence between the dialects and the identifiers. To support custom identifiers for a specific dialect, put the identifiers after that specific dialect in the identifier list in option `embeddedSqlIdentifiers`, or use [`embeddedOverrides`](#embeddedoverrides).
185
187
 
186
188
  #### TS
187
189
 
@@ -204,12 +206,42 @@ Formatting embedded XML code requires [`@prettier/plugin-xml`](https://github.co
204
206
 
205
207
  ### Language-Agnostic Options
206
208
 
207
- | Option | Default | Description |
208
- | :-----------------------------------: | :-----: | ------------------------------------------------------------------------------------------------------------------------------ |
209
- | `noEmbeddedIdentificationByComment` | `[]` | Turns off `` /* identifier */ `...` `` comment-based language identification for the specified identifiers |
210
- | `noEmbeddedIdentificationByTag` | `[]` | Turns off `` identifier`...` `` tag-based language identification for the specified identifiers |
211
- | `preserveEmbeddedExteriorWhitespaces` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers |
212
- | `noEmbeddedMultiLineIndentation` | `[]` | Turns off auto indentation in the formatting results when they are formatted to span multi lines for the specified identifiers |
209
+ | Option | Default | Description |
210
+ | :-----------------------------------: | :---------: | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
211
+ | `noEmbeddedIdentificationByComment` | `[]` | Turns off `` /* identifier */ `...` `` comment-based language identification for the specified identifiers |
212
+ | `noEmbeddedIdentificationByTag` | `[]` | Turns off `` identifier`...` `` tag-based language identification for the specified identifiers |
213
+ | `preserveEmbeddedExteriorWhitespaces` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers |
214
+ | `noEmbeddedMultiLineIndentation` | `[]` | Turns off auto indentation in the formatting results when they are formatted to span multi lines for the specified identifiers |
215
+ | `embeddedOverrides` | `undefined` | Option overrides for the specified identifiers. This option accepts a string if not undefined. See [below](#embeddedoverrides) for a detailed explanation |
216
+
217
+ #### `embeddedOverrides`
218
+
219
+ This option is provided for users to override certain options based on identifiers. Due to the lack of support for using objects in prettier plugin options (https://github.com/prettier/prettier/issues/14671), it accepts a **stringified** json string, or a file path with an extension of `.json` or `.js` or `.cjs` or `.mjs` as its value. If no extension is provided, it will be treated as a `.json` file. For relative paths, it will automatically figure out the prettier config location and use that as the base path.
220
+
221
+ The resolved value should be an array of objects. Each object in the array must have 2 fields: `identifiers` and `options`. The `options` are considerred overrides that will be applied to the global `options` of prettier for those `idenfitiers` only. It's like the [`overrides`](https://prettier.io/docs/en/configuration.html#configuration-overrides) of `prettier`, but it is identifier-based instead of file-based.
222
+
223
+ In a json file, the root is the array of objects. In a javascript file, the array of objects should be a default export, or a named export with the name `embeddedOverrides`.
224
+
225
+ An example `.json` file is:
226
+
227
+ ```json
228
+ [
229
+ {
230
+ "identifiers": ["sql"],
231
+ "options": {
232
+ "keywordCase": "lower"
233
+ }
234
+ },
235
+ {
236
+ "identifiers": ["mysql"],
237
+ "options": {
238
+ "keywordCase": "upper"
239
+ }
240
+ }
241
+ ]
242
+ ```
243
+
244
+ Please note that not every option is supported to override. That largely depends on at which phase those options will kick in and take effect. For example, you can't override `tabWidth` in `embeddedOverrides` because this option is used in the [`printDocToString`](https://github.com/prettier/prettier/blob/7aecca5d6473d73f562ca3af874831315f8f2581/src/document/printer.js#L302) phase, where `prettier-plugin-embed` cannot override this option for only a set of specified identifiers. To find the list of unsupported options, please check the interface definition of `EmbeddedOverride` in the [source code](https://github.com/Sec-ant/prettier-plugin-embed/blob/main/src/types.ts).
213
245
 
214
246
  ## Demos
215
247
 
@@ -1,4 +1,4 @@
1
- import { type Options } from "prettier";
1
+ import type { Options } from "prettier";
2
2
  import type { Embedder } from "../../types.js";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const embedder: Embedder<Options>;
@@ -1,4 +1,4 @@
1
- import { type Options } from "prettier";
1
+ import type { Options } from "prettier";
2
2
  import type { Embedder } from "../../types.js";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const embedder: Embedder<Options>;
@@ -1,4 +1,4 @@
1
- import { type Options } from "prettier";
1
+ import type { Options } from "prettier";
2
2
  import type { Embedder } from "../../types.js";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const embedder: Embedder<Options>;
@@ -1,3 +1,3 @@
1
1
  export * from "./register.js";
2
- export type { EmbeddedLanguage, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, EmbeddedDefaultIdentifier, PrettierPluginEmbedOptions, } from "./types.js";
2
+ export type { EmbeddedDefaultIdentifier, EmbeddedEmbedders, EmbeddedLanguage, EmbeddedOptions, EmbeddedParsers, PrettierPluginEmbedOptions, } from "./types.js";
3
3
  export { makeIdentifiersOptionName, type AutocompleteStringList, } from "./utils.js";
@@ -1,5 +1,5 @@
1
- import { type AutocompleteStringList } from "../utils.js";
2
1
  import type { EmbeddedDefaultIdentifier } from "../types.js";
2
+ import { type AutocompleteStringList } from "../utils.js";
3
3
  type EmbeddedIdentifiers = AutocompleteStringList<EmbeddedDefaultIdentifier[]>;
4
4
  declare const embeddedLanguageIdentifiers: "embeddedNoopIdentifiers";
5
5
  export declare const options: {
@@ -1,15 +1,15 @@
1
- import type { EmbeddedEmbedders, EmbeddedLanguage, EmbeddedParsers, EmbeddedOptions } from "./types.js";
1
+ import type { EmbeddedEmbedders, EmbeddedLanguage, EmbeddedOptions, EmbeddedParsers } from "./types.js";
2
2
  export declare const embeddedLanguages: EmbeddedLanguage[];
3
3
  export declare const embeddedParsers: EmbeddedParsers;
4
4
  export declare const embeddedEmbedders: EmbeddedEmbedders;
5
5
  export declare const embeddedOptions: EmbeddedOptions;
6
6
  import * as __glob__0_0 from "./css/index.js";
7
- import * as __glob__0_1 from "./es/index.js";
8
- import * as __glob__0_2 from "./html/index.js";
9
- import * as __glob__0_3 from "./glsl/index.js";
10
- import * as __glob__0_4 from "./markdown/index.js";
11
- import * as __glob__0_5 from "./php/index.js";
12
- import * as __glob__0_6 from "./noop/index.js";
7
+ import * as __glob__0_1 from "./glsl/index.js";
8
+ import * as __glob__0_2 from "./markdown/index.js";
9
+ import * as __glob__0_3 from "./noop/index.js";
10
+ import * as __glob__0_4 from "./es/index.js";
11
+ import * as __glob__0_5 from "./html/index.js";
12
+ import * as __glob__0_6 from "./php/index.js";
13
13
  import * as __glob__0_7 from "./ruby/index.js";
14
14
  import * as __glob__0_8 from "./sql/index.js";
15
15
  import * as __glob__0_9 from "./ts/index.js";
@@ -1,10 +1,10 @@
1
1
  import type { SqlBaseOptions as PrettierPluginDepsOptions } from "prettier-plugin-sql";
2
2
  import { type AutocompleteStringList, type StringListToInterfaceKey } from "../utils.js";
3
3
  /** References
4
- * - https://github.com/un-ts/prettier/blob/214a5ff53c2485aabc6e78e1c346b69b712bee42/packages/sql/src/index.ts
4
+ * - https://github.com/un-ts/prettier/blob/a5f1aae6464aa54749377d69a8237a70a6509a13/packages/sql/src/index.ts
5
5
  */
6
- export declare const SQL_FORMATTER_LANGUAGES: readonly ["sql", "bigquery", "hive", "mariadb", "mysql", "postgresql", "db2", "plsql", "n1ql", "redshift", "singlestoredb", "spark", "sqlite", "transactsql", "tsql", "trino"];
7
- export declare const NODE_SQL_PARSER_DATABASES: readonly ["bigquery", "db2", "hive", "mariadb", "mysql", "postgresql", "transactsql", "flinksql"];
6
+ export declare const SQL_FORMATTER_LANGUAGES: readonly ["sql", "bigquery", "db2", "db2i", "hive", "mariadb", "mysql", "n1ql", "postgresql", "plsql", "redshift", "singlestoredb", "snowflake", "spark", "sqlite", "transactsql", "tsql", "trino"];
7
+ export declare const NODE_SQL_PARSER_DATABASES: readonly ["bigquery", "db2", "hive", "mariadb", "mysql", "postgresql", "transactsql", "flinksql", "snowflake"];
8
8
  type Identifiers = AutocompleteStringList<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
9
9
  type DefaultIdentifiersHolder = StringListToInterfaceKey<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
10
10
  export type SqlFormatterLanguage = (typeof SQL_FORMATTER_LANGUAGES)[number];
@@ -17,7 +17,7 @@ export declare const options: {
17
17
  type: "string";
18
18
  array: true;
19
19
  default: {
20
- value: ("sql" | "bigquery" | "hive" | "mariadb" | "mysql" | "postgresql" | "db2" | "plsql" | "n1ql" | "redshift" | "singlestoredb" | "spark" | "sqlite" | "transactsql" | "tsql" | "trino")[];
20
+ value: string[];
21
21
  }[];
22
22
  description: string;
23
23
  };
@@ -1,4 +1,4 @@
1
- import { type Options } from "prettier";
1
+ import type { Options } from "prettier";
2
2
  import type { Embedder } from "../../types.js";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const embedder: Embedder<Options>;
@@ -1,4 +1,4 @@
1
- import type { Parser, SupportOption, Options } from "prettier";
1
+ import type { Options, Parser, SupportOption } from "prettier";
2
2
  import type { Embedder } from "../types.js";
3
3
  import type { Satisfies } from "./utils.js";
4
4
  type EmbeddedLanguageNamingConvention = `embedded${Capitalize<string>}`;
@@ -16,8 +16,4 @@ export interface EmbeddedDefaultIdentifiersHolder {
16
16
  export type EmbeddedDefaultIdentifier = keyof EmbeddedDefaultIdentifiersHolder;
17
17
  export interface PrettierPluginEmbedOptions {
18
18
  }
19
- declare module "prettier" {
20
- interface Options extends PrettierPluginEmbedOptions {
21
- }
22
- }
23
19
  export {};
@@ -1,5 +1,5 @@
1
- import type { Expression, Comment, TemplateLiteral } from "estree";
2
- import type { AstPath, Options, Doc } from "prettier";
1
+ import type { Comment, Expression, TemplateLiteral } from "estree";
2
+ import type { AstPath, Doc, Options } from "prettier";
3
3
  import { builders } from "prettier/doc";
4
4
  import type { InternalPrintFun } from "../types.js";
5
5
  export declare function printTemplateExpression(path: AstPath<Expression & {
@@ -9,7 +9,7 @@ export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>,
9
9
  export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[]): builders.Doc[] | builders.DocCommand;
10
10
  export declare function throwIfPluginIsNotFound(pluginName: string, options: Options, identifier: string): void;
11
11
  export declare function insertEmbeddedLanguage(embeddedLanguages: string[], embeddedLanguage: string, firstEmbeddedLanguage: string): void;
12
- export declare const randomUUID: (uuidLength?: number | undefined) => string;
12
+ export declare const randomUUID: () => string;
13
13
  export declare function preparePlaceholder(leading?: string, trailing?: string): {
14
14
  createPlaceholder: (index: number) => string;
15
15
  placeholderRegex: RegExp;
@@ -1,4 +1,4 @@
1
- import { type Options } from "prettier";
1
+ import type { Options } from "prettier";
2
2
  import type { Embedder } from "../../types.js";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const embedder: Embedder<Options>;
@@ -1,4 +1,4 @@
1
1
  export * from "./embedded-language.js";
2
- export * from "./parser.js";
3
2
  export * from "./embedder.js";
4
3
  export * from "./options.js";
4
+ export * from "./parser.js";
@@ -1,5 +1,5 @@
1
- import type { Parser } from "prettier";
2
1
  import type { CstNode } from "chevrotain";
2
+ import type { Parser } from "prettier";
3
3
  import { embeddedLanguage } from "./embedded-language.js";
4
4
  export declare const parser: Parser<CstNode>;
5
5
  declare module "../types.js" {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
+ export * from "./embedded/index.js";
2
+ export { options } from "./options.js";
1
3
  export { parsers } from "./parsers.js";
2
4
  export { printers } from "./printers.js";
3
- export { options } from "./options.js";
4
5
  export type * from "./types.js";
5
- export * from "./embedded/index.js";