prettier-plugin-sfmc 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/LICENSE +21 -0
- package/README.md +82 -0
- package/docs/options/ampscript-block-line-breaks.md +64 -0
- package/docs/options/ampscript-enforce-variable-casing.md +63 -0
- package/docs/options/ampscript-function-case.md +82 -0
- package/docs/options/ampscript-keyword-case.md +74 -0
- package/docs/options/ampscript-quote-style.md +69 -0
- package/docs/options/ampscript-remove-unnecessary-brackets.md +63 -0
- package/docs/options/ampscript-spacing.md +54 -0
- package/docs/options/ampscript-var-declaration-style.md +86 -0
- package/package.json +56 -0
- package/src/index.js +320 -0
- package/src/printer.js +428 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jörn Berkefeld
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# prettier-plugin-sfmc
|
|
2
|
+
|
|
3
|
+
Unified Prettier plugin for **Salesforce Marketing Cloud** — formats **AMPscript** (`.ampscript`, `.amp`, `.html`) and registers **SSJS** (`.ssjs`) files with Prettier's built-in JavaScript formatter.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install prettier-plugin-sfmc --save-dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Prettier 3.7+.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
Prettier auto-discovers plugins installed in `node_modules`. No config needed for `.ampscript`, `.amp`, and `.ssjs` files.
|
|
16
|
+
|
|
17
|
+
For `.html` files containing AMPscript, the plugin's parser handles AMPscript regions while delegating HTML to Prettier's built-in HTML formatter. SSJS `<script runat="server">` blocks are formatted as JavaScript by Prettier's HTML pipeline automatically.
|
|
18
|
+
|
|
19
|
+
To use explicitly in `.prettierrc`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"plugins": ["prettier-plugin-sfmc"]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
All options use the `ampscript` prefix — they control AMPscript formatting behavior.
|
|
30
|
+
|
|
31
|
+
| Option | Type | Default | Description |
|
|
32
|
+
| ------------------------------------ | ---------------------------------------------------------------------------- | --------------- | ---------------------------------------------- |
|
|
33
|
+
| [`ampscriptSpacing`](docs/options/ampscript-spacing.md) | boolean | `true` | Spacing in inline expressions: `%%= V(@x) =%%` |
|
|
34
|
+
| [`ampscriptEnforceVariableCasing`](docs/options/ampscript-enforce-variable-casing.md) | boolean | `true` | Normalize variable casing to first occurrence |
|
|
35
|
+
| [`ampscriptRemoveUnnecessaryBrackets`](docs/options/ampscript-remove-unnecessary-brackets.md) | boolean | `true` | Remove needless parentheses |
|
|
36
|
+
| [`ampscriptQuoteStyle`](docs/options/ampscript-quote-style.md) | `"single"` \| `"double"` | `"single"` | String quote style |
|
|
37
|
+
| [`ampscriptKeywordCase`](docs/options/ampscript-keyword-case.md) | `"lower"` \| `"upper"` \| `"preserve"` | `"lower"` | Keyword casing |
|
|
38
|
+
| [`ampscriptFunctionCase`](docs/options/ampscript-function-case.md) | `"upper-camel"` \| `"lower-camel"` \| `"upper"` \| `"lower"` \| `"preserve"` | `"upper-camel"` | Function name casing |
|
|
39
|
+
| [`ampscriptBlockLineBreaks`](docs/options/ampscript-block-line-breaks.md) | boolean | `true` | Line breaks before/after `%%[ ]%%` blocks |
|
|
40
|
+
| [`ampscriptVarDeclarationStyle`](docs/options/ampscript-var-declaration-style.md) | `"auto"` \| `"single-line"` \| `"multi-line"` | `"auto"` | Var declaration formatting |
|
|
41
|
+
|
|
42
|
+
### Example `.prettierrc`
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
47
|
+
"ampscriptKeywordCase": "upper",
|
|
48
|
+
"ampscriptFunctionCase": "upper-camel",
|
|
49
|
+
"ampscriptQuoteStyle": "single"
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Supported File Types
|
|
54
|
+
|
|
55
|
+
| Extension | Parser | What happens |
|
|
56
|
+
| ------------ | ------------------ | ----------------------------------------------- |
|
|
57
|
+
| `.ampscript` | `ampscript-parse` | Full AMPscript formatting |
|
|
58
|
+
| `.amp` | `ampscript-parse` | Full AMPscript formatting |
|
|
59
|
+
| `.html` | `ampscript-parse` | AMPscript formatted; HTML delegated to Prettier |
|
|
60
|
+
| `.ssjs` | `babel` (built-in) | Standard JavaScript formatting |
|
|
61
|
+
|
|
62
|
+
## HTML Embedding
|
|
63
|
+
|
|
64
|
+
When formatting `.html` files, the plugin:
|
|
65
|
+
|
|
66
|
+
1. Parses AMPscript regions (`%%[ ]%%`, `%%= =%%`, `<script language="ampscript">`)
|
|
67
|
+
2. Delegates HTML content to Prettier's built-in HTML formatter
|
|
68
|
+
3. Prettier's HTML formatter handles `<script runat="server">` SSJS blocks as JavaScript
|
|
69
|
+
|
|
70
|
+
This means a single plugin handles all SFMC formatting in HTML email templates.
|
|
71
|
+
|
|
72
|
+
## Migration from `prettier-plugin-ampscript` / `prettier-plugin-ssjs`
|
|
73
|
+
|
|
74
|
+
Both plugins have been merged into this single package:
|
|
75
|
+
|
|
76
|
+
1. Replace `prettier-plugin-ampscript` and `prettier-plugin-ssjs` with `prettier-plugin-sfmc`
|
|
77
|
+
2. Update the `plugins` array in `.prettierrc` if explicitly configured
|
|
78
|
+
3. All `ampscript*` option names are unchanged
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# `ampscriptBlockLineBreaks`
|
|
2
|
+
|
|
3
|
+
> Enforce blank lines before and after `%%[ … ]%%` block expressions.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `boolean` |
|
|
8
|
+
| **Default** | `true` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Adds an empty line before and after every AMPscript block (`%%[ … ]%%`) to visually separate logic from surrounding HTML or text content. Inline expressions (`%%= … =%%`) are never affected. Set to `false` when blocks are embedded in contexts — such as attribute values or tightly formatted output sections — where extra blank lines would break the template layout.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `true` (default) | Blank line inserted before and after every `%%[ ]%%` block |
|
|
20
|
+
| `false` | No blank lines added; blocks formatted flush with surrounding content |
|
|
21
|
+
|
|
22
|
+
### `true` (default)
|
|
23
|
+
|
|
24
|
+
**Input:**
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<p>Hello</p>%%[
|
|
28
|
+
var @name
|
|
29
|
+
set @name = "Alice"
|
|
30
|
+
]%%<p>%%=v(@name)=%%</p>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Output:**
|
|
34
|
+
|
|
35
|
+
```html
|
|
36
|
+
<p>Hello</p>
|
|
37
|
+
|
|
38
|
+
%%[
|
|
39
|
+
var @name
|
|
40
|
+
set @name = "Alice"
|
|
41
|
+
]%%
|
|
42
|
+
|
|
43
|
+
<p>%%= v(@name) =%%</p>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### `false`
|
|
47
|
+
|
|
48
|
+
**Output:**
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<p>Hello</p>%%[
|
|
52
|
+
var @name
|
|
53
|
+
set @name = "Alice"
|
|
54
|
+
]%%<p>%%= v(@name) =%%</p>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Configuration Example
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
62
|
+
"ampscriptBlockLineBreaks": false
|
|
63
|
+
}
|
|
64
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# `ampscriptEnforceVariableCasing`
|
|
2
|
+
|
|
3
|
+
> Normalize all occurrences of a variable to the casing of its first appearance in the file.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `boolean` |
|
|
8
|
+
| **Default** | `true` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
AMPscript variables are case-insensitive at runtime — `@firstName`, `@FirstName`, and `@FIRSTNAME` all refer to the same variable. This option enforces a consistent casing across all references to the same variable within a file. When `true`, the casing of the first declaration (or first use if there is no `var`) is treated as canonical, and all subsequent occurrences are normalised to match it.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `true` (default) | All occurrences of a variable adopt the casing of its first appearance |
|
|
20
|
+
| `false` | Variable casing is preserved as-is |
|
|
21
|
+
|
|
22
|
+
### `true` (default)
|
|
23
|
+
|
|
24
|
+
**Input:**
|
|
25
|
+
|
|
26
|
+
```ampscript
|
|
27
|
+
%%[
|
|
28
|
+
var @firstName
|
|
29
|
+
set @FirstName = "Alice"
|
|
30
|
+
output(v(@FIRSTNAME))
|
|
31
|
+
]%%
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Output:**
|
|
35
|
+
|
|
36
|
+
```ampscript
|
|
37
|
+
%%[
|
|
38
|
+
var @firstName
|
|
39
|
+
set @firstName = "Alice"
|
|
40
|
+
output(v(@firstName))
|
|
41
|
+
]%%
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `false`
|
|
45
|
+
|
|
46
|
+
**Input / Output** (casing preserved):
|
|
47
|
+
|
|
48
|
+
```ampscript
|
|
49
|
+
%%[
|
|
50
|
+
var @firstName
|
|
51
|
+
set @FirstName = "Alice"
|
|
52
|
+
output(v(@FIRSTNAME))
|
|
53
|
+
]%%
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Configuration Example
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
61
|
+
"ampscriptEnforceVariableCasing": false
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# `ampscriptFunctionCase`
|
|
2
|
+
|
|
3
|
+
> Control the casing of AMPscript function names.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `"upper-camel"` \| `"lower-camel"` \| `"upper"` \| `"lower"` \| `"preserve"` |
|
|
8
|
+
| **Default** | `"upper-camel"` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Normalises the casing of every known AMPscript function name. AMPscript function names are case-insensitive at runtime; this option chooses a consistent form for the formatted output. The `"upper-camel"` value uses the canonical PascalCase form as published in the Salesforce documentation (e.g. `Lookup`, `ContentBlockByKey`, `AttributeValue`).
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `"upper-camel"` (default) | Canonical PascalCase: `Lookup`, `ContentBlockByKey` |
|
|
20
|
+
| `"lower-camel"` | camelCase: `lookup`, `contentBlockByKey` |
|
|
21
|
+
| `"upper"` | ALL CAPS: `LOOKUP`, `CONTENTBLOCKBYKEY` |
|
|
22
|
+
| `"lower"` | all lowercase: `lookup`, `contentblockbykey` |
|
|
23
|
+
| `"preserve"` | Function casing is left exactly as written |
|
|
24
|
+
|
|
25
|
+
### `"upper-camel"` (default)
|
|
26
|
+
|
|
27
|
+
**Input:**
|
|
28
|
+
|
|
29
|
+
```ampscript
|
|
30
|
+
%%[
|
|
31
|
+
var @result
|
|
32
|
+
set @result = LOOKUP("MyDE", "Value", "Key", @key)
|
|
33
|
+
set @html = contentblockbykey("my-block")
|
|
34
|
+
]%%
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Output:**
|
|
38
|
+
|
|
39
|
+
```ampscript
|
|
40
|
+
%%[
|
|
41
|
+
var @result
|
|
42
|
+
set @result = Lookup("MyDE", "Value", "Key", @key)
|
|
43
|
+
set @html = ContentBlockByKey("my-block")
|
|
44
|
+
]%%
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `"upper"`
|
|
48
|
+
|
|
49
|
+
**Output:**
|
|
50
|
+
|
|
51
|
+
```ampscript
|
|
52
|
+
%%[
|
|
53
|
+
var @result
|
|
54
|
+
set @result = LOOKUP("MyDE", "Value", "Key", @key)
|
|
55
|
+
set @html = CONTENTBLOCKBYKEY("my-block")
|
|
56
|
+
]%%
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### `"lower"`
|
|
60
|
+
|
|
61
|
+
**Output:**
|
|
62
|
+
|
|
63
|
+
```ampscript
|
|
64
|
+
%%[
|
|
65
|
+
var @result
|
|
66
|
+
set @result = lookup("MyDE", "Value", "Key", @key)
|
|
67
|
+
set @html = contentblockbykey("my-block")
|
|
68
|
+
]%%
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `"preserve"`
|
|
72
|
+
|
|
73
|
+
Function names are emitted exactly as they appeared in the source.
|
|
74
|
+
|
|
75
|
+
## Configuration Example
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
80
|
+
"ampscriptFunctionCase": "upper-camel"
|
|
81
|
+
}
|
|
82
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# `ampscriptKeywordCase`
|
|
2
|
+
|
|
3
|
+
> Control the casing of AMPscript keywords.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `"lower"` \| `"upper"` \| `"preserve"` |
|
|
8
|
+
| **Default** | `"lower"` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Normalises the casing of AMPscript control-flow keywords: `if`, `then`, `elseif`, `else`, `endif`, `for`, `to`, `downto`, `do`, `next`, `var`, `set`, `and`, `or`, `not`, `true`, `false`. AMPscript keywords are case-insensitive at runtime; this option picks a single style for the formatted output.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `"lower"` (default) | `if`, `set`, `var`, `for`, `then`, `endif`, … |
|
|
20
|
+
| `"upper"` | `IF`, `SET`, `VAR`, `FOR`, `THEN`, `ENDIF`, … |
|
|
21
|
+
| `"preserve"` | Keyword casing is left exactly as written |
|
|
22
|
+
|
|
23
|
+
### `"lower"` (default)
|
|
24
|
+
|
|
25
|
+
**Input:**
|
|
26
|
+
|
|
27
|
+
```ampscript
|
|
28
|
+
%%[
|
|
29
|
+
VAR @name
|
|
30
|
+
SET @name = "Alice"
|
|
31
|
+
IF @name == "Alice" THEN
|
|
32
|
+
output(v(@name))
|
|
33
|
+
ENDIF
|
|
34
|
+
]%%
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Output:**
|
|
38
|
+
|
|
39
|
+
```ampscript
|
|
40
|
+
%%[
|
|
41
|
+
var @name
|
|
42
|
+
set @name = "Alice"
|
|
43
|
+
if @name == "Alice" then
|
|
44
|
+
output(v(@name))
|
|
45
|
+
endif
|
|
46
|
+
]%%
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `"upper"`
|
|
50
|
+
|
|
51
|
+
**Output:**
|
|
52
|
+
|
|
53
|
+
```ampscript
|
|
54
|
+
%%[
|
|
55
|
+
VAR @name
|
|
56
|
+
SET @name = "Alice"
|
|
57
|
+
IF @name == "Alice" THEN
|
|
58
|
+
output(v(@name))
|
|
59
|
+
ENDIF
|
|
60
|
+
]%%
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### `"preserve"`
|
|
64
|
+
|
|
65
|
+
Keywords are emitted exactly as they appeared in the source.
|
|
66
|
+
|
|
67
|
+
## Configuration Example
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
72
|
+
"ampscriptKeywordCase": "upper"
|
|
73
|
+
}
|
|
74
|
+
```
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# `ampscriptQuoteStyle`
|
|
2
|
+
|
|
3
|
+
> Select whether strings should be wrapped in single or double quotes.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `"single"` \| `"double"` |
|
|
8
|
+
| **Default** | `"single"` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Normalises all AMPscript string literals to use a single consistent quote character. This applies to function arguments, `set` values, and any other string expression throughout the file.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `"single"` (default) | All strings use single quotes: `'value'` |
|
|
20
|
+
| `"double"` | All strings use double quotes: `"value"` |
|
|
21
|
+
|
|
22
|
+
### `"single"` (default)
|
|
23
|
+
|
|
24
|
+
**Input:**
|
|
25
|
+
|
|
26
|
+
```ampscript
|
|
27
|
+
%%[
|
|
28
|
+
var @name
|
|
29
|
+
set @name = Lookup("MyDE", "Name", "Key", "abc")
|
|
30
|
+
]%%
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Output:**
|
|
34
|
+
|
|
35
|
+
```ampscript
|
|
36
|
+
%%[
|
|
37
|
+
var @name
|
|
38
|
+
set @name = Lookup('MyDE', 'Name', 'Key', 'abc')
|
|
39
|
+
]%%
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### `"double"`
|
|
43
|
+
|
|
44
|
+
**Input:**
|
|
45
|
+
|
|
46
|
+
```ampscript
|
|
47
|
+
%%[
|
|
48
|
+
var @name
|
|
49
|
+
set @name = Lookup('MyDE', 'Name', 'Key', 'abc')
|
|
50
|
+
]%%
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Output:**
|
|
54
|
+
|
|
55
|
+
```ampscript
|
|
56
|
+
%%[
|
|
57
|
+
var @name
|
|
58
|
+
set @name = Lookup("MyDE", "Name", "Key", "abc")
|
|
59
|
+
]%%
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Configuration Example
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
67
|
+
"ampscriptQuoteStyle": "double"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# `ampscriptRemoveUnnecessaryBrackets`
|
|
2
|
+
|
|
3
|
+
> Automatically remove parentheses that add no grouping value.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `boolean` |
|
|
8
|
+
| **Default** | `true` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Removes redundant parentheses around simple expressions where they contribute no grouping semantics. For example, `(@name)` used as a function argument or assignment value is simplified to `@name`. Parentheses that are genuinely required for operator precedence are always preserved.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `true` (default) | Redundant parentheses are stripped |
|
|
20
|
+
| `false` | Parentheses are preserved exactly as written |
|
|
21
|
+
|
|
22
|
+
### `true` (default)
|
|
23
|
+
|
|
24
|
+
**Input:**
|
|
25
|
+
|
|
26
|
+
```ampscript
|
|
27
|
+
%%[
|
|
28
|
+
var @result
|
|
29
|
+
set @result = (Lookup("MyDE", "Value", "Key", (@key)))
|
|
30
|
+
output(v((@result)))
|
|
31
|
+
]%%
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Output:**
|
|
35
|
+
|
|
36
|
+
```ampscript
|
|
37
|
+
%%[
|
|
38
|
+
var @result
|
|
39
|
+
set @result = Lookup("MyDE", "Value", "Key", @key)
|
|
40
|
+
output(v(@result))
|
|
41
|
+
]%%
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `false`
|
|
45
|
+
|
|
46
|
+
**Input / Output** (parentheses preserved):
|
|
47
|
+
|
|
48
|
+
```ampscript
|
|
49
|
+
%%[
|
|
50
|
+
var @result
|
|
51
|
+
set @result = (Lookup("MyDE", "Value", "Key", (@key)))
|
|
52
|
+
output(v((@result)))
|
|
53
|
+
]%%
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Configuration Example
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
61
|
+
"ampscriptRemoveUnnecessaryBrackets": false
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# `ampscriptSpacing`
|
|
2
|
+
|
|
3
|
+
> Enforce consistent spacing around operators and inside inline expressions.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `boolean` |
|
|
8
|
+
| **Default** | `true` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Controls whether spaces are emitted inside inline expressions (`%%= … =%%`) — between the `=%%` / `%%=` delimiters and the expression content — and around binary operators inside expressions. When `true`, the output is spaced for readability. When `false`, delimiters are printed flush against the content.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `true` (default) | Prints `%%= V(@name) =%%` — spaces inside delimiters and around operators |
|
|
20
|
+
| `false` | Prints `%%=V(@name)=%%` — no spaces inside delimiters |
|
|
21
|
+
|
|
22
|
+
### `true` (default)
|
|
23
|
+
|
|
24
|
+
**Input:**
|
|
25
|
+
|
|
26
|
+
```ampscript
|
|
27
|
+
%%=V(@firstName)=%%
|
|
28
|
+
%%=Lookup("MyDE","Value","Key",@key)=%%
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Output:**
|
|
32
|
+
|
|
33
|
+
```ampscript
|
|
34
|
+
%%= V(@firstName) =%%
|
|
35
|
+
%%= Lookup("MyDE", "Value", "Key", @key) =%%
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `false`
|
|
39
|
+
|
|
40
|
+
**Input / Output:**
|
|
41
|
+
|
|
42
|
+
```ampscript
|
|
43
|
+
%%=V(@firstName)=%%
|
|
44
|
+
%%=Lookup("MyDE","Value","Key",@key)=%%
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration Example
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
52
|
+
"ampscriptSpacing": false
|
|
53
|
+
}
|
|
54
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# `ampscriptVarDeclarationStyle`
|
|
2
|
+
|
|
3
|
+
> Control how `var` declarations with multiple variables are formatted.
|
|
4
|
+
|
|
5
|
+
| | |
|
|
6
|
+
|---|---|
|
|
7
|
+
| **Type** | `"auto"` \| `"single-line"` \| `"multi-line"` |
|
|
8
|
+
| **Default** | `"auto"` |
|
|
9
|
+
| **Applied by** | `prettier --write` · VS Code format-on-save (requires the [Prettier extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)) |
|
|
10
|
+
|
|
11
|
+
## What It Controls
|
|
12
|
+
|
|
13
|
+
Determines whether multiple variables in a single `var` statement are kept on one line, split to one variable per line, or left to Prettier's `printWidth` heuristic. AMPscript allows both `var @a, @b, @c` (all on one line) and separate `var` statements for each variable.
|
|
14
|
+
|
|
15
|
+
## Settings
|
|
16
|
+
|
|
17
|
+
| Value | Effect |
|
|
18
|
+
|-------|--------|
|
|
19
|
+
| `"auto"` (default) | Single line when it fits within `printWidth`; one-per-line when it doesn't |
|
|
20
|
+
| `"single-line"` | Always `var @a, @b, @c` on one line regardless of width |
|
|
21
|
+
| `"multi-line"` | Always one variable per `var` statement |
|
|
22
|
+
|
|
23
|
+
### `"auto"` (default)
|
|
24
|
+
|
|
25
|
+
**Input:**
|
|
26
|
+
|
|
27
|
+
```ampscript
|
|
28
|
+
%%[
|
|
29
|
+
var @firstName, @lastName, @email, @address, @city, @postalCode
|
|
30
|
+
]%%
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Output (when line is short enough for `printWidth`):**
|
|
34
|
+
|
|
35
|
+
```ampscript
|
|
36
|
+
%%[
|
|
37
|
+
var @firstName, @lastName, @email
|
|
38
|
+
]%%
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Output (when line exceeds `printWidth`):**
|
|
42
|
+
|
|
43
|
+
```ampscript
|
|
44
|
+
%%[
|
|
45
|
+
var @firstName
|
|
46
|
+
var @lastName
|
|
47
|
+
var @email
|
|
48
|
+
var @address
|
|
49
|
+
var @city
|
|
50
|
+
var @postalCode
|
|
51
|
+
]%%
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### `"single-line"`
|
|
55
|
+
|
|
56
|
+
**Output:**
|
|
57
|
+
|
|
58
|
+
```ampscript
|
|
59
|
+
%%[
|
|
60
|
+
var @firstName, @lastName, @email, @address, @city, @postalCode
|
|
61
|
+
]%%
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `"multi-line"`
|
|
65
|
+
|
|
66
|
+
**Output:**
|
|
67
|
+
|
|
68
|
+
```ampscript
|
|
69
|
+
%%[
|
|
70
|
+
var @firstName
|
|
71
|
+
var @lastName
|
|
72
|
+
var @email
|
|
73
|
+
var @address
|
|
74
|
+
var @city
|
|
75
|
+
var @postalCode
|
|
76
|
+
]%%
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Configuration Example
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"plugins": ["prettier-plugin-sfmc"],
|
|
84
|
+
"ampscriptVarDeclarationStyle": "multi-line"
|
|
85
|
+
}
|
|
86
|
+
```
|