eslint-plugin-sfmc 5.4.4 → 5.6.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 +7 -11
- package/docs/unicorn-compatibility.md +182 -50
- package/package.json +11 -5
- package/src/index.js +381 -7
- package/src/rules/amp/argument-types.js +2 -2
- package/src/rules/ssjs/cache-loop-length.js +6 -5
- package/src/rules/ssjs/http-property-value.js +5 -4
- package/src/rules/ssjs/no-clr-header-access.js +5 -4
- package/src/rules/ssjs/no-invalid-property-access.js +5 -4
- package/src/rules/ssjs/no-nonexistent-global.js +1 -1
- package/src/rules/ssjs/no-treatascontent-injection.js +11 -14
- package/src/rules/ssjs/no-unavailable-method.js +6 -4
- package/src/rules/ssjs/prefer-parsejson-safe-argument.js +19 -25
- package/src/rules/ssjs/require-string-clr-content.js +5 -4
- package/src/rules/ssjs/ssjs-argument-types.js +5 -5
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Unified ESLint plugin for **Salesforce Marketing Cloud** — linting rules for b
|
|
|
8
8
|
npm install eslint-plugin-sfmc --save-dev
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires ESLint **10.0.0+** (flat config) and Node.js **22+**. The ESLint minimum is a breaking requirement change; all 12 public configuration shapes remain unchanged (six objects and six multi-config arrays). Optional composition with `eslint-plugin-unicorn@76` requires ESLint **10.4.0+**, matching
|
|
11
|
+
Requires ESLint **10.0.0+** (flat config) and Node.js **22+**. The ESLint minimum is a breaking requirement change; all 12 public configuration shapes remain unchanged (six objects and six multi-config arrays). Optional composition with `eslint-plugin-unicorn@76` or `@80` requires ESLint **10.4.0+**, matching their upstream peer range (unicorn 80 also needs Node.js **22.13+**); the base SFMC plugin and its non-Unicorn configs remain supported from ESLint 10.0.0.
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
@@ -202,9 +202,11 @@ Severities above are the same in `embedded`, `strict`, `embedded-next`, and `str
|
|
|
202
202
|
|
|
203
203
|
[`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`, `Math.trunc`, spread `...`, ES modules, `async`/`await`, …). CloudPage probes found zero-argument string `slice()` throwing after a working `"Hello".substring()` call. Native `Object.fromEntries`, `toReversed`, `toSorted`, `toSpliced`, `replaceAll`, `matchAll` and `structuredClone` were unavailable: `typeof` returned `undefined` and direct calls threw, both without Core and with Core 1.1.1 or 1.1.5.
|
|
204
204
|
|
|
205
|
-
For Unicorn **
|
|
205
|
+
For Unicorn **80.0.0**, **87** of its **340** enabled recommended rules must not run on SSJS: API/syntax incompatibilities, recorded runtime-semantic hazards, and diagnostic-only pressure toward unsafe changes. `prefer-keyboard-event-key` is also off, because its unicorn 76 autofix is unsafe. The other **252** were audited as safe for SSJS; this is not a blanket runtime-safety guarantee. Of its **39** other current rules, which run only if you turn them on, **24** were audited as safe, **8** stay off (for example `prefer-temporal` and `prefer-error-is-error`) and **7** do not support JavaScript. The v80 audit also found 20 rules whose fixes or suggestions were already unsafe in v76 — 16 unchanged, 4 reaching more code in v80 (for example `value ||= "none"`, `1_133_955`, `"\u{E9}"`, `replaceAll`, arrow functions); they are off for both versions. A later check found four more in v80, plus `prefer-keyboard-event-key` in v76, whose fixes or suggestions write control characters in strings as `"\u{1b}"`-style escapes (for example the `no-useless-concat` autofix); they are off too.
|
|
206
206
|
|
|
207
|
-
**
|
|
207
|
+
**Supported unicorn versions: `>=57.0.0 <=80.0.0`** (optional peer dependency). 57.0.0 is the first ESM-only, flat-config-only unicorn. The ceiling is exactly the newest audited version: every unicorn release, patches included, can change what an autofix writes, so it is audited before `eslint-plugin-sfmc` allows it. Unicorn 76 and 80 were audited rule by rule; 77–79 are covered by the 76 → 80 comparison, and 57–75 were not audited. Unicorn 66 and later require ESLint **10.4.0+**; the base SFMC plugin supports ESLint 10.0.0+.
|
|
208
|
+
|
|
209
|
+
Add your unicorn config, then spread `sfmc.unicornSsjs(eslintPluginUnicorn)` **after** it. For standalone `.ssjs` files and SSJS embedded in HTML, it turns off every unicorn rule that the audits did not mark safe — including rules a newer unicorn adds or renames, and rules you enabled yourself. The rules audited as safe keep whatever your unicorn config sets. Pass the same unicorn object your config uses.
|
|
208
210
|
|
|
209
211
|
```js
|
|
210
212
|
import sfmc from 'eslint-plugin-sfmc';
|
|
@@ -218,19 +220,13 @@ export default [
|
|
|
218
220
|
},
|
|
219
221
|
...sfmc.configs.recommended,
|
|
220
222
|
...sfmc.configs.embedded, // AMPscript + SSJS embedded in HTML (<script runat="server">)
|
|
221
|
-
sfmc.
|
|
222
|
-
sfmc.configs['unicorn-ssjs-embedded'], // REQUIRED: protect SSJS embedded in HTML
|
|
223
|
+
...sfmc.unicornSsjs(eslintPluginUnicorn), // REQUIRED: only audited unicorn rules run on SSJS
|
|
223
224
|
];
|
|
224
225
|
```
|
|
225
226
|
|
|
226
|
-
| Config | Files | What it does |
|
|
227
|
-
| --------------------------------------- | ---------------- | --------------------------------------------------------- |
|
|
228
|
-
| `sfmc.configs['unicorn-ssjs']` | `**/*.ssjs` | Turns off the 60 SFMC-incompatible unicorn rules for SSJS |
|
|
229
|
-
| `sfmc.configs['unicorn-ssjs-embedded']` | `**/*.html/*.js` | Same 60-rule override for SSJS embedded in HTML |
|
|
230
|
-
|
|
231
227
|
Scope the complete Unicorn preset to JavaScript/SSJS, not custom AMPscript, Handlebars or MSO ASTs. Clearing its builtin map prevents modern globals leaking into SSJS; other matching configs can still supply globals. The SFMC presets do not enable general `no-undef` checking, and extracted HTML server blocks are linted independently.
|
|
232
228
|
|
|
233
|
-
|
|
229
|
+
The earlier setup still works: `sfmc.configs['unicorn-ssjs']` (`**/*.ssjs`) and `sfmc.configs['unicorn-ssjs-embedded']` (`**/*.html/*.js`) turn off exactly the 88 recommended rules, but not unaudited rules or the 8 unsafe rules outside the recommended set. If you don't use unicorn, omit all of these. For the full rule-by-rule breakdown (with rationale and SFMC evidence links), see [docs/unicorn-compatibility.md](docs/unicorn-compatibility.md).
|
|
234
230
|
|
|
235
231
|
## Processors
|
|
236
232
|
|