eslint-plugin-sfmc 5.0.0 → 5.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
CHANGED
|
@@ -57,6 +57,18 @@ Add the following to your `.vscode/settings.json`:
|
|
|
57
57
|
|
|
58
58
|
> **Why `eslint.validate` and not `eslint.probe`?** `eslint.probe` silently skips files for language IDs that the ESLint extension does not natively recognise. `eslint.validate` forces the extension to process those files regardless of language ID.
|
|
59
59
|
|
|
60
|
+
## Diagnostic documentation links
|
|
61
|
+
|
|
62
|
+
SFMC rule metadata links to the owning plugin version's documentation under `blob/v<package-version>/docs/rules/`. These links also work with custom plugin namespaces. Local development uses the package version deterministically; links for a prospective release may not resolve until that version and its documentation are tagged and published. ESLint parser failures (`ruleId: null`) have no rule metadata link. Core and third-party rules retain their own documentation metadata.
|
|
63
|
+
|
|
64
|
+
### 5.1.0 release notes
|
|
65
|
+
|
|
66
|
+
- All 52 exported SFMC rules now expose version-pinned documentation metadata; the plugin metadata version comes from its own package rather than a hardcoded constant.
|
|
67
|
+
- Added the missing [SSJS switch fallthrough reference](docs/rules/ssjs/no-switch-fallthrough.md). Existing rule IDs, configurations, severities, and fixes are unchanged.
|
|
68
|
+
- Release checks verify the producer's tagged documentation and metadata in the packed npm artifact.
|
|
69
|
+
|
|
70
|
+
Version **5.1.0** adds these links without changing rule IDs or configuration shapes. It also adopts `ssjs-data@^2.1.0`: eight additional static/prototype methods receive unavailable-method guidance without a polyfill suggestion. The catalog's ninth addition, bare `structuredClone()`, remains outside this member-call rule's coverage. The evidence comes from tested Engagement CloudPages, not email or every execution context. No verified polyfill is bundled for these additions.
|
|
71
|
+
|
|
60
72
|
## Configs
|
|
61
73
|
|
|
62
74
|
### Marketing Cloud Engagement (default)
|
|
@@ -145,9 +157,12 @@ export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-n
|
|
|
145
157
|
| [`sfmc/ssjs-no-nonfunctional-method`](docs/rules/ssjs/no-nonfunctional-method.md) | `warn` | Flag Core Library methods that never take effect at runtime |
|
|
146
158
|
| [`sfmc/ssjs-prefer-parsejson-safe-arg`](docs/rules/ssjs/prefer-parsejson-safe-arg.md) | `warn` | Require string coercion on `ParseJSON` argument |
|
|
147
159
|
| [`sfmc/ssjs-no-switch-default`](docs/rules/ssjs/no-switch-default.md) | `warn` | Disallow `default` clause in `switch` statements |
|
|
160
|
+
| [`sfmc/ssjs-no-switch-fallthrough`](docs/rules/ssjs/no-switch-fallthrough.md) | `warn` | Flag stacked labels and unterminated clauses that rely on switch fall-through |
|
|
148
161
|
| [`sfmc/ssjs-no-treatascontent-injection`](docs/rules/ssjs/no-treatascontent-injection.md) | `warn` | Flag dynamic string concatenation in `TreatAsContent` calls |
|
|
149
162
|
| [`sfmc/ssjs-core-method-arity`](docs/rules/ssjs/core-method-arity.md) | `warn` | Enforce correct argument counts for Core Library object methods |
|
|
150
163
|
| [`sfmc/ssjs-arg-types`](docs/rules/ssjs/arg-types.md) | `warn` | Check that literal arguments match expected parameter types |
|
|
164
|
+
| [`sfmc/ssjs-http-property-value`](docs/rules/ssjs/http-property-value.md) | `error` | Validate literal HTTP request property values |
|
|
165
|
+
| [`sfmc/ssjs-no-invalid-property-access`](docs/rules/ssjs/no-invalid-property-access.md) | `error` | Flag reads of write-only properties and writes to read-only properties |
|
|
151
166
|
|
|
152
167
|
## Handlebars Rules (`hbs-*`)
|
|
153
168
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# `sfmc/ssjs-no-switch-fallthrough`
|
|
2
|
+
|
|
3
|
+
Flag switch clauses that appear to depend on execution continuing into the next clause.
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
Marketing Cloud Engagement's SSJS engine does not implement JavaScript switch fall-through. Stacked labels therefore do not share the following body, and an unterminated case does not execute the next case's statements. Code that assumes either behavior can silently skip work.
|
|
8
|
+
|
|
9
|
+
## What this rule reports
|
|
10
|
+
|
|
11
|
+
- An empty case or default clause before another clause: for example, two adjacent case labels with a single shared body.
|
|
12
|
+
- A non-final clause whose last statement is not a break, return, throw, or continue: for example, an assignment followed immediately by the next case label.
|
|
13
|
+
|
|
14
|
+
The final clause is not reported because there is no subsequent clause to enter. A non-final clause ending directly in a terminating statement is accepted. This is a structural check, not control-flow analysis: a clause ending in an if statement can still be reported even when all its branches return.
|
|
15
|
+
|
|
16
|
+
## How to fix
|
|
17
|
+
|
|
18
|
+
Use an if/else chain when multiple values should perform the same work. Alternatively, give each case its own explicit body and terminator rather than stacking labels or expecting execution to cascade. A final clause needs no fall-through correction.
|
|
19
|
+
|
|
20
|
+
Adding break makes intent explicit, but does not repair code that actually needs the next case's work. Move that shared work into an explicit shared path instead. Also consider the separate function-scoped switch/break engine hazard described by [no-switch-default](no-switch-default.md); an if/else chain avoids both issues.
|
|
21
|
+
|
|
22
|
+
## Configuration and applicability
|
|
23
|
+
|
|
24
|
+
This rule has no options or automatic fix. It is enabled at warning severity in the Engagement recommended and embedded configurations, and error severity in strict configurations. It applies to standalone and HTML-embedded SSJS. Next configurations disable this rule and report SSJS as unsupported instead.
|
|
25
|
+
|
|
26
|
+
To suppress an intentional empty or unterminated clause, configure `sfmc/ssjs-no-switch-fallthrough` as `off`, or use a narrowly scoped ESLint disable-next-line comment naming this rule and explaining why the clause does not depend on fall-through. Replace `sfmc` with your configured plugin namespace if using an alias.
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
> Flag Array methods that are unavailable or broken in SFMC SSJS and suggest inserting a polyfill.
|
|
4
4
|
|
|
5
|
-
|
|
|
6
|
-
|
|
7
|
-
| **Type**
|
|
8
|
-
| **Default severity** | `warn` in `recommended` and `strict`
|
|
9
|
-
| **Fixable**
|
|
5
|
+
| | |
|
|
6
|
+
| -------------------- | ----------------------------------------------------- |
|
|
7
|
+
| **Type** | `problem` |
|
|
8
|
+
| **Default severity** | `warn` in `recommended` and `strict` |
|
|
9
|
+
| **Fixable** | **Suggestion** only (lightbulb / `Ctrl+.` in VS Code) |
|
|
10
10
|
|
|
11
11
|
## Why This Rule Exists
|
|
12
12
|
|
|
@@ -26,32 +26,46 @@ the language-server quick-fix so both tools place polyfills consistently.
|
|
|
26
26
|
|
|
27
27
|
## Covered methods
|
|
28
28
|
|
|
29
|
-
| Method
|
|
30
|
-
|
|
31
|
-
| `Array.prototype.copyWithin`
|
|
32
|
-
| `Array.prototype.entries`
|
|
33
|
-
| `Array.prototype.fill`
|
|
34
|
-
| `Array.prototype.filter`
|
|
35
|
-
| `Array.prototype.find`
|
|
36
|
-
| `Array.prototype.findIndex`
|
|
37
|
-
| `Array.prototype.forEach`
|
|
38
|
-
| `Array.prototype.includes`
|
|
39
|
-
| `Array.prototype.indexOf`
|
|
40
|
-
| `Array.prototype.lastIndexOf` | broken
|
|
41
|
-
| `Array.prototype.map`
|
|
42
|
-
| `Array.prototype.reduce`
|
|
43
|
-
| `Array.prototype.reduceRight` | unavailable |
|
|
44
|
-
| `Array.prototype.some`
|
|
45
|
-
| `Array.prototype.splice`
|
|
46
|
-
| `Array.isArray`
|
|
47
|
-
| `Array.of`
|
|
29
|
+
| Method | Category | Notes |
|
|
30
|
+
| ----------------------------- | ----------- | --------------------------------------------------------------- |
|
|
31
|
+
| `Array.prototype.copyWithin` | unavailable | |
|
|
32
|
+
| `Array.prototype.entries` | unavailable | Returns a minimal iterator; `for...of` is also unsupported |
|
|
33
|
+
| `Array.prototype.fill` | unavailable | |
|
|
34
|
+
| `Array.prototype.filter` | unavailable | |
|
|
35
|
+
| `Array.prototype.find` | unavailable | |
|
|
36
|
+
| `Array.prototype.findIndex` | unavailable | |
|
|
37
|
+
| `Array.prototype.forEach` | unavailable | |
|
|
38
|
+
| `Array.prototype.includes` | unavailable | |
|
|
39
|
+
| `Array.prototype.indexOf` | unavailable | Only flagged on array literals; string `.indexOf()` still works |
|
|
40
|
+
| `Array.prototype.lastIndexOf` | broken | Natively always returns `-1` |
|
|
41
|
+
| `Array.prototype.map` | unavailable | |
|
|
42
|
+
| `Array.prototype.reduce` | unavailable | |
|
|
43
|
+
| `Array.prototype.reduceRight` | unavailable | |
|
|
44
|
+
| `Array.prototype.some` | unavailable | |
|
|
45
|
+
| `Array.prototype.splice` | broken | Natively ignores `startIndex` and `deleteCount` |
|
|
46
|
+
| `Array.isArray` | unavailable | |
|
|
47
|
+
| `Array.of` | unavailable | |
|
|
48
|
+
|
|
49
|
+
## Catalog entries without bundled polyfills
|
|
50
|
+
|
|
51
|
+
The rule also reads `KNOWN_UNSUPPORTED` from `ssjs-data`. These reports carry the
|
|
52
|
+
catalog's guidance but no automatic fix or polyfill insertion suggestion. Absence
|
|
53
|
+
of a bundled verified polyfill does not mean a polyfill is impossible.
|
|
54
|
+
|
|
55
|
+
With `ssjs-data` 2.1.0, this includes `Object.fromEntries`, `Object.groupBy`,
|
|
56
|
+
`Array.prototype.toReversed`, `toSorted`, `toSpliced`, `findLastIndex`, and
|
|
57
|
+
`String.prototype.replaceAll` and `matchAll`. Their absence was checked in
|
|
58
|
+
Engagement CloudPages before Core loading and with Core 1.1.1 and 1.1.5; email and
|
|
59
|
+
other contexts were not tested. The catalog also records global `structuredClone`,
|
|
60
|
+
but this rule examines member calls, not bare global calls, so it does not report
|
|
61
|
+
`structuredClone()`.
|
|
48
62
|
|
|
49
63
|
## Settings
|
|
50
64
|
|
|
51
|
-
| Setting
|
|
52
|
-
|
|
53
|
-
| severity | `"error"` \| `"warn"` \| `"off"`
|
|
54
|
-
| `ignore` | Array of method names to suppress | `[]`
|
|
65
|
+
| Setting | Values | Default |
|
|
66
|
+
| -------- | --------------------------------- | -------- |
|
|
67
|
+
| severity | `"error"` \| `"warn"` \| `"off"` | `"warn"` |
|
|
68
|
+
| `ignore` | Array of method names to suppress | `[]` |
|
|
55
69
|
|
|
56
70
|
Use `ignore` when polyfills are loaded externally via a Content Block or Code Resource
|
|
57
71
|
that runs before your script.
|
|
@@ -69,9 +83,11 @@ rules: {
|
|
|
69
83
|
|
|
70
84
|
```js
|
|
71
85
|
var nums = [1, 2, 3];
|
|
72
|
-
var doubled = nums.map(function (n) {
|
|
86
|
+
var doubled = nums.map(function (n) {
|
|
87
|
+
return n * 2;
|
|
88
|
+
}); // unavailable
|
|
73
89
|
|
|
74
|
-
var pos = nums.lastIndexOf(2);
|
|
90
|
+
var pos = nums.lastIndexOf(2); // broken — always returns -1 natively
|
|
75
91
|
|
|
76
92
|
var found = Array.isArray(nums); // unavailable
|
|
77
93
|
```
|
|
@@ -80,9 +96,13 @@ var found = Array.isArray(nums); // unavailable
|
|
|
80
96
|
|
|
81
97
|
```js
|
|
82
98
|
// Polyfill defined in the same file — rule is suppressed
|
|
83
|
-
Array.prototype.map = function (callback) {
|
|
99
|
+
Array.prototype.map = function (callback) {
|
|
100
|
+
/* ... */
|
|
101
|
+
};
|
|
84
102
|
|
|
85
|
-
var doubled = nums.map(function (n) {
|
|
103
|
+
var doubled = nums.map(function (n) {
|
|
104
|
+
return n * 2;
|
|
105
|
+
}); // ok
|
|
86
106
|
|
|
87
107
|
// Native methods that work correctly are never flagged
|
|
88
108
|
nums.push(4);
|
|
@@ -102,14 +122,18 @@ rules: {
|
|
|
102
122
|
|
|
103
123
|
```js
|
|
104
124
|
// No warning — 'map' and 'filter' are in the ignore list
|
|
105
|
-
var doubled = nums.map(function (n) {
|
|
106
|
-
|
|
125
|
+
var doubled = nums.map(function (n) {
|
|
126
|
+
return n * 2;
|
|
127
|
+
});
|
|
128
|
+
var evens = nums.filter(function (n) {
|
|
129
|
+
return n % 2 === 0;
|
|
130
|
+
});
|
|
107
131
|
```
|
|
108
132
|
|
|
109
133
|
## Suggestion (lightbulb)
|
|
110
134
|
|
|
111
|
-
When a
|
|
112
|
-
|
|
135
|
+
When a bundled verified polyfill exists, a suggestion is available to insert it
|
|
136
|
+
at the **top of the file**, after a leading global directive if present. Apply it via:
|
|
113
137
|
|
|
114
138
|
- Click the **lightbulb** or press `Ctrl+.` in VS Code (requires the ESLint extension)
|
|
115
139
|
- `eslint --fix` does **not** apply suggestions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sfmc",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
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",
|
|
@@ -42,13 +42,15 @@
|
|
|
42
42
|
"handlebars-data": "^0.4.0",
|
|
43
43
|
"mso-conditional-parser": "^2.0.1",
|
|
44
44
|
"sfmc-handlebars-parser": "^0.1.1",
|
|
45
|
-
"ssjs-data": "^2.
|
|
45
|
+
"ssjs-data": "^2.1.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"eslint": ">=10.4.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
|
-
"test": "node --test tests/rules.test.js && node --test tests/deprecated-catalog.test.js && node --test tests/fixtures.test.mjs && node --test tests/autofix-manual.test.mjs && node --test tests/unicorn-protection.test.js tests/unicorn-hazards.test.js tests/unicorn-configs.test.js && node --test tests/unicorn-minimum.test.js",
|
|
51
|
+
"test": "node --test tests/release-safeguards.test.js tests/metadata.test.js && node --test tests/rules.test.js && node --test tests/deprecated-catalog.test.js && node --test tests/fixtures.test.mjs && node --test tests/autofix-manual.test.mjs && node --test tests/unicorn-protection.test.js tests/unicorn-hazards.test.js tests/unicorn-configs.test.js && node --test tests/unicorn-minimum.test.js",
|
|
52
|
+
"test:release": "node --test tests/release-safeguards.test.js",
|
|
53
|
+
"validate:release-docs": "node scripts/validate-release-documentation.js",
|
|
52
54
|
"test:autofix-manual": "node --test tests/autofix-manual.test.mjs",
|
|
53
55
|
"test:fixtures": "node --test tests/fixtures.test.mjs",
|
|
54
56
|
"test:fixtures:update": "node --test tests/fixtures.test.mjs -- --update-snapshots",
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* - vscode-sfmc-language (IntelliSense, diagnostics)
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
12
13
|
import * as ampscriptParser from './ampscript-parser.js';
|
|
13
14
|
import * as handlebarsParser from './handlebars-parser.js';
|
|
14
15
|
|
|
@@ -94,10 +95,12 @@ import { SSJS_GLOBALS_MAP } from 'ssjs-data';
|
|
|
94
95
|
|
|
95
96
|
// ── Plugin definition ─────────────────────────────────────────────────────────
|
|
96
97
|
|
|
98
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
99
|
+
|
|
97
100
|
const plugin = {
|
|
98
101
|
meta: {
|
|
99
102
|
name: 'eslint-plugin-sfmc',
|
|
100
|
-
version
|
|
103
|
+
version,
|
|
101
104
|
},
|
|
102
105
|
|
|
103
106
|
rules: {
|
|
@@ -167,6 +170,21 @@ const plugin = {
|
|
|
167
170
|
},
|
|
168
171
|
};
|
|
169
172
|
|
|
173
|
+
// Derive paths from public IDs, not source filenames or the configured namespace.
|
|
174
|
+
for (const [ruleId, rule] of Object.entries(plugin.rules)) {
|
|
175
|
+
const documentationPath = ruleId.replace('-', '/');
|
|
176
|
+
plugin.rules[ruleId] = {
|
|
177
|
+
...rule,
|
|
178
|
+
meta: {
|
|
179
|
+
...rule.meta,
|
|
180
|
+
docs: {
|
|
181
|
+
...rule.meta.docs,
|
|
182
|
+
url: `https://github.com/JoernBerkefeld/eslint-plugin-sfmc/blob/v${version}/docs/rules/${documentationPath}.md`,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
170
188
|
// ── MCN SSJS rule set (all SSJS rules off except ssjs-no-unknown-function) ────
|
|
171
189
|
|
|
172
190
|
/**
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* 1. POLYFILLABLE_METHODS — a shipped ES3-safe polyfill exists. The report
|
|
10
10
|
* carries a suggestion that inserts the polyfill at the top of the file.
|
|
11
|
-
* 2. KNOWN_UNSUPPORTED — no polyfill is
|
|
11
|
+
* 2. KNOWN_UNSUPPORTED — no verified polyfill is bundled. The report has no fix; the
|
|
12
12
|
* message carries the ssjs-data `suggestion` (e.g. use Platform.Function.X).
|
|
13
13
|
*
|
|
14
14
|
* - category 'unavailable': method does not exist; calling it throws a runtime error.
|
|
@@ -250,7 +250,7 @@ export default {
|
|
|
250
250
|
const ownerDisplay = entry.owner.replace(/\.prototype$/, '');
|
|
251
251
|
|
|
252
252
|
if (noPolyfill) {
|
|
253
|
-
// No polyfill is
|
|
253
|
+
// No verified polyfill is bundled — report with the ssjs-data suggestion
|
|
254
254
|
// and no auto-insert fix.
|
|
255
255
|
context.report({
|
|
256
256
|
node,
|