prettier-plugin-embed 0.0.6 → 0.1.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 +183 -3
- package/dist/embedded/es/embedded-language.d.ts +6 -0
- package/dist/embedded/es/embedder.d.ts +9 -0
- package/dist/embedded/es/index.d.ts +3 -0
- package/dist/embedded/es/options.d.ts +44 -0
- package/dist/embedded/html/embedded-language.d.ts +6 -0
- package/dist/embedded/html/embedder.d.ts +9 -0
- package/dist/embedded/html/index.d.ts +3 -0
- package/dist/embedded/html/options.d.ts +33 -0
- package/dist/embedded/index.d.ts +1 -1
- package/dist/embedded/noop/embedded-language.d.ts +6 -0
- package/dist/embedded/noop/index.d.ts +2 -2
- package/dist/embedded/noop/options.d.ts +21 -0
- package/dist/embedded/php/embedded-language.d.ts +6 -0
- package/dist/embedded/php/embedder.d.ts +2 -2
- package/dist/embedded/php/index.d.ts +2 -2
- package/dist/embedded/php/options.d.ts +36 -0
- package/dist/embedded/register.d.ts +9 -6
- package/dist/embedded/sql/embedded-language.d.ts +6 -0
- package/dist/embedded/sql/embedder.d.ts +2 -2
- package/dist/embedded/sql/index.d.ts +2 -2
- package/dist/embedded/sql/options.d.ts +35 -0
- package/dist/embedded/ts/embedded-language.d.ts +6 -0
- package/dist/embedded/ts/embedder.d.ts +9 -0
- package/dist/embedded/ts/index.d.ts +3 -0
- package/dist/embedded/ts/options.d.ts +44 -0
- package/dist/embedded/types.d.ts +10 -9
- package/dist/embedded/utils.d.ts +15 -4
- package/dist/embedded/xml/embedded-language.d.ts +6 -0
- package/dist/embedded/xml/embedder.d.ts +3 -3
- package/dist/embedded/xml/index.d.ts +2 -2
- package/dist/embedded/xml/options.d.ts +47 -0
- package/dist/embedded/xml/parser.d.ts +3 -5
- package/dist/index.js +901 -338
- package/dist/options.d.ts +135 -5
- package/dist/prettier-plugin-embed-wide-dark.svg +309 -0
- package/dist/prettier-plugin-embed-wide-light.svg +309 -0
- package/dist/types.d.ts +1 -1
- package/package.json +17 -13
- package/dist/embedded/noop/name.d.ts +0 -6
- package/dist/embedded/noop/option.d.ts +0 -11
- package/dist/embedded/php/name.d.ts +0 -6
- package/dist/embedded/php/option.d.ts +0 -20
- package/dist/embedded/sql/name.d.ts +0 -6
- package/dist/embedded/sql/option.d.ts +0 -21
- package/dist/embedded/xml/name.d.ts +0 -6
- package/dist/embedded/xml/option.d.ts +0 -21
package/README.md
CHANGED
|
@@ -1,5 +1,185 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
# Prettier Plugin Embed
|
|
7
|
+
|
|
8
|
+
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.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i -D prettier-plugin-embed
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## Introduction
|
|
17
|
+
|
|
18
|
+
### What?
|
|
19
|
+
|
|
20
|
+
This Prettier plugin (namely [`prettier-plugin-embed`](https://github.com/Sec-ant/prettier-plugin-embed)) provides a configurable solution for formatting embedded languages in the form of [template literals](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Template_literals) within JavaScript or TypeScript files.
|
|
21
|
+
|
|
22
|
+
### Why?
|
|
23
|
+
|
|
24
|
+
Although Prettier has introduced the [`embedded-language-formatting`](https://prettier.io/docs/en/options.html#embedded-language-formatting) option for formatting embedded languages, it only supports two modes: `auto` and `off`. Therefore it doesn't allow for individual formatting adjustments for specific languages, nor does it support customizing the languages that require formatting and identifiers for identification. These limitations restrict the usability of this feature. For more detailed discussions, refer to: https://github.com/prettier/prettier/issues/4424 and https://github.com/prettier/prettier/issues/5588.
|
|
25
|
+
|
|
26
|
+
### How?
|
|
27
|
+
|
|
28
|
+
By leveraging Prettier's plugin system, this plugin overrides the default [`embed`](https://prettier.io/docs/en/plugins#optional-embed) function of the `estree` printer, so varieties of new languages can be hooked in through this function. Check [this file](./src/printers.ts) to get an idea of how this is accomplished.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Support for Additional Languages:** Extend the embedded language formatting capability to include languages such as XML, SQL, PHP, and more.
|
|
33
|
+
|
|
34
|
+
- **Dual Identification Modes:** Identify embedded languages by tags `` identifier`...` `` or comments `` /* identifier */ `...` `` preceding the template literals.
|
|
35
|
+
|
|
36
|
+
- **Customizable Language Identifiers:** Customize the identifiers used for identifying the embedded languages.
|
|
37
|
+
|
|
38
|
+
- **Formatting Opt-out Mechanism:** Offer the capability to deactivate formatting for certain identifiers, including the default ones (`html`, `css`...) supported by the `embedded-language-formatting` option.
|
|
39
|
+
|
|
40
|
+
- **Configurable Formatting Style:** Provide additional options to tailor the formatting style for embedded languages.
|
|
41
|
+
|
|
42
|
+
- **Strongly Typed API:** Benefit from comprehensive type support for configuring this plugin's options when employing the [Prettier API](https://prettier.io/docs/en/api) in TypeScript.
|
|
43
|
+
|
|
44
|
+
- **Easy Integration:** Integrate with the existing Prettier setup seamlessly, requiring minimal configuration to get started.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm i -D prettier-plugin-embed
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Getting Started
|
|
55
|
+
|
|
56
|
+
This is a Prettier plugin, which follows the [standard usage pattern](https://prettier.io/docs/en/plugins.html#using-plugins) of many other Prettier plugins:
|
|
57
|
+
|
|
58
|
+
#### [CLI](https://prettier.io/docs/en/cli):
|
|
59
|
+
|
|
60
|
+
Via `--plugin`:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
prettier --write main.ts --plugin=prettier-plugin-embed
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### [API](https://prettier.io/docs/en/api):
|
|
67
|
+
|
|
68
|
+
Via the `plugins` options:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
await prettier.format(code, {
|
|
72
|
+
filepath: "main.ts",
|
|
73
|
+
plugins: ["prettier-plugin-embed"],
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### [Configuration File](https://prettier.io/docs/en/configuration):
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"plugins": ["prettier-plugin-embed"]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### An Overview of the Philosophy
|
|
86
|
+
|
|
87
|
+
To use this plugin, `embedded-language-formatting` option must be set to `auto` (which is the default setting as of now), because this option serves as the main switch for activating embedded language formatting.
|
|
88
|
+
|
|
89
|
+
This plugin does not aim to implement parsers or printers to support every newly added embedded language. Instead, ideally, it makes use of existing [Prettier plugins](https://prettier.io/docs/en/plugins.html#official-plugins) for those languages and only adds formatting support when they are embedded.
|
|
90
|
+
|
|
91
|
+
Therefore, to enable formatting for a specific embedded language, the corresponding Prettier plugin for that language must also be loaded. For example, if you wish to format embedded XML code, you will need to load both this plugin and [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml). To find out which other plugins are required when using this plugin, please refer to the [Language-Specific Options](#language-specific-options) section below.
|
|
92
|
+
|
|
93
|
+
Embedded languages to be formatted are required to be enclosed in the template literals, and are identified by the preceding [tags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) `` identifier`...` `` or block comments `` /* identifier */ `...` ``. This plugin comes pre-configured with a built-in set of identifiers for identifying various embedded languages. For instance, using identifiers like `xml` or `svg` will trigger automatic formatting for the embedded XML code. You can specify an alternative list of identifiers using the `embeddedXML` option. The naming convention for these options follows the pattern of `embedded{CapitalizedLanguageName}` for other languages as well. Further details on these options and how to configure them are also available in the [Language-Specific Options](#language-specific-options) section.
|
|
94
|
+
|
|
95
|
+
To exclude certain identifiers from being identified, including the default ones supported by the `embedded-language-formatting` option, add them to the list of the `embeddedNoop` option. Any matching identifiers listed in this option will take precedence over other `embedded{CapitalizedLanguageName}` options, effectively disabling their formatting.
|
|
96
|
+
|
|
97
|
+
### Language-Specific Options
|
|
98
|
+
|
|
99
|
+
<details>
|
|
100
|
+
<summary>
|
|
101
|
+
Click Here
|
|
102
|
+
</summary>
|
|
103
|
+
|
|
104
|
+
#### NOOP
|
|
105
|
+
|
|
106
|
+
| Option | Default | Description |
|
|
107
|
+
| :------------: | :-----: | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
108
|
+
| `embeddedNoop` | `[]` | Tag or comment identifiers that prevent their subsequent template literals from being identified as embedded languages and from being formatted |
|
|
109
|
+
|
|
110
|
+
This doesn't require other plugins and can override the native embedded language formatting for ECMAScript code. It serves as a way to turn off embedded language formatting for specific language identifiers.
|
|
111
|
+
|
|
112
|
+
#### ES
|
|
113
|
+
|
|
114
|
+
| Option | Default | Description |
|
|
115
|
+
| :----------------: | :---------------------------------------: | --------------------------------------------------------------------------------------------------------------------- |
|
|
116
|
+
| `embeddedEs` | [`[...]`](./src/embedded/es/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as ECMAScript (JavaScript) code |
|
|
117
|
+
| `embeddedEsParser` | [`"babel"`](./src/embedded/es/options.ts) | The parser used to parse the ECMASCript (JavaScript) code |
|
|
118
|
+
|
|
119
|
+
Formatting embedded ECMAScript code doesn't require other plugins and uses the parsers and printers provided by Prettier natively. This can override the native embedded language formatting for ECMAScript code.
|
|
120
|
+
|
|
121
|
+
#### HTML
|
|
122
|
+
|
|
123
|
+
| Option | Default | Description |
|
|
124
|
+
| :------------: | :---------------------------------------: | --------------------------------------------------------------------------------------------------------------------- |
|
|
125
|
+
| `embeddedHtml` | [`[...]`](./src/embedded/html/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as ECMAScript (JavaScript) code |
|
|
126
|
+
|
|
127
|
+
Formatting embedded HTML code doesn't require other plugins and uses the parsers and printers provided by Prettier natively. This can override the native embedded language formatting for HTML code.
|
|
128
|
+
|
|
129
|
+
#### PHP
|
|
130
|
+
|
|
131
|
+
| Option | Default | Description |
|
|
132
|
+
| :-----------: | :--------------------------------------: | ------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `embeddedPhp` | [`[...]`](./src/embedded/php/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as PHP code |
|
|
134
|
+
|
|
135
|
+
Formatting embedded PHP code requires [`@prettier/plugin-php`](https://github.com/prettier/plugin-php) to be loaded as well. And [options](https://github.com/prettier/plugin-php#configuration) supported by `@prettier/plugin-php` can therefore be used to further control the formatting behavior.
|
|
136
|
+
|
|
137
|
+
#### SQL
|
|
138
|
+
|
|
139
|
+
| Option | Default | Description |
|
|
140
|
+
| :-----------: | :--------------------------------------: | ------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| `embeddedSql` | [`[...]`](./src/embedded/sql/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as SQL code |
|
|
142
|
+
|
|
143
|
+
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.
|
|
144
|
+
|
|
145
|
+
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 `embeddedSql`.
|
|
146
|
+
|
|
147
|
+
#### TS
|
|
148
|
+
|
|
149
|
+
| Option | Default | Description |
|
|
150
|
+
| :----------------: | :--------------------------------------------: | -------------------------------------------------------------------------------------------------------- |
|
|
151
|
+
| `embeddedTs` | [`[...]`](./src/embedded/ts/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as TypeScript code |
|
|
152
|
+
| `embeddedTsParser` | [`"typescript"`](./src/embedded/ts/options.ts) | The parser used to parse the TypeScript code |
|
|
153
|
+
|
|
154
|
+
Formatting embedded TypeScript code doesn't require other plugins and uses the parsers and printers provided by Prettier natively. This can override the native embedded language formatting for TypeScript code.
|
|
155
|
+
|
|
156
|
+
#### XML
|
|
157
|
+
|
|
158
|
+
| Option | Default | Description |
|
|
159
|
+
| :-----------: | :--------------------------------------: | ------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| `embeddedXml` | [`[...]`](./src/embedded/xml/options.ts) | Tag or comment identifiers that make their subsequent template literals be identified as XML code |
|
|
161
|
+
|
|
162
|
+
Formatting embedded XML code requires [`@prettier/plugin-xml`](https://github.com/prettier/plugin-xml) to be loaded as well. And [options](https://github.com/prettier/plugin-xml#configuration) supported by `@prettier/plugin-xml` can therefore be used to further control the formatting behavior.
|
|
163
|
+
|
|
164
|
+
</details>
|
|
165
|
+
|
|
166
|
+
### Language-Agnostic Options
|
|
167
|
+
|
|
168
|
+
| Option | Default | Description |
|
|
169
|
+
| :-----------------------------------: | :-----: | ------------------------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| `noEmbeddedIdentificationByComment` | `[]` | Turns off `` /* identifier */ `...` `` comment-based language identification for the specified identifiers |
|
|
171
|
+
| `noEmbeddedIdentificationByTag` | `[]` | Turns off `` identifier`...` `` tag-based language identification for the specified identifiers |
|
|
172
|
+
| `preserveEmbeddedExteriorWhitespaces` | `[]` | Preserves leading and trailing whitespaces in the formatting results for the specified identifiers |
|
|
173
|
+
| `noEmbeddedMultiLineIndentation` | `[]` | Tsurns off auto indentation in the formatting results for the specified identifiers when they are formatted to span multi lines |
|
|
174
|
+
|
|
175
|
+
## Demos
|
|
176
|
+
|
|
177
|
+
TBD.
|
|
178
|
+
|
|
179
|
+
## Contributing
|
|
180
|
+
|
|
181
|
+
To add support for new languages, create a new directory named after the language within the [`src/embedded`](./src/embedded) directory. Then, export the required variables in the `index.ts` file. Check the existing directories for guidance.
|
|
182
|
+
|
|
183
|
+
## License
|
|
184
|
+
|
|
185
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Options } from "prettier";
|
|
2
|
+
import type { Embedder } from "../../types.js";
|
|
3
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
4
|
+
export declare const embedder: Embedder<Options>;
|
|
5
|
+
declare module "../types.js" {
|
|
6
|
+
interface EmbeddedEmbedders {
|
|
7
|
+
[embeddedLanguage]: typeof embedder;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
2
|
+
import type { MakeIdentifiersType, MakeIdentifiersHolderType } from "../utils.js";
|
|
3
|
+
declare const DEFAULT_IDENTIFIERS: readonly ["js", "es", "es6", "mjs", "cjs", "pac", "javascript"];
|
|
4
|
+
type Identifiers = MakeIdentifiersType<typeof DEFAULT_IDENTIFIERS>;
|
|
5
|
+
type DefaultIdentifiersHolder = MakeIdentifiersHolderType<typeof DEFAULT_IDENTIFIERS>;
|
|
6
|
+
declare const DEFAULT_ES_PARSERS: readonly ["babel", "babel-flow", "acorn", "espree", "flow", "meriyah"];
|
|
7
|
+
type EsParser = (typeof DEFAULT_ES_PARSERS)[number];
|
|
8
|
+
declare const EMBEDDED_ES_PARSER = "embeddedEsParser";
|
|
9
|
+
export interface PrettierPluginDepsOptions {
|
|
10
|
+
}
|
|
11
|
+
export declare const options: {
|
|
12
|
+
embeddedEs: {
|
|
13
|
+
category: "Global";
|
|
14
|
+
type: "string";
|
|
15
|
+
array: true;
|
|
16
|
+
default: {
|
|
17
|
+
value: ("js" | "es" | "es6" | "mjs" | "cjs" | "pac" | "javascript")[];
|
|
18
|
+
}[];
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
embeddedEsParser: {
|
|
22
|
+
category: "Global";
|
|
23
|
+
type: "string";
|
|
24
|
+
array: false;
|
|
25
|
+
default: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
type Options = typeof options;
|
|
30
|
+
declare module "../types.js" {
|
|
31
|
+
interface EmbeddedOptions extends Options {
|
|
32
|
+
}
|
|
33
|
+
interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
|
|
34
|
+
}
|
|
35
|
+
interface PrettierPluginEmbedOptions {
|
|
36
|
+
[embeddedLanguage]?: Identifiers;
|
|
37
|
+
[EMBEDDED_ES_PARSER]?: EsParser;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
declare module "prettier" {
|
|
41
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Options } from "prettier";
|
|
2
|
+
import type { Embedder } from "../../types.js";
|
|
3
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
4
|
+
export declare const embedder: Embedder<Options>;
|
|
5
|
+
declare module "../types.js" {
|
|
6
|
+
interface EmbeddedEmbedders {
|
|
7
|
+
[embeddedLanguage]: typeof embedder;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
2
|
+
import type { MakeIdentifiersType, MakeIdentifiersHolderType } from "../utils.js";
|
|
3
|
+
declare const DEFAULT_IDENTIFIERS: readonly ["html", "htm", "shtml", "xhtml", "xht", "mdoc", "jsp", "asp", "aspx", "jshtm", "volt", "rhtml"];
|
|
4
|
+
type Identifiers = MakeIdentifiersType<typeof DEFAULT_IDENTIFIERS>;
|
|
5
|
+
type DefaultIdentifiersHolder = MakeIdentifiersHolderType<typeof DEFAULT_IDENTIFIERS>;
|
|
6
|
+
export interface PrettierPluginDepsOptions {
|
|
7
|
+
}
|
|
8
|
+
export declare const options: {
|
|
9
|
+
embeddedHtml: {
|
|
10
|
+
category: "Global";
|
|
11
|
+
type: "string";
|
|
12
|
+
array: true;
|
|
13
|
+
default: {
|
|
14
|
+
value: ("html" | "htm" | "shtml" | "xhtml" | "xht" | "mdoc" | "jsp" | "asp" | "aspx" | "jshtm" | "volt" | "rhtml")[];
|
|
15
|
+
}[];
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type Options = typeof options;
|
|
20
|
+
declare module "../types.js" {
|
|
21
|
+
interface EmbeddedOptions extends Options {
|
|
22
|
+
}
|
|
23
|
+
interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
|
|
24
|
+
}
|
|
25
|
+
interface PrettierPluginEmbedOptions {
|
|
26
|
+
[embeddedLanguage]?: Identifiers;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
declare module "prettier" {
|
|
30
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {};
|
package/dist/embedded/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./register.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type { EmbeddedLanguage, EmbeddedParsers, EmbeddedEmbedders, EmbeddedOptions, EmbeddedDefaultIdentifier, PrettierPluginEmbedOptions, } from "./types.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./embedded-language.js";
|
|
2
|
+
export * from "./options.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
2
|
+
export declare const options: {
|
|
3
|
+
embeddedNoop: {
|
|
4
|
+
category: "Global";
|
|
5
|
+
type: "string";
|
|
6
|
+
array: true;
|
|
7
|
+
default: {
|
|
8
|
+
value: never[];
|
|
9
|
+
}[];
|
|
10
|
+
description: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type Options = typeof options;
|
|
14
|
+
declare module "../types.js" {
|
|
15
|
+
interface EmbeddedOptions extends Options {
|
|
16
|
+
}
|
|
17
|
+
interface PrettierPluginEmbedOptions {
|
|
18
|
+
[embeddedLanguage]?: string[];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Options } from "prettier";
|
|
2
2
|
import type { Embedder } from "../../types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
4
4
|
export declare const embedder: Embedder<Options>;
|
|
5
5
|
declare module "../types.js" {
|
|
6
6
|
interface EmbeddedEmbedders {
|
|
7
|
-
[
|
|
7
|
+
[embeddedLanguage]: typeof embedder;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./embedded-language.js";
|
|
2
2
|
export * from "./embedder.js";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./options.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
2
|
+
import type { MakeIdentifiersType, MakeIdentifiersHolderType } from "../utils.js";
|
|
3
|
+
declare const DEFAULT_IDENTIFIERS: readonly ["php", "php5", "phtml", "ctp"];
|
|
4
|
+
type Identifiers = MakeIdentifiersType<typeof DEFAULT_IDENTIFIERS>;
|
|
5
|
+
type DefaultIdentifiersHolder = MakeIdentifiersHolderType<typeof DEFAULT_IDENTIFIERS>;
|
|
6
|
+
export declare const options: {
|
|
7
|
+
embeddedPhp: {
|
|
8
|
+
category: "Global";
|
|
9
|
+
type: "string";
|
|
10
|
+
array: true;
|
|
11
|
+
default: {
|
|
12
|
+
value: ("php" | "php5" | "phtml" | "ctp")[];
|
|
13
|
+
}[];
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
type Options = typeof options;
|
|
18
|
+
export interface PrettierPluginDepsOptions {
|
|
19
|
+
phpVersion?: "5.0" | "5.1" | "5.2" | "5.3" | "5.4" | "5.5" | "5.6" | "7.0" | "7.1" | "7.2" | "7.3" | "7.4" | "8.0" | "8.1" | "8.2";
|
|
20
|
+
trailingCommaPHP?: boolean;
|
|
21
|
+
braceStyle?: "psr-2" | "per-cs" | "1tbs";
|
|
22
|
+
}
|
|
23
|
+
declare module "../types.js" {
|
|
24
|
+
interface EmbeddedOptions extends Options {
|
|
25
|
+
}
|
|
26
|
+
interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
|
|
27
|
+
}
|
|
28
|
+
interface PrettierPluginEmbedOptions {
|
|
29
|
+
[embeddedLanguage]?: Identifiers;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
declare module "prettier" {
|
|
33
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type { EmbeddedEmbedders,
|
|
2
|
-
export declare const
|
|
1
|
+
import type { EmbeddedEmbedders, EmbeddedLanguage, EmbeddedParsers, EmbeddedOptions } from "./types.js";
|
|
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
|
-
import * as __glob__0_0 from "./
|
|
7
|
-
import * as __glob__0_1 from "./
|
|
8
|
-
import * as __glob__0_2 from "./
|
|
9
|
-
import * as __glob__0_3 from "./
|
|
6
|
+
import * as __glob__0_0 from "./es/index.js";
|
|
7
|
+
import * as __glob__0_1 from "./html/index.js";
|
|
8
|
+
import * as __glob__0_2 from "./noop/index.js";
|
|
9
|
+
import * as __glob__0_3 from "./php/index.js";
|
|
10
|
+
import * as __glob__0_4 from "./sql/index.js";
|
|
11
|
+
import * as __glob__0_5 from "./ts/index.js";
|
|
12
|
+
import * as __glob__0_6 from "./xml/index.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Options } from "prettier";
|
|
2
2
|
import type { Embedder } from "../../types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
4
4
|
export declare const embedder: Embedder<Options>;
|
|
5
5
|
declare module "../types.js" {
|
|
6
6
|
interface EmbeddedEmbedders {
|
|
7
|
-
[
|
|
7
|
+
[embeddedLanguage]: typeof embedder;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./embedded-language.js";
|
|
2
2
|
export * from "./embedder.js";
|
|
3
|
-
export * from "./
|
|
3
|
+
export * from "./options.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { SqlBaseOptions as PrettierPluginDepsOptions } from "prettier-plugin-sql";
|
|
2
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
3
|
+
import { MakeIdentifiersType, MakeIdentifiersHolderType } from "../utils.js";
|
|
4
|
+
export declare const SQL_FORMATTER_LANGUAGES: readonly ["sql", "bigquery", "hive", "mariadb", "mysql", "postgresql", "db2", "plsql", "n1ql", "redshift", "singlestoredb", "spark", "sqlite", "transactsql", "tsql", "trino"];
|
|
5
|
+
export declare const NODE_SQL_PARSER_DATABASES: readonly ["bigquery", "db2", "hive", "mariadb", "mysql", "postgresql", "transactsql", "flinksql"];
|
|
6
|
+
type Identifiers = MakeIdentifiersType<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
|
|
7
|
+
type DefaultIdentifiersHolder = MakeIdentifiersHolderType<typeof SQL_FORMATTER_LANGUAGES | typeof NODE_SQL_PARSER_DATABASES>;
|
|
8
|
+
export type SqlFormatterLanguage = (typeof SQL_FORMATTER_LANGUAGES)[number];
|
|
9
|
+
export type NodeSqlParserDataBase = (typeof NODE_SQL_PARSER_DATABASES)[number];
|
|
10
|
+
export { PrettierPluginDepsOptions };
|
|
11
|
+
export declare const options: {
|
|
12
|
+
embeddedSql: {
|
|
13
|
+
category: "Global";
|
|
14
|
+
type: "string";
|
|
15
|
+
array: true;
|
|
16
|
+
default: {
|
|
17
|
+
value: ("sql" | "bigquery" | "hive" | "mariadb" | "mysql" | "postgresql" | "db2" | "plsql" | "n1ql" | "redshift" | "singlestoredb" | "spark" | "sqlite" | "transactsql" | "tsql" | "trino")[];
|
|
18
|
+
}[];
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
type Options = typeof options;
|
|
23
|
+
declare module "../types.js" {
|
|
24
|
+
interface EmbeddedOptions extends Options {
|
|
25
|
+
}
|
|
26
|
+
interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
|
|
27
|
+
}
|
|
28
|
+
interface PrettierPluginEmbedOptions {
|
|
29
|
+
[embeddedLanguage]?: Identifiers;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
declare module "prettier" {
|
|
33
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Options } from "prettier";
|
|
2
|
+
import type { Embedder } from "../../types.js";
|
|
3
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
4
|
+
export declare const embedder: Embedder<Options>;
|
|
5
|
+
declare module "../types.js" {
|
|
6
|
+
interface EmbeddedEmbedders {
|
|
7
|
+
[embeddedLanguage]: typeof embedder;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { embeddedLanguage } from "./embedded-language.js";
|
|
2
|
+
import type { MakeIdentifiersType, MakeIdentifiersHolderType } from "../utils.js";
|
|
3
|
+
declare const DEFAULT_IDENTIFIERS: readonly ["ts", "cts", "mts", "typescript"];
|
|
4
|
+
type Identifiers = MakeIdentifiersType<typeof DEFAULT_IDENTIFIERS>;
|
|
5
|
+
type DefaultIdentifiersHolder = MakeIdentifiersHolderType<typeof DEFAULT_IDENTIFIERS>;
|
|
6
|
+
declare const DEFAULT_TS_PARSERS: readonly ["typescript", "babel-ts"];
|
|
7
|
+
type TsParser = (typeof DEFAULT_TS_PARSERS)[number];
|
|
8
|
+
declare const EMBEDDED_TS_PARSER = "embeddedTsParser";
|
|
9
|
+
export interface PrettierPluginDepsOptions {
|
|
10
|
+
}
|
|
11
|
+
export declare const options: {
|
|
12
|
+
embeddedTs: {
|
|
13
|
+
category: "Global";
|
|
14
|
+
type: "string";
|
|
15
|
+
array: true;
|
|
16
|
+
default: {
|
|
17
|
+
value: ("ts" | "cts" | "mts" | "typescript")[];
|
|
18
|
+
}[];
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
embeddedTsParser: {
|
|
22
|
+
category: "Global";
|
|
23
|
+
type: "string";
|
|
24
|
+
array: false;
|
|
25
|
+
default: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
type Options = typeof options;
|
|
30
|
+
declare module "../types.js" {
|
|
31
|
+
interface EmbeddedOptions extends Options {
|
|
32
|
+
}
|
|
33
|
+
interface EmbeddedDefaultIdentifiersHolder extends DefaultIdentifiersHolder {
|
|
34
|
+
}
|
|
35
|
+
interface PrettierPluginEmbedOptions {
|
|
36
|
+
[embeddedLanguage]?: Identifiers;
|
|
37
|
+
[EMBEDDED_TS_PARSER]?: TsParser;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
declare module "prettier" {
|
|
41
|
+
interface Options extends PrettierPluginDepsOptions {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export {};
|
package/dist/embedded/types.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { Parser, SupportOption, Options } from "prettier";
|
|
2
2
|
import type { Embedder } from "../types.js";
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import type { Satisfies } from "./utils.js";
|
|
4
|
+
type EmbeddedLanguageNamingConvention = `embedded${Capitalize<string>}`;
|
|
5
|
+
export interface EmbeddedParsers extends Record<EmbeddedLanguageNamingConvention, Parser | undefined> {
|
|
6
6
|
}
|
|
7
|
-
export interface EmbeddedEmbedders {
|
|
8
|
-
[name: EmbeddedNameConvention]: Embedder<Options> | undefined;
|
|
7
|
+
export interface EmbeddedEmbedders extends Record<EmbeddedLanguageNamingConvention, Embedder<Options> | undefined> {
|
|
9
8
|
}
|
|
10
|
-
export interface EmbeddedOptions {
|
|
11
|
-
[name: EmbeddedNameConvention]: SupportOption | undefined;
|
|
9
|
+
export interface EmbeddedOptions extends Record<EmbeddedLanguageNamingConvention, SupportOption | undefined> {
|
|
12
10
|
}
|
|
13
|
-
export interface
|
|
11
|
+
export interface EmbeddedLanguagesHolder {
|
|
14
12
|
}
|
|
15
|
-
export type
|
|
13
|
+
export type EmbeddedLanguage = Satisfies<EmbeddedLanguageNamingConvention, keyof EmbeddedLanguagesHolder>;
|
|
14
|
+
export interface EmbeddedDefaultIdentifiersHolder {
|
|
15
|
+
}
|
|
16
|
+
export type EmbeddedDefaultIdentifier = keyof EmbeddedDefaultIdentifiersHolder;
|
|
16
17
|
export interface PrettierPluginEmbedOptions {
|
|
17
18
|
}
|
|
18
19
|
declare module "prettier" {
|
package/dist/embedded/utils.d.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import type { Expression, Comment, TemplateLiteral } from "estree";
|
|
2
|
-
import type { AstPath, Options } from "prettier";
|
|
2
|
+
import type { AstPath, Options, Doc } 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 & {
|
|
6
6
|
comments?: Comment[];
|
|
7
7
|
}>, print: InternalPrintFun): builders.Doc[];
|
|
8
8
|
export declare function printTemplateExpressions(path: AstPath<TemplateLiteral>, print: InternalPrintFun): builders.Doc[][];
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
9
|
+
export declare function simpleRehydrateDoc(doc: Doc, placeholderRegex: RegExp, expressionDocs: Doc[]): builders.Doc[] | builders.DocCommand;
|
|
10
|
+
export declare function throwIfPluginIsNotFound(pluginName: string, options: Options, identifier: string): void;
|
|
11
|
+
export declare function insertEmbeddedLanguage(embeddedLanguages: string[], embeddedLanguage: string, firstEmbeddedLanguage: string): void;
|
|
12
|
+
export declare const randomUUID: (uuidLength?: number | undefined) => string;
|
|
13
|
+
export declare function preparePlaceholder(leading?: string, trailing?: string): {
|
|
14
|
+
createPlaceholder: (index: number) => string;
|
|
15
|
+
placeholderRegex: RegExp;
|
|
16
|
+
};
|
|
17
|
+
export declare function escapeRegExp(text: string): string;
|
|
18
|
+
export type MakeIdentifiersType<T extends readonly string[]> = (T[number][] & string[]) | string[];
|
|
19
|
+
export type MakeIdentifiersHolderType<T extends readonly string[]> = {
|
|
20
|
+
[key in T[number]]: void;
|
|
21
|
+
};
|
|
22
|
+
export type Satisfies<U, T extends U> = T;
|