eslint-plugin-sfmc 4.8.3 → 4.9.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 +50 -50
- package/docs/unicorn-compatibility.md +18 -10
- package/package.json +11 -11
- package/src/ampscript-parser.js +1 -0
- package/src/index.js +4 -2
- package/src/processor.js +3 -1
- package/src/rules/amp/prefer-attribute-value.js +51 -27
- package/src/rules/hbs/_shared.js +3 -1
- package/src/rules/hbs/no-unknown-binding.js +6 -2
- package/src/rules/hbs/no-unsupported-construct.js +6 -2
- package/src/rules/ssjs/no-clr-header-access.js +3 -1
package/README.md
CHANGED
|
@@ -79,8 +79,8 @@ Use the `-next` config variants when targeting **Marketing Cloud Next (MCN)**. M
|
|
|
79
79
|
| ---------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- |
|
|
80
80
|
| `sfmc.configs['ampscript-next']` | `**/*.ampscript`, `**/*.amp` | AMPscript rules + flags functions unsupported in MCN (single config object) |
|
|
81
81
|
| `sfmc.configs['ssjs-next']` | `**/*.ssjs` | Flags all SSJS API calls as MCN-unsupported; all other SSJS quality rules disabled |
|
|
82
|
-
| `sfmc.configs['recommended-next']` | Both of the above + `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for standalone `.hbs` files
|
|
83
|
-
| `sfmc.configs['embedded-next']` | `**/*.html`, `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for HTML-embedded code and `.hbs`
|
|
82
|
+
| `sfmc.configs['recommended-next']` | Both of the above + `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for standalone `.hbs` files |
|
|
83
|
+
| `sfmc.configs['embedded-next']` | `**/*.html`, `**/*.hbs` | AMPscript MCN-aware + SSJS flagged + Handlebars rules for HTML-embedded code and `.hbs` |
|
|
84
84
|
| `sfmc.configs['strict-next']` | All of the above + HTML + `**/*.hbs` | All AMPscript rules at `error` severity + MCN flag; SSJS fully flagged; Handlebars rules on |
|
|
85
85
|
|
|
86
86
|
Standalone `.hbs` files (VS Code's built-in **Handlebars** language) are treated as MCN by default — Handlebars only runs on Marketing Cloud Next, so a `.hbs` file is always linted with the full Handlebars rule set. This is deliberately wired **only** into the `-next` configs; the classic `recommended` / `strict` (Engagement) configs never lint `.hbs`.
|
|
@@ -122,30 +122,30 @@ export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-n
|
|
|
122
122
|
|
|
123
123
|
## SSJS Rules (`ssjs-*`)
|
|
124
124
|
|
|
125
|
-
| Rule | Default | Description
|
|
126
|
-
| ------------------------------------------------------------------------------------------- | ------------------------ |
|
|
127
|
-
| [`sfmc/ssjs-require-platform-load`](docs/rules/ssjs/require-platform-load.md) | `error` | Require `Platform.Load("core")` before Core or requiresCoreLoad globals
|
|
128
|
-
| [`sfmc/ssjs-no-unsupported-syntax`](docs/rules/ssjs/no-unsupported-syntax.md) | `error` | Flag ES6+ syntax not supported by SFMC
|
|
129
|
-
| [`sfmc/ssjs-no-unknown-function`](docs/rules/ssjs/no-unknown-function.md) | `error` | Disallow unknown methods on Platform.\*, HTTP, Core Library, and WSProxy
|
|
130
|
-
| [`sfmc/ssjs-no-mcn-unsupported`](docs/rules/ssjs/no-mcn-unsupported.md) | off (`error` in `-next`) | Flag all SSJS API usage as unsupported in Marketing Cloud Next
|
|
125
|
+
| Rule | Default | Description |
|
|
126
|
+
| ------------------------------------------------------------------------------------------- | ------------------------ | -------------------------------------------------------------------------- |
|
|
127
|
+
| [`sfmc/ssjs-require-platform-load`](docs/rules/ssjs/require-platform-load.md) | `error` | Require `Platform.Load("core")` before Core or requiresCoreLoad globals |
|
|
128
|
+
| [`sfmc/ssjs-no-unsupported-syntax`](docs/rules/ssjs/no-unsupported-syntax.md) | `error` | Flag ES6+ syntax not supported by SFMC |
|
|
129
|
+
| [`sfmc/ssjs-no-unknown-function`](docs/rules/ssjs/no-unknown-function.md) | `error` | Disallow unknown methods on Platform.\*, HTTP, Core Library, and WSProxy |
|
|
130
|
+
| [`sfmc/ssjs-no-mcn-unsupported`](docs/rules/ssjs/no-mcn-unsupported.md) | off (`error` in `-next`) | Flag all SSJS API usage as unsupported in Marketing Cloud Next |
|
|
131
131
|
| [`sfmc/ssjs-no-deprecated-function`](docs/rules/ssjs/no-deprecated-function.md) | `error` | Flag use of deprecated SFMC SSJS APIs (Classic Content classes, ErrorUtil) |
|
|
132
|
-
| [`sfmc/ssjs-no-nonexistent-global`](docs/rules/ssjs/no-nonexistent-global.md) | `error` | Flag documented SSJS globals that throw ReferenceError at runtime
|
|
133
|
-
| [`sfmc/ssjs-no-property-call`](docs/rules/ssjs/no-property-call.md) | `error` | Disallow calling Platform.Request/Response properties as functions
|
|
134
|
-
| [`sfmc/ssjs-no-clr-header-access`](docs/rules/ssjs/no-clr-header-access.md) | `error` | Disallow CLR-unsafe reads of `HttpResponse.headers`; read via `for..in`
|
|
135
|
-
| [`sfmc/ssjs-require-string-clr-content`](docs/rules/ssjs/require-string-clr-content.md) | `error` | Require wrapping `HttpResponse.content` with `String()` before use
|
|
136
|
-
| [`sfmc/ssjs-platform-function-arity`](docs/rules/ssjs/platform-function-arity.md) | `error` | Enforce correct arity for `Platform.Function.*`
|
|
137
|
-
| [`sfmc/ssjs-require-platform-load-order`](docs/rules/ssjs/require-platform-load-order.md) | `error` | Require `Platform.Load()` before Core usage in order
|
|
138
|
-
| [`sfmc/ssjs-no-hardcoded-credentials`](docs/rules/ssjs/no-hardcoded-credentials.md) | `error` | Flag hardcoded keys in encryption calls
|
|
139
|
-
| [`sfmc/ssjs-cache-loop-length`](docs/rules/ssjs/cache-loop-length.md) | `warn` | Require caching `.length` in for-loops
|
|
140
|
-
| [`sfmc/ssjs-require-hasownproperty`](docs/rules/ssjs/require-hasownproperty.md) | `warn` | Require `hasOwnProperty` guard in for-in loops
|
|
141
|
-
| [`sfmc/ssjs-prefer-platform-load-version`](docs/rules/ssjs/prefer-platform-load-version.md) | `warn` | Enforce a minimum `Platform.Load` version string
|
|
142
|
-
| [`sfmc/ssjs-no-unavailable-method`](docs/rules/ssjs/no-unavailable-method.md) | `warn` | Flag Array/String methods unavailable or broken in SFMC's ES3 engine
|
|
143
|
-
| [`sfmc/ssjs-no-nonfunctional-method`](docs/rules/ssjs/no-nonfunctional-method.md) | `warn` | Flag Core Library methods that never take effect at runtime
|
|
144
|
-
| [`sfmc/ssjs-prefer-parsejson-safe-arg`](docs/rules/ssjs/prefer-parsejson-safe-arg.md) | `warn` | Require string coercion on `ParseJSON` argument
|
|
145
|
-
| [`sfmc/ssjs-no-switch-default`](docs/rules/ssjs/no-switch-default.md) | `warn` | Disallow `default` clause in `switch` statements
|
|
146
|
-
| [`sfmc/ssjs-no-treatascontent-injection`](docs/rules/ssjs/no-treatascontent-injection.md) | `warn` | Flag dynamic string concatenation in `TreatAsContent` calls
|
|
147
|
-
| [`sfmc/ssjs-core-method-arity`](docs/rules/ssjs/core-method-arity.md) | `warn` | Enforce correct argument counts for Core Library object methods
|
|
148
|
-
| [`sfmc/ssjs-arg-types`](docs/rules/ssjs/arg-types.md) | `warn` | Check that literal arguments match expected parameter types
|
|
132
|
+
| [`sfmc/ssjs-no-nonexistent-global`](docs/rules/ssjs/no-nonexistent-global.md) | `error` | Flag documented SSJS globals that throw ReferenceError at runtime |
|
|
133
|
+
| [`sfmc/ssjs-no-property-call`](docs/rules/ssjs/no-property-call.md) | `error` | Disallow calling Platform.Request/Response properties as functions |
|
|
134
|
+
| [`sfmc/ssjs-no-clr-header-access`](docs/rules/ssjs/no-clr-header-access.md) | `error` | Disallow CLR-unsafe reads of `HttpResponse.headers`; read via `for..in` |
|
|
135
|
+
| [`sfmc/ssjs-require-string-clr-content`](docs/rules/ssjs/require-string-clr-content.md) | `error` | Require wrapping `HttpResponse.content` with `String()` before use |
|
|
136
|
+
| [`sfmc/ssjs-platform-function-arity`](docs/rules/ssjs/platform-function-arity.md) | `error` | Enforce correct arity for `Platform.Function.*` |
|
|
137
|
+
| [`sfmc/ssjs-require-platform-load-order`](docs/rules/ssjs/require-platform-load-order.md) | `error` | Require `Platform.Load()` before Core usage in order |
|
|
138
|
+
| [`sfmc/ssjs-no-hardcoded-credentials`](docs/rules/ssjs/no-hardcoded-credentials.md) | `error` | Flag hardcoded keys in encryption calls |
|
|
139
|
+
| [`sfmc/ssjs-cache-loop-length`](docs/rules/ssjs/cache-loop-length.md) | `warn` | Require caching `.length` in for-loops |
|
|
140
|
+
| [`sfmc/ssjs-require-hasownproperty`](docs/rules/ssjs/require-hasownproperty.md) | `warn` | Require `hasOwnProperty` guard in for-in loops |
|
|
141
|
+
| [`sfmc/ssjs-prefer-platform-load-version`](docs/rules/ssjs/prefer-platform-load-version.md) | `warn` | Enforce a minimum `Platform.Load` version string |
|
|
142
|
+
| [`sfmc/ssjs-no-unavailable-method`](docs/rules/ssjs/no-unavailable-method.md) | `warn` | Flag Array/String methods unavailable or broken in SFMC's ES3 engine |
|
|
143
|
+
| [`sfmc/ssjs-no-nonfunctional-method`](docs/rules/ssjs/no-nonfunctional-method.md) | `warn` | Flag Core Library methods that never take effect at runtime |
|
|
144
|
+
| [`sfmc/ssjs-prefer-parsejson-safe-arg`](docs/rules/ssjs/prefer-parsejson-safe-arg.md) | `warn` | Require string coercion on `ParseJSON` argument |
|
|
145
|
+
| [`sfmc/ssjs-no-switch-default`](docs/rules/ssjs/no-switch-default.md) | `warn` | Disallow `default` clause in `switch` statements |
|
|
146
|
+
| [`sfmc/ssjs-no-treatascontent-injection`](docs/rules/ssjs/no-treatascontent-injection.md) | `warn` | Flag dynamic string concatenation in `TreatAsContent` calls |
|
|
147
|
+
| [`sfmc/ssjs-core-method-arity`](docs/rules/ssjs/core-method-arity.md) | `warn` | Enforce correct argument counts for Core Library object methods |
|
|
148
|
+
| [`sfmc/ssjs-arg-types`](docs/rules/ssjs/arg-types.md) | `warn` | Check that literal arguments match expected parameter types |
|
|
149
149
|
|
|
150
150
|
## Handlebars Rules (`hbs-*`)
|
|
151
151
|
|
|
@@ -165,16 +165,16 @@ Email HTML for SFMC frequently contains **Outlook conditional comments** (`<!--[
|
|
|
165
165
|
|
|
166
166
|
The MSO rules are **auto-included** in the HTML-embedded configs: `embedded`, `strict`, `embedded-next`, and `strict-next`. When you lint an `.html` file with any of these, the combined `sfmc/sfmc` processor also extracts MSO conditional comments and the document body and runs the MSO rules on them — no extra processor or config to wire up, and no processor conflict.
|
|
167
167
|
|
|
168
|
-
| Rule (`mso/*`)
|
|
169
|
-
|
|
|
170
|
-
| [`mso/valid-mso-condition`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/valid-mso-condition.md)
|
|
171
|
-
| [`mso/matching-mso-endif`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif.md)
|
|
172
|
-
| [`mso/matching-mso-endif-type`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif-type.md)
|
|
173
|
-
| [`mso/no-unknown-mso-property`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-mso-property.md)
|
|
174
|
-
| [`mso/vml-requires-namespace`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/vml-requires-namespace.md)
|
|
175
|
-
| [`mso/no-unknown-vml-tag`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-tag.md)
|
|
176
|
-
| [`mso/no-unknown-vml-attribute`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-attribute.md) | `warn`
|
|
177
|
-
| [`mso/table-presentation-role`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/table-presentation-role.md)
|
|
168
|
+
| Rule (`mso/*`) | Default (embedded/strict) | Description |
|
|
169
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | ----------------------------------------------------------- |
|
|
170
|
+
| [`mso/valid-mso-condition`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/valid-mso-condition.md) | `error` | Validate the `[if …]` expression syntax of MSO comments |
|
|
171
|
+
| [`mso/matching-mso-endif`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif.md) | `error` | Require every MSO opener to have a matching `<![endif]>` |
|
|
172
|
+
| [`mso/matching-mso-endif-type`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/matching-mso-endif-type.md) | `warn` | Require the endif comment style to match its opener |
|
|
173
|
+
| [`mso/no-unknown-mso-property`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-mso-property.md) | `warn` | Flag unknown `mso-*` CSS properties |
|
|
174
|
+
| [`mso/vml-requires-namespace`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/vml-requires-namespace.md) | `warn` | Require the `v:` VML namespace declaration when VML is used |
|
|
175
|
+
| [`mso/no-unknown-vml-tag`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-tag.md) | `warn` | Flag unknown `v:*` VML tags |
|
|
176
|
+
| [`mso/no-unknown-vml-attribute`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/no-unknown-vml-attribute.md) | `warn` | Flag unknown attributes on VML tags |
|
|
177
|
+
| [`mso/table-presentation-role`](https://github.com/JoernBerkefeld/eslint-plugin-mso-email/blob/main/docs/rules/table-presentation-role.md) | `warn` | Require `role="presentation"` on layout tables |
|
|
178
178
|
|
|
179
179
|
Severities above are the same in `embedded`, `strict`, `embedded-next`, and `strict-next` (MSO markup is engine-agnostic — it behaves identically for Engagement and Next). For MSO rule details and options, see the [`eslint-plugin-mso-email` docs](https://github.com/JoernBerkefeld/eslint-plugin-mso-email).
|
|
180
180
|
|
|
@@ -182,7 +182,7 @@ Severities above are the same in `embedded`, `strict`, `embedded-next`, and `str
|
|
|
182
182
|
|
|
183
183
|
[`eslint-plugin-unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn) is a high-quality, widely used plugin that we **strongly recommend** — but it is built for modern JavaScript, not SFMC's **SSJS** runtime. SFMC SSJS runs on a JINT-based ES3/ES5-era engine that lacks many built-ins (`Array#includes`, `String#startsWith`, `Set`, `Map`, `Object.fromEntries`, `Math.trunc`, spread `...`, ES modules, `async`/`await`, …).
|
|
184
184
|
|
|
185
|
-
If you enable unicorn's `recommended` set on SSJS, about **46** of its
|
|
185
|
+
If you enable unicorn's `recommended` set on SSJS, about **46** of its 308 recommended rules would either **autofix your code to a missing built-in** (breaking it at runtime) or **forbid a required SFMC workaround**. `eslint-plugin-sfmc` offers an **optional** override config that turns off exactly those 46 rules for SSJS.
|
|
186
186
|
|
|
187
187
|
**Important — this is optional and only needed if you use unicorn.** `eslint-plugin-sfmc` does **not** depend on or load unicorn. The override configs are plain rules objects with **no** `plugins` key, so they only resolve when your own unicorn config (which registers the `unicorn` plugin) is loaded **earlier** in the flat-config array. Spread the sfmc override **after** it:
|
|
188
188
|
|
|
@@ -191,27 +191,27 @@ import sfmc from 'eslint-plugin-sfmc';
|
|
|
191
191
|
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
|
|
192
192
|
|
|
193
193
|
export default [
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
194
|
+
eslintPluginUnicorn.configs.recommended, // you opt in — registers the `unicorn` plugin
|
|
195
|
+
...sfmc.configs.recommended,
|
|
196
|
+
...sfmc.configs.embedded, // AMPscript + SSJS embedded in HTML (<script runat="server">)
|
|
197
|
+
...sfmc.configs['unicorn-ssjs'], // OPTIONAL: off the 46 SFMC-incompatible unicorn rules for SSJS
|
|
198
|
+
...sfmc.configs['unicorn-ssjs-embedded'], // OPTIONAL: same override for SSJS embedded in HTML (<script runat="server">)
|
|
199
199
|
];
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
| Config
|
|
203
|
-
|
|
|
204
|
-
| `sfmc.configs['unicorn-ssjs']`
|
|
205
|
-
| `sfmc.configs['unicorn-ssjs-embedded']` | `**/*.html/*.js`
|
|
202
|
+
| Config | Files | What it does |
|
|
203
|
+
| --------------------------------------- | ---------------- | --------------------------------------------------------- |
|
|
204
|
+
| `sfmc.configs['unicorn-ssjs']` | `**/*.ssjs` | Turns off the 46 SFMC-incompatible unicorn rules for SSJS |
|
|
205
|
+
| `sfmc.configs['unicorn-ssjs-embedded']` | `**/*.html/*.js` | Same 46-rule override for SSJS embedded in HTML |
|
|
206
206
|
|
|
207
|
-
Only **46** of unicorn's
|
|
207
|
+
Only **46** of unicorn's 308 recommended rules are overridden — the other **262** stay active. If you don't use unicorn, omit these configs entirely. For the full rule-by-rule breakdown (with rationale and SFMC evidence links, pinned to unicorn v73.0.0), see [docs/unicorn-compatibility.md](docs/unicorn-compatibility.md).
|
|
208
208
|
|
|
209
209
|
## Processors
|
|
210
210
|
|
|
211
|
-
| Processor | Purpose
|
|
212
|
-
| ---------------- |
|
|
213
|
-
| `sfmc/ampscript` | Extract `%%[ ]%%`, `%%= =%%`, `<script language="ampscript">`
|
|
214
|
-
| `sfmc/ssjs` | Extract `<script runat="server">` (non-ampscript)
|
|
211
|
+
| Processor | Purpose |
|
|
212
|
+
| ---------------- | ----------------------------------------------------------------- |
|
|
213
|
+
| `sfmc/ampscript` | Extract `%%[ ]%%`, `%%= =%%`, `<script language="ampscript">` |
|
|
214
|
+
| `sfmc/ssjs` | Extract `<script runat="server">` (non-ampscript) |
|
|
215
215
|
| `sfmc/sfmc` | Combined: extracts AMPscript, SSJS, Handlebars, and MSO from HTML |
|
|
216
216
|
|
|
217
217
|
## License
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# `eslint-plugin-unicorn` compatibility with SFMC SSJS
|
|
2
2
|
|
|
3
|
-
> **Compatibility analysis for [`eslint-plugin-unicorn@
|
|
3
|
+
> **Compatibility analysis for [`eslint-plugin-unicorn@73.0.0`](https://github.com/sindresorhus/eslint-plugin-unicorn).**
|
|
4
4
|
>
|
|
5
|
-
> ⚠️ **Version warning:** This classification was done against `eslint-plugin-unicorn` **
|
|
5
|
+
> ⚠️ **Version warning:** This classification was done against `eslint-plugin-unicorn` **v73.0.0** (308 recommended rules). Newer versions of unicorn may add, rename, or change rules that are **not** yet classified here. Re-audit this page whenever you upgrade unicorn — a rule added in a later version could autofix SSJS into runtime-breaking code without being in the override list below.
|
|
6
6
|
|
|
7
7
|
`eslint-plugin-unicorn` is an excellent, actively maintained plugin that we **strongly recommend** — but it targets modern JavaScript engines, not the Salesforce Marketing Cloud **SSJS** runtime. SFMC SSJS runs on a JINT-based ES3/ES5-era engine that is missing many built-ins (`Array#includes`, `String#startsWith`, `Set`, `Map`, `Object.fromEntries`, `Math.trunc`, spread `...`, ES modules, `async`/`await`, …). See the SFMC evidence pages:
|
|
8
8
|
|
|
9
9
|
- **ECMAScript built-ins support** — <https://ssjs.guide/ecmascript-builtins/>
|
|
10
10
|
- **Engine limitations** — <https://ssjs.guide/engine-limitations/>
|
|
11
11
|
|
|
12
|
-
Of unicorn's **
|
|
12
|
+
Of unicorn's **308** recommended rules (v73.0.0), **262** are safe to keep on for SSJS and **46** should be turned off. `eslint-plugin-sfmc` ships an **optional** override config (`unicorn-ssjs` / `unicorn-ssjs-embedded`) that turns off exactly those 46 for SSJS files. `eslint-plugin-sfmc` does **not** depend on or load unicorn — the override only takes effect when you have loaded unicorn yourself. See [Section 1](#section-1--how-to-apply).
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -41,7 +41,7 @@ If you don't use unicorn, omit these configs entirely — nothing else in `eslin
|
|
|
41
41
|
|
|
42
42
|
## Section 2 — Rules to override for SSJS (46)
|
|
43
43
|
|
|
44
|
-
These 46 recommended rules either **autofix code to a missing built-in**, **forbid a documented SFMC workaround**, or **enforce ES-module / async / ES6-only syntax** the engine cannot run. The override config sets each to `'off'` for SSJS. All 46 are confirmed `recommended` in unicorn
|
|
44
|
+
These 46 recommended rules either **autofix code to a missing built-in**, **forbid a documented SFMC workaround**, or **enforce ES-module / async / ES6-only syntax** the engine cannot run. The override config sets each to `'off'` for SSJS. All 46 are confirmed `recommended` in unicorn v73.0.0.
|
|
45
45
|
|
|
46
46
|
### Group A — autofix to a missing built-in / forbid a SFMC workaround (41)
|
|
47
47
|
|
|
@@ -103,11 +103,11 @@ These 46 recommended rules either **autofix code to a missing built-in**, **forb
|
|
|
103
103
|
|
|
104
104
|
---
|
|
105
105
|
|
|
106
|
-
## Section 3 — Rules OK as-is (
|
|
106
|
+
## Section 3 — Rules OK as-is (262)
|
|
107
107
|
|
|
108
108
|
These recommended rules are **not** disabled by the override config. They are either genuinely SFMC-safe (readability / best-practice rules that work on the ES3/ES5 engine) or **inert** on SSJS — many target the DOM, Node.js, Promises, TypeScript, or ES modules and therefore never fire on server-side SFMC code. Each links to its official unicorn documentation.
|
|
109
109
|
|
|
110
|
-
<!-- BEGIN
|
|
110
|
+
<!-- BEGIN 262-OK-LIST -->
|
|
111
111
|
- [better-dom-traversing](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/better-dom-traversing.md)
|
|
112
112
|
- [catch-error-name](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/catch-error-name.md)
|
|
113
113
|
- [class-reference-in-static-methods](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/class-reference-in-static-methods.md)
|
|
@@ -150,8 +150,8 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
150
150
|
- [no-array-from-fill](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-from-fill.md)
|
|
151
151
|
- [no-array-method-this-argument](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-method-this-argument.md)
|
|
152
152
|
- [no-array-reduce](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md)
|
|
153
|
-
- [no-array-sort](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-sort.md)
|
|
154
153
|
- [no-array-sort-for-min-max](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-sort-for-min-max.md)
|
|
154
|
+
- [no-array-sort](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-sort.md)
|
|
155
155
|
- [no-array-splice](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-splice.md)
|
|
156
156
|
- [no-async-promise-finally](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-async-promise-finally.md)
|
|
157
157
|
- [no-await-expression-member](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-await-expression-member.md)
|
|
@@ -195,6 +195,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
195
195
|
- [no-magic-array-flat-depth](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-magic-array-flat-depth.md)
|
|
196
196
|
- [no-mismatched-map-key](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-mismatched-map-key.md)
|
|
197
197
|
- [no-misrefactored-assignment](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-misrefactored-assignment.md)
|
|
198
|
+
- [no-multiple-promise-resolver-calls](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-multiple-promise-resolver-calls.md)
|
|
198
199
|
- [no-named-default](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-named-default.md)
|
|
199
200
|
- [no-negated-array-predicate](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-negated-array-predicate.md)
|
|
200
201
|
- [no-negated-comparison](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-negated-comparison.md)
|
|
@@ -213,6 +214,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
213
214
|
- [no-redundant-comparison](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-redundant-comparison.md)
|
|
214
215
|
- [no-return-array-push](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-return-array-push.md)
|
|
215
216
|
- [no-selector-as-dom-name](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-selector-as-dom-name.md)
|
|
217
|
+
- [no-shorthand-property-overrides](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-shorthand-property-overrides.md)
|
|
216
218
|
- [no-single-promise-in-promise-methods](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-single-promise-in-promise-methods.md)
|
|
217
219
|
- [no-static-only-class](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-static-only-class.md)
|
|
218
220
|
- [no-subtraction-comparison](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-subtraction-comparison.md)
|
|
@@ -221,6 +223,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
221
223
|
- [no-this-outside-of-class](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-this-outside-of-class.md)
|
|
222
224
|
- [no-top-level-assignment-in-function](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-top-level-assignment-in-function.md)
|
|
223
225
|
- [no-top-level-side-effects](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-top-level-side-effects.md)
|
|
226
|
+
- [no-transition-all](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-transition-all.md)
|
|
224
227
|
- [no-typeof-undefined](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-typeof-undefined.md)
|
|
225
228
|
- [no-uncalled-method](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-uncalled-method.md)
|
|
226
229
|
- [no-undeclared-class-members](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-undeclared-class-members.md)
|
|
@@ -243,6 +246,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
243
246
|
- [no-unsafe-buffer-conversion](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unsafe-buffer-conversion.md)
|
|
244
247
|
- [no-unsafe-promise-all-settled-values](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unsafe-promise-all-settled-values.md)
|
|
245
248
|
- [no-unsafe-property-key](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unsafe-property-key.md)
|
|
249
|
+
- [no-unsafe-sqlite-interpolation](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unsafe-sqlite-interpolation.md)
|
|
246
250
|
- [no-unsafe-string-replacement](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unsafe-string-replacement.md)
|
|
247
251
|
- [no-unused-array-method-return](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unused-array-method-return.md)
|
|
248
252
|
- [no-useless-boolean-cast](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-boolean-cast.md)
|
|
@@ -260,6 +264,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
260
264
|
- [no-useless-logical-operand](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-logical-operand.md)
|
|
261
265
|
- [no-useless-override](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-override.md)
|
|
262
266
|
- [no-useless-promise-resolve-reject](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-promise-resolve-reject.md)
|
|
267
|
+
- [no-useless-re-export](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-re-export.md)
|
|
263
268
|
- [no-useless-recursion](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-recursion.md)
|
|
264
269
|
- [no-useless-spread](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-spread.md)
|
|
265
270
|
- [no-useless-switch-case](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-switch-case.md)
|
|
@@ -272,8 +277,8 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
272
277
|
- [operator-assignment](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/operator-assignment.md)
|
|
273
278
|
- [prefer-abort-signal-any](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-abort-signal-any.md)
|
|
274
279
|
- [prefer-abort-signal-timeout](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-abort-signal-timeout.md)
|
|
275
|
-
- [prefer-add-event-listener](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-add-event-listener.md)
|
|
276
280
|
- [prefer-add-event-listener-options](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-add-event-listener-options.md)
|
|
281
|
+
- [prefer-add-event-listener](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-add-event-listener.md)
|
|
277
282
|
- [prefer-aggregate-error](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-aggregate-error.md)
|
|
278
283
|
- [prefer-array-from-map](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-from-map.md)
|
|
279
284
|
- [prefer-array-from-range](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-from-range.md)
|
|
@@ -290,6 +295,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
290
295
|
- [prefer-default-parameters](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-default-parameters.md)
|
|
291
296
|
- [prefer-direct-iteration](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-direct-iteration.md)
|
|
292
297
|
- [prefer-dom-node-append](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-append.md)
|
|
298
|
+
- [prefer-dom-node-html-methods](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-html-methods.md)
|
|
293
299
|
- [prefer-dom-node-remove](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-remove.md)
|
|
294
300
|
- [prefer-dom-node-replace-children](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-replace-children.md)
|
|
295
301
|
- [prefer-dom-node-text-content](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-dom-node-text-content.md)
|
|
@@ -305,8 +311,8 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
305
311
|
- [prefer-identifier-import-export-specifiers](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-identifier-import-export-specifiers.md)
|
|
306
312
|
- [prefer-includes-over-repeated-comparisons](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-includes-over-repeated-comparisons.md)
|
|
307
313
|
- [prefer-iterable-in-constructor](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-iterable-in-constructor.md)
|
|
308
|
-
- [prefer-iterator-to-array](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-iterator-to-array.md)
|
|
309
314
|
- [prefer-iterator-to-array-at-end](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-iterator-to-array-at-end.md)
|
|
315
|
+
- [prefer-iterator-to-array](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-iterator-to-array.md)
|
|
310
316
|
- [prefer-keyboard-event-key](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-keyboard-event-key.md)
|
|
311
317
|
- [prefer-location-assign](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-location-assign.md)
|
|
312
318
|
- [prefer-logical-operator-over-ternary](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-logical-operator-over-ternary.md)
|
|
@@ -340,6 +346,7 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
340
346
|
- [prefer-split-limit](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-split-limit.md)
|
|
341
347
|
- [prefer-switch](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-switch.md)
|
|
342
348
|
- [prefer-ternary](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-ternary.md)
|
|
349
|
+
- [prefer-then-catch](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-then-catch.md)
|
|
343
350
|
- [prefer-toggle-attribute](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-toggle-attribute.md)
|
|
344
351
|
- [prefer-type-error](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-type-error.md)
|
|
345
352
|
- [prefer-type-literal-last](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-type-literal-last.md)
|
|
@@ -357,10 +364,11 @@ These recommended rules are **not** disabled by the override config. They are ei
|
|
|
357
364
|
- [require-number-to-fixed-digits-argument](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/require-number-to-fixed-digits-argument.md)
|
|
358
365
|
- [require-passive-events](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/require-passive-events.md)
|
|
359
366
|
- [require-proxy-trap-boolean-return](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/require-proxy-trap-boolean-return.md)
|
|
367
|
+
- [single-line-block-comment-style](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/single-line-block-comment-style.md)
|
|
360
368
|
- [switch-case-braces](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/switch-case-braces.md)
|
|
361
369
|
- [switch-case-break-position](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/switch-case-break-position.md)
|
|
362
370
|
- [template-indent](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/template-indent.md)
|
|
363
371
|
- [text-encoding-identifier-case](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/text-encoding-identifier-case.md)
|
|
364
372
|
- [throw-new-error](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/throw-new-error.md)
|
|
365
|
-
<!-- END
|
|
373
|
+
<!-- END 262-OK-LIST -->
|
|
366
374
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sfmc",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.1",
|
|
4
4
|
"description": "ESLint plugin for Salesforce Marketing Cloud Engagement+Next - AMPscript, Server-Side JavaScript (SSJS) and Handlebars",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@handlebars/parser": "^2.2.2",
|
|
40
|
-
"ampscript-data": "^3.
|
|
41
|
-
"ampscript-parser": "^0.
|
|
40
|
+
"ampscript-data": "^3.1.1",
|
|
41
|
+
"ampscript-parser": "^0.3.1",
|
|
42
42
|
"eslint-plugin-mso-email": "^2.0.0",
|
|
43
|
-
"handlebars-data": "^0.3.
|
|
43
|
+
"handlebars-data": "^0.3.1",
|
|
44
44
|
"mso-conditional-parser": "^2.0.1",
|
|
45
|
-
"ssjs-data": "^1.
|
|
45
|
+
"ssjs-data": "^1.3.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"eslint": ">=9.0.0"
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@eslint/js": "^10.0.1",
|
|
67
|
-
"eslint": "^10.
|
|
67
|
+
"eslint": "^10.8.0",
|
|
68
68
|
"eslint-config-prettier": "^10.1.8",
|
|
69
|
-
"eslint-plugin-jsdoc": "^63.
|
|
69
|
+
"eslint-plugin-jsdoc": "^63.3.3",
|
|
70
70
|
"eslint-plugin-prettier": "^5.5.6",
|
|
71
|
-
"eslint-plugin-unicorn": "^
|
|
72
|
-
"globals": "^17.
|
|
71
|
+
"eslint-plugin-unicorn": "^73.0.0",
|
|
72
|
+
"globals": "^17.9.0",
|
|
73
73
|
"husky": "^9.1.7",
|
|
74
|
-
"lint-staged": "^17.0
|
|
75
|
-
"prettier": "^3.9.
|
|
74
|
+
"lint-staged": "^17.3.0",
|
|
75
|
+
"prettier": "^3.9.6"
|
|
76
76
|
},
|
|
77
77
|
"lint-staged": {
|
|
78
78
|
"*.{js,mjs,cjs}": [
|
package/src/ampscript-parser.js
CHANGED
package/src/index.js
CHANGED
|
@@ -323,7 +323,9 @@ const hbsOffRules = {
|
|
|
323
323
|
'sfmc/hbs-no-mcn-unsupported': 'off',
|
|
324
324
|
};
|
|
325
325
|
|
|
326
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* Shared languageOptions for linting virtual `.hbs` files.
|
|
328
|
+
*/
|
|
327
329
|
const hbsLanguageOptions = { parser: handlebarsParser };
|
|
328
330
|
|
|
329
331
|
/**
|
|
@@ -353,7 +355,7 @@ function standaloneHandlebarsConfigs(configName) {
|
|
|
353
355
|
|
|
354
356
|
/**
|
|
355
357
|
* The 46 `eslint-plugin-unicorn` recommended rules (analysed against
|
|
356
|
-
* unicorn
|
|
358
|
+
* unicorn v73.0.0) that are incompatible with the SFMC SSJS (JINT / ES3-ES5)
|
|
357
359
|
* engine — they either autofix code to a missing built-in or forbid a required
|
|
358
360
|
* SFMC workaround, or enforce ES-module / async / ES6-only syntax that the
|
|
359
361
|
* engine cannot run. Each is mapped to `'off'`.
|
package/src/processor.js
CHANGED
|
@@ -29,7 +29,9 @@ const SSJS_SCRIPT_OPEN_RE =
|
|
|
29
29
|
/<script\b(?=[^>]*\brunat\s*=\s*['"]server['"])(?![^>]*\blanguage\s*=\s*['"]ampscript['"])[^>]*>/gi;
|
|
30
30
|
const SCRIPT_CLOSE_G = /<\/script\s*>/gi;
|
|
31
31
|
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* AMPscript region patterns blanked before the Handlebars parser runs.
|
|
34
|
+
*/
|
|
33
35
|
const AMPSCRIPT_REGION_PATTERNS = [
|
|
34
36
|
/%%\[[\s\S]*?\]%%/g,
|
|
35
37
|
/%%=[\s\S]*?=%%/g,
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Suggests wrapping
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Suggests wrapping custom personalization strings in `AttributeValue("...")`
|
|
3
|
+
* to prevent send-aborting errors when the attribute is missing from the
|
|
4
|
+
* subscriber context. Applies to both bare identifiers (e.g. `FirstName`) and
|
|
5
|
+
* bracket notation (e.g. `[First Name]`).
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Known Marketing Cloud system personalization strings (e.g. `_subscriberkey`,
|
|
8
|
+
* `emailaddr`, `[MSG(0).NOUN(0)]`) are exempt in either form. Only flags nodes
|
|
9
|
+
* that appear directly in SetStatement values or as standalone
|
|
10
|
+
* ExpressionStatements — contexts where a bare attribute reference is likely
|
|
11
|
+
* intentional data access rather than a function name.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
import { functionNames } from 'ampscript-data';
|
|
14
|
+
import { functionNames, isSystemPersonalizationString } from 'ampscript-data';
|
|
13
15
|
|
|
14
16
|
const AMPSCRIPT_KEYWORDS = new Set([
|
|
15
17
|
'var',
|
|
@@ -31,15 +33,35 @@ const AMPSCRIPT_KEYWORDS = new Set([
|
|
|
31
33
|
'false',
|
|
32
34
|
]);
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Returns the attribute name a node refers to when it is a candidate for the
|
|
38
|
+
* AttributeValue() suggestion, or null when the node should be ignored (a
|
|
39
|
+
* function name, keyword, or known system personalization string).
|
|
40
|
+
*
|
|
41
|
+
* @param {object} node - AMPscript AST node to inspect.
|
|
42
|
+
* @returns {string | null} The attribute name to wrap, or null.
|
|
43
|
+
*/
|
|
44
|
+
function personalizationName(node) {
|
|
45
|
+
if (!node) {
|
|
46
|
+
return null;
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
if (node.type === 'Identifier') {
|
|
49
|
+
const lower = node.value.toLowerCase();
|
|
50
|
+
if (functionNames.has(lower) || AMPSCRIPT_KEYWORDS.has(lower)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (isSystemPersonalizationString(node.value)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return node.value;
|
|
57
|
+
}
|
|
58
|
+
if (node.type === 'PersonalizationString') {
|
|
59
|
+
if (isSystemPersonalizationString(node.value)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return node.value;
|
|
41
63
|
}
|
|
42
|
-
return
|
|
64
|
+
return null;
|
|
43
65
|
}
|
|
44
66
|
|
|
45
67
|
export default {
|
|
@@ -60,20 +82,20 @@ export default {
|
|
|
60
82
|
},
|
|
61
83
|
|
|
62
84
|
create(context) {
|
|
63
|
-
function reportWithSuggestion(
|
|
85
|
+
function reportWithSuggestion(node, name) {
|
|
86
|
+
// Escape embedded double quotes so the generated
|
|
87
|
+
// AttributeValue("…") call stays syntactically valid.
|
|
88
|
+
const escaped = name.replaceAll('"', String.raw`\"`);
|
|
64
89
|
context.report({
|
|
65
|
-
node
|
|
90
|
+
node,
|
|
66
91
|
messageId: 'preferAttributeValue',
|
|
67
|
-
data: { name
|
|
92
|
+
data: { name },
|
|
68
93
|
suggest: [
|
|
69
94
|
{
|
|
70
95
|
messageId: 'wrapWithAttributeValue',
|
|
71
|
-
data: { name
|
|
96
|
+
data: { name },
|
|
72
97
|
fix(fixer) {
|
|
73
|
-
return fixer.replaceText(
|
|
74
|
-
identifierNode,
|
|
75
|
-
`AttributeValue("${identifierNode.value}")`,
|
|
76
|
-
);
|
|
98
|
+
return fixer.replaceText(node, `AttributeValue("${escaped}")`);
|
|
77
99
|
},
|
|
78
100
|
},
|
|
79
101
|
],
|
|
@@ -82,14 +104,16 @@ export default {
|
|
|
82
104
|
|
|
83
105
|
return {
|
|
84
106
|
SetStatement(node) {
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
const name = personalizationName(node.value);
|
|
108
|
+
if (name !== null) {
|
|
109
|
+
reportWithSuggestion(node.value, name);
|
|
87
110
|
}
|
|
88
111
|
},
|
|
89
112
|
|
|
90
113
|
AmpExpressionStatement(node) {
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
const name = personalizationName(node.expression);
|
|
115
|
+
if (name !== null) {
|
|
116
|
+
reportWithSuggestion(node.expression, name);
|
|
93
117
|
}
|
|
94
118
|
},
|
|
95
119
|
};
|
package/src/rules/hbs/_shared.js
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* that ESLint diagnostics and editor diagnostics stay consistent.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* Matches a `{!$namespace.Field}` built-in data binding token.
|
|
10
|
+
*/
|
|
9
11
|
export const BINDING_PATTERN = /\{!\$([A-Za-z0-9_.]+)\}/g;
|
|
10
12
|
|
|
11
13
|
/**
|
|
@@ -12,9 +12,13 @@ import { BINDING_PATTERN, closestMatch } from './_shared.js';
|
|
|
12
12
|
* than walking the AST.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Proper-cased built-in binding names, used for "did you mean" suggestions.
|
|
17
|
+
*/
|
|
16
18
|
const BINDING_NAME_LIST = BUILTIN_BINDINGS.map((b) => b.name);
|
|
17
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Map from lowercase binding name to its `{!$...}` token, for suggestion text.
|
|
21
|
+
*/
|
|
18
22
|
const BINDING_TOKEN_BY_NAME = new Map(BUILTIN_BINDINGS.map((b) => [b.name.toLowerCase(), b.token]));
|
|
19
23
|
|
|
20
24
|
export default {
|
|
@@ -11,14 +11,18 @@ import { simpleHelperName } from './_shared.js';
|
|
|
11
11
|
* sfmc-language-lsp.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* AST node types that may carry an unsupported construct.
|
|
16
|
+
*/
|
|
15
17
|
const NODE_TYPES = unsupportedByNodeType.keys().toArray();
|
|
16
18
|
|
|
17
19
|
// The handlebars-data messages contain literal `{{> ...}}`, `{{log}}`, etc. as
|
|
18
20
|
// examples. ESLint treats `{{...}}` in a message template as an interpolation
|
|
19
21
|
// placeholder, so the literal text is passed through a single `{{text}}`
|
|
20
22
|
// placeholder instead of being baked into the template.
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* messageId per construct id → passthrough template, declared statically.
|
|
25
|
+
*/
|
|
22
26
|
const MESSAGES = Object.fromEntries(
|
|
23
27
|
unsupportedByNodeType
|
|
24
28
|
.values()
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
* and rewrites the access to `getHeaderMap(resp)["name"]`.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Canonical helper inserted by the quick-fix, mirrored from ssjs.guide.
|
|
24
|
+
*/
|
|
23
25
|
const HEADER_MAP_HELPER = `/**
|
|
24
26
|
* Build a plain { name: value } header map from an HttpResponse.
|
|
25
27
|
* Reads only the for..in enumeration keys (shaped "[Name, Value]") so it never
|