prettier-plugin-sfmc 0.2.0 → 0.3.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 +18 -19
- package/package.json +1 -1
- package/src/index.js +3 -0
package/README.md
CHANGED
|
@@ -60,41 +60,40 @@ All options use the `ampscript` prefix — they control AMPscript formatting beh
|
|
|
60
60
|
| `.ssjs` | `babel` (built-in) | Standard JavaScript formatting |
|
|
61
61
|
| `.sql` | `sql` | SQL via composed `prettier-plugin-sql` |
|
|
62
62
|
|
|
63
|
-
## Core Prettier defaults (AMPscript, HTML, SQL)
|
|
63
|
+
## Core Prettier defaults (AMPscript, HTML, SQL, JavaScript / SSJS)
|
|
64
64
|
|
|
65
|
-
This plugin exports [Prettier `defaultOptions`](https://prettier.io/docs/plugins#defaultoptions). Prettier merges them
|
|
65
|
+
This plugin exports [Prettier `defaultOptions`](https://prettier.io/docs/plugins#defaultoptions). Prettier merges them from whichever plugin **owns the active printer** for the file being formatted. This package supplies printers for **AMPscript**, **SQL** (via composed `prettier-plugin-sql`), and the shared **`estree`** printer (the same implementation Prettier ships for JavaScript). User plugins are loaded **after** built-ins, so this plugin becomes the effective `estree` printer—meaning **`.ssjs`** files (typically `parser: "babel"`) pick up the table below **without** copying these keys into `.prettierrc`.
|
|
66
66
|
|
|
67
67
|
| Option | Default | Rationale |
|
|
68
68
|
| ------ | ------- | --------- |
|
|
69
69
|
| `useTabs` | `false` | SFMC often normalizes tabs away on save; spaces keep layout stable. |
|
|
70
70
|
| `tabWidth` | `4` | Readable indentation (override in config if you prefer 2). |
|
|
71
71
|
| `printWidth` | `100` | Fits typical editor panes better than Prettier’s 80. |
|
|
72
|
-
| `singleQuote` | `true` |
|
|
73
|
-
| `trailingComma` | `'none'` | Avoids trailing commas
|
|
72
|
+
| `singleQuote` | `true` | Common JS style; aligns with `ampscriptQuoteStyle: 'single'` where the core quote option applies. |
|
|
73
|
+
| `trailingComma` | `'none'` | Avoids trailing commas that can break SSJS in some SFMC contexts. |
|
|
74
74
|
|
|
75
75
|
String delimiters inside AMPscript blocks still follow `ampscriptQuoteStyle`. See [Prettier options](https://prettier.io/docs/options) for every standard flag.
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
**Overrides:** Add options to `.prettierrc` or [overrides](https://prettier.io/docs/configuration#configuration-overrides) only when you want to **diverge** (for example `tabWidth: 2` for the whole project, or different rules per file glob).
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```json
|
|
82
|
-
{
|
|
83
|
-
"plugins": ["prettier-plugin-sfmc"],
|
|
84
|
-
"singleQuote": true,
|
|
85
|
-
"trailingComma": "none",
|
|
86
|
-
"tabWidth": 4,
|
|
87
|
-
"printWidth": 100
|
|
88
|
-
}
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
To keep **AMPscript-only** indentation at 2 spaces while using different values for SSJS, use `overrides` keyed by file pattern.
|
|
79
|
+
**Scope:** With this plugin enabled, any file Prettier formats using the **`estree`** printer uses these defaults—not only `.ssjs`. If another plugin in your config also registers `printers.estree`, plugin **order** matters (the last one wins).
|
|
92
80
|
|
|
93
81
|
## SQL (Transact-SQL / SFMC)
|
|
94
82
|
|
|
95
83
|
`.sql` formatting is provided by [prettier-plugin-sql](https://github.com/un-ts/prettier/tree/master/packages/sql) (npm: [prettier-plugin-sql](https://www.npmjs.com/package/prettier-plugin-sql)). You only need `prettier` and `prettier-plugin-sfmc`; do not add a second entry in `plugins` for SQL.
|
|
96
84
|
|
|
97
|
-
**Defaults
|
|
85
|
+
**Defaults for SFMC-style T-SQL** (from composed [prettier-plugin-sql](https://www.npmjs.com/package/prettier-plugin-sql)):
|
|
86
|
+
|
|
87
|
+
| Option | Default | Other values | Rationale |
|
|
88
|
+
| ------ | ------- | ------------ | --------- |
|
|
89
|
+
| `language` | `tsql` | n/a | Must stay `tsql` for SFMC T-SQL. Other dialects are not supported for SFMC SQL; changing this can break formatting or behaviour. |
|
|
90
|
+
| `formatter` | `sql-formatter` | n/a | Must stay `sql-formatter` for SFMC SQL. Other formatters are not supported in this context; changing this can break. |
|
|
91
|
+
| `keywordCase` | `upper` | `preserve`, `lower` | Casing for reserved keywords. |
|
|
92
|
+
| `functionCase` | `upper` | `preserve`, `lower` | Casing for function names. |
|
|
93
|
+
| `identifierCase` | `preserve` | `upper`, `lower` | Unquoted identifiers only (upstream treats this as experimental). |
|
|
94
|
+
| `dataTypeCase` | `preserve` | `upper`, `lower` | Casing for data type names. |
|
|
95
|
+
|
|
96
|
+
Do **not** override `language` or `formatter` for SFMC. You may override the **casing** options in `.prettierrc` or under `overrides` with `files: "*.sql"` if you want different keyword/function/identifier/data-type casing.
|
|
98
97
|
|
|
99
98
|
Core layout still follows [Prettier options](https://prettier.io/docs/options). SQL-specific knobs (`expressionWidth`, `linesBetweenQueries`, etc.) are documented in the upstream package README.
|
|
100
99
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* A unified Prettier plugin for Salesforce Marketing Cloud.
|
|
5
5
|
* Handles AMPscript formatting (.ampscript, .amp, .html), SSJS file
|
|
6
6
|
* registration (.ssjs), and SQL (.sql) via composed prettier-plugin-sql.
|
|
7
|
+
* Re-exports Prettier’s `estree` printer so `defaultOptions` apply to JS/SSJS.
|
|
7
8
|
*
|
|
8
9
|
* Exports: languages, parsers, printers, options, defaultOptions
|
|
9
10
|
* Following the Prettier v3 plugin API (ESM).
|
|
@@ -11,6 +12,7 @@
|
|
|
11
12
|
|
|
12
13
|
import { parse } from 'ampscript-parser';
|
|
13
14
|
import sqlPlugin from 'prettier-plugin-sql';
|
|
15
|
+
import { printers as prettierEstreePrinters } from 'prettier/plugins/estree';
|
|
14
16
|
import { printAmpscriptNode, collectVariableMap } from './printer.js';
|
|
15
17
|
import * as prettier from 'prettier';
|
|
16
18
|
|
|
@@ -96,6 +98,7 @@ export const parsers = {
|
|
|
96
98
|
|
|
97
99
|
export const printers = {
|
|
98
100
|
...sqlPlugin.printers,
|
|
101
|
+
estree: prettierEstreePrinters.estree,
|
|
99
102
|
'ampscript-ast': {
|
|
100
103
|
print(path, options, print) {
|
|
101
104
|
const node = path.node;
|