prettier-plugin-embed 0.2.4 → 0.3.0-rc.0
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 +47 -7
- package/dist/embedded/index.d.ts +1 -1
- package/dist/embedded/register.d.ts +2 -2
- package/dist/embedded/sql/options.d.ts +4 -4
- package/dist/embedded/types.d.ts +0 -4
- package/dist/embedded/utils.d.ts +2 -1
- package/dist/index.js +813 -836
- package/dist/options.d.ts +17 -6
- package/dist/types.d.ts +7 -0
- package/package.json +21 -21
package/README.md
CHANGED
|
@@ -50,6 +50,20 @@ By leveraging Prettier's plugin system, this plugin overrides the default [`embe
|
|
|
50
50
|
npm i -D prettier-plugin-embed
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Peer dependecies are automatically installed by default if you're using npm v7 or higher versions. The peer dependencies of this plugin are mainly packages to support parsing and formatting for different languages. If you only plan to use this plugin for a very specific language and don't want to bloat your node modules folder, you can omit the peer dependencies by changing the installation command to either:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm i -D --legacy-peer-deps prettier-plugin-embed
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
or:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm i -D --omit=peer prettier-plugin-embed
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For other package managers, refer to their documents on how to achieve the same result.
|
|
66
|
+
|
|
53
67
|
## Usage
|
|
54
68
|
|
|
55
69
|
### Getting Started
|
|
@@ -167,7 +181,7 @@ Formatting embedded Ruby code requires [`@prettier/plugin-ruby`](https://github.
|
|
|
167
181
|
|
|
168
182
|
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.
|
|
169
183
|
|
|
170
|
-
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
|
|
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`, or use [`embeddedOverrides`](#embeddedoverrides).
|
|
171
185
|
|
|
172
186
|
#### TS
|
|
173
187
|
|
|
@@ -190,12 +204,38 @@ Formatting embedded XML code requires [`@prettier/plugin-xml`](https://github.co
|
|
|
190
204
|
|
|
191
205
|
### Language-Agnostic Options
|
|
192
206
|
|
|
193
|
-
| Option |
|
|
194
|
-
| :-----------------------------------: |
|
|
195
|
-
| `noEmbeddedIdentificationByComment` |
|
|
196
|
-
| `noEmbeddedIdentificationByTag` |
|
|
197
|
-
| `preserveEmbeddedExteriorWhitespaces` |
|
|
198
|
-
| `noEmbeddedMultiLineIndentation` |
|
|
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 |
|
|
213
|
+
| `embeddedOverrides` | `undefined` | Option overrides for the specified identifiers. This option accepts a string if not undefined. See [below](#embeddedoverrides) for a detailed explanation |
|
|
214
|
+
|
|
215
|
+
#### `embeddedOverrides`
|
|
216
|
+
|
|
217
|
+
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 an **absolute** json file path as its value.
|
|
218
|
+
|
|
219
|
+
The value should be an array of objects. Each object 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. An example is:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
[
|
|
223
|
+
{
|
|
224
|
+
"identifiers": ["sql"],
|
|
225
|
+
"options": {
|
|
226
|
+
"keywordCase": "lower"
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"identifiers": ["mysql"],
|
|
231
|
+
"options": {
|
|
232
|
+
"keywordCase": "upper"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
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).
|
|
199
239
|
|
|
200
240
|
## Demos
|
|
201
241
|
|
package/dist/embedded/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from "./register.js";
|
|
2
2
|
export type { EmbeddedLanguage, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, EmbeddedDefaultIdentifier, PrettierPluginEmbedOptions, } from "./types.js";
|
|
3
|
-
export { makeIdentifiersOptionName
|
|
3
|
+
export { makeIdentifiersOptionName, type AutocompleteStringList, } from "./utils.js";
|
|
@@ -4,9 +4,9 @@ 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 "./
|
|
7
|
+
import * as __glob__0_1 from "./es/index.js";
|
|
8
8
|
import * as __glob__0_2 from "./glsl/index.js";
|
|
9
|
-
import * as __glob__0_3 from "./
|
|
9
|
+
import * as __glob__0_3 from "./html/index.js";
|
|
10
10
|
import * as __glob__0_4 from "./markdown/index.js";
|
|
11
11
|
import * as __glob__0_5 from "./noop/index.js";
|
|
12
12
|
import * as __glob__0_6 from "./php/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/
|
|
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", "
|
|
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:
|
|
20
|
+
value: string[];
|
|
21
21
|
}[];
|
|
22
22
|
description: string;
|
|
23
23
|
};
|
package/dist/embedded/types.d.ts
CHANGED
|
@@ -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 {};
|
package/dist/embedded/utils.d.ts
CHANGED
|
@@ -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: (
|
|
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;
|
|
@@ -22,3 +22,4 @@ export type StringListToInterfaceKey<T extends readonly string[]> = {
|
|
|
22
22
|
[key in T[number]]: void;
|
|
23
23
|
};
|
|
24
24
|
export type Satisfies<U, T extends U> = T;
|
|
25
|
+
export declare const parseEmbeddedOverrideOptions: import("micro-memoize").Memoized<(embeddedOverrides: string | undefined, identifier: string) => Omit<Omit<Options, keyof import("./types.js").PrettierPluginEmbedOptions> & Omit<import("./types.js").PrettierPluginEmbedOptions, "embeddedNoopIdentifiers" | "embeddedCssIdentifiers" | "embeddedEsIdentifiers" | "embeddedGlslIdentifiers" | "embeddedHtmlIdentifiers" | "embeddedMarkdownIdentifiers" | "embeddedPhpIdentifiers" | "embeddedRubyIdentifiers" | "embeddedSqlIdentifiers" | "embeddedTsIdentifiers" | "embeddedXmlIdentifiers" | keyof import("../options.js").PrettierPluginGlobalOptions>, "parser" | "filepath" | "endOfLine" | "embeddedLanguageFormatting" | "printWidth" | "tabWidth" | "useTabs" | `__${string}`> | undefined>;
|