eslint-plugin-sfmc 4.9.1 → 4.10.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
|
@@ -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
|
|
131
|
-
| [`sfmc/ssjs-no-deprecated-function`](docs/rules/ssjs/no-deprecated-function.md) | `error` | Flag
|
|
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
|
|
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
|
+
| [`sfmc/ssjs-no-deprecated-function`](docs/rules/ssjs/no-deprecated-function.md) | `error` | Flag deprecated SFMC SSJS APIs (Classic Content classes, ErrorUtil); reports a stronger "undefined at runtime" message when the loaded Core version no longer provides the API |
|
|
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; autofix is withheld in files using `ErrorUtil` |
|
|
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
|
|
|
@@ -22,6 +22,23 @@ plus the legacy `ErrorUtil` helper that only exists under the oldest Core versio
|
|
|
22
22
|
| `Email.*` | `Email` class is deprecated in favor of Content Builder / Journey Builder sends |
|
|
23
23
|
| `ErrorUtil.ThrowWSProxyError(…)` | Only exists under `Platform.Load("Core", "1")`; undefined in newer Core versions — check `result.Status` and `throw new Error(…)` instead |
|
|
24
24
|
|
|
25
|
+
## `ErrorUtil` — two message variants
|
|
26
|
+
|
|
27
|
+
`ErrorUtil` is bound to a maximum Core version (`maxCoreVersion: "1"` in `ssjs-data`), so
|
|
28
|
+
the rule picks its wording from the `Platform.Load("Core", …)` version the file loads:
|
|
29
|
+
|
|
30
|
+
| Loaded Core version | Message | Meaning |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `"1"`, or no version argument, or no `Platform.Load` at all | *"… is deprecated …"* | The call works today, but the API is retired — migrate away from it |
|
|
33
|
+
| Anything above `"1"` (`"1.1.1"`, `"1.1.5"`, `"2"`, …) | *"… is undefined under Platform.Load("Core", "…") …"* | `ErrorUtil` does not exist at runtime — the call throws a `TypeError` |
|
|
34
|
+
|
|
35
|
+
The applicable load is the nearest preceding `Platform.Load("Core", …)`; when every load
|
|
36
|
+
appears after the call, the first one in the file is used (it still governs at runtime).
|
|
37
|
+
|
|
38
|
+
Because bumping the Core version would break such a file,
|
|
39
|
+
[`sfmc/ssjs-prefer-platform-load-version`](./prefer-platform-load-version.md) withholds
|
|
40
|
+
its autofix whenever `ErrorUtil` is used.
|
|
41
|
+
|
|
25
42
|
## Examples
|
|
26
43
|
|
|
27
44
|
### ❌ Incorrect
|
|
@@ -51,6 +51,14 @@ What the fix does:
|
|
|
51
51
|
- When the version argument is present but wrong: replaces the version string literal with the required version.
|
|
52
52
|
- When the version argument is missing entirely: inserts `, "1.1.5"` after the `"core"` argument.
|
|
53
53
|
|
|
54
|
+
### Files using `ErrorUtil` are reported but not fixed
|
|
55
|
+
|
|
56
|
+
`ErrorUtil` is provided only by `Platform.Load("Core", "1")` — under any newer version it is
|
|
57
|
+
`undefined` and calling it throws a `TypeError`. When the file contains an `ErrorUtil` usage,
|
|
58
|
+
the version is still reported but **no fix is attached**, so `eslint --fix` cannot silently
|
|
59
|
+
break working code. Migrate off `ErrorUtil` first (see
|
|
60
|
+
[`sfmc/ssjs-no-deprecated-function`](./no-deprecated-function.md)), then bump the version.
|
|
61
|
+
|
|
54
62
|
## Configuration Example
|
|
55
63
|
|
|
56
64
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-sfmc",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.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,7 +42,7 @@
|
|
|
42
42
|
"eslint-plugin-mso-email": "^2.0.0",
|
|
43
43
|
"handlebars-data": "^0.3.1",
|
|
44
44
|
"mso-conditional-parser": "^2.0.1",
|
|
45
|
-
"ssjs-data": "^1.
|
|
45
|
+
"ssjs-data": "^1.4.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"eslint": ">=9.0.0"
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* both static (`Portfolio.Retrieve(...)`) and instance
|
|
13
13
|
* (`var p = Portfolio.Init(...); p.Update(...)`) call styles, including
|
|
14
14
|
* multi-part static/instance paths (`Send.Definition.Add(...)`).
|
|
15
|
-
* - ErrorUtil.ThrowWSProxyError(...) — deprecated; only exists under Platform.Load("Core", "1")
|
|
15
|
+
* - ErrorUtil.ThrowWSProxyError(...) — deprecated; only exists under Platform.Load("Core", "1").
|
|
16
|
+
* When the file loads a Core version above the entry's `maxCoreVersion` the call is
|
|
17
|
+
* undefined at runtime, so the stronger `unavailableInCoreVersion` message is used.
|
|
16
18
|
*/
|
|
17
19
|
|
|
18
20
|
import {
|
|
@@ -21,6 +23,7 @@ import {
|
|
|
21
23
|
coreObjectNames,
|
|
22
24
|
coreDeprecatedMethodLookup,
|
|
23
25
|
ERROR_UTIL_METHODS,
|
|
26
|
+
maxCoreVersionLookup,
|
|
24
27
|
} from 'ssjs-data';
|
|
25
28
|
|
|
26
29
|
// Lookup Map: lowercase name → entry, for SSJS_GLOBALS entries that are deprecated.
|
|
@@ -93,6 +96,77 @@ function getCoreInitType(node) {
|
|
|
93
96
|
return objectPath && coreObjectNames.has(objectPath) ? objectPath : null;
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Detect `Platform.Load("core", …)` and return the version literal it loads.
|
|
101
|
+
*
|
|
102
|
+
* @param {object} node - a CallExpression node
|
|
103
|
+
* @returns {string|null} the version string, '' when the version argument is
|
|
104
|
+
* missing or not a string literal, or null when this is not a core load
|
|
105
|
+
*/
|
|
106
|
+
function getCoreLoadVersion(node) {
|
|
107
|
+
const callee = node.callee;
|
|
108
|
+
if (
|
|
109
|
+
callee.type !== 'MemberExpression' ||
|
|
110
|
+
callee.object.type !== 'Identifier' ||
|
|
111
|
+
callee.object.name !== 'Platform' ||
|
|
112
|
+
callee.property.type !== 'Identifier' ||
|
|
113
|
+
callee.property.name !== 'Load'
|
|
114
|
+
) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const arguments_ = node.arguments;
|
|
118
|
+
if (
|
|
119
|
+
arguments_.length === 0 ||
|
|
120
|
+
arguments_[0].type !== 'Literal' ||
|
|
121
|
+
typeof arguments_[0].value !== 'string' ||
|
|
122
|
+
arguments_[0].value.toLowerCase() !== 'core'
|
|
123
|
+
) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const versionArgument = arguments_[1];
|
|
127
|
+
if (
|
|
128
|
+
versionArgument &&
|
|
129
|
+
versionArgument.type === 'Literal' &&
|
|
130
|
+
typeof versionArgument.value === 'string'
|
|
131
|
+
) {
|
|
132
|
+
return versionArgument.value;
|
|
133
|
+
}
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Split a Core version string into three numeric segments, padding missing
|
|
139
|
+
* ones with 0 so "1" and "1.0.0" are equivalent.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} version - version string, e.g. "1" or "1.1.5"
|
|
142
|
+
* @returns {number[]} three numeric segments
|
|
143
|
+
*/
|
|
144
|
+
function parseCoreVersion(version) {
|
|
145
|
+
const parts = version.split('.').map((p) => Number(p) || 0);
|
|
146
|
+
while (parts.length < 3) {
|
|
147
|
+
parts.push(0);
|
|
148
|
+
}
|
|
149
|
+
return parts;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Compare two Core version strings ("1", "1.1.5", …) numerically.
|
|
154
|
+
*
|
|
155
|
+
* @param {string} a - left version
|
|
156
|
+
* @param {string} b - right version
|
|
157
|
+
* @returns {number} negative when a < b, 0 when equal, positive when a > b
|
|
158
|
+
*/
|
|
159
|
+
function compareCoreVersions(a, b) {
|
|
160
|
+
const left = parseCoreVersion(a);
|
|
161
|
+
const right = parseCoreVersion(b);
|
|
162
|
+
for (const [index, element] of left.entries()) {
|
|
163
|
+
if (element !== right[index]) {
|
|
164
|
+
return element - right[index];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
96
170
|
/**
|
|
97
171
|
* Extract the trailing "Deprecated — ..." sentence from a deprecated
|
|
98
172
|
* method's `description` so the message surfaces each class's specific
|
|
@@ -121,6 +195,8 @@ export default {
|
|
|
121
195
|
"'{{method}}' called on a {{className}} variable is deprecated. {{note}}",
|
|
122
196
|
deprecatedErrorUtil:
|
|
123
197
|
"'ErrorUtil.{{name}}' is deprecated — it only exists under Platform.Load(\"Core\", \"1\") and is undefined in newer Core versions. Check 'result.Status' and 'throw new Error(...)' instead.",
|
|
198
|
+
unavailableInCoreVersion:
|
|
199
|
+
'\'ErrorUtil.{{name}}\' is undefined under Platform.Load("Core", "{{version}}") — it only exists in Core version "{{max}}", so this call throws a TypeError at runtime. Check \'result.Status\' and \'throw new Error(...)\' instead.',
|
|
124
200
|
},
|
|
125
201
|
schema: [],
|
|
126
202
|
},
|
|
@@ -129,6 +205,11 @@ export default {
|
|
|
129
205
|
// Track variable names assigned via <CoreClass>.Init(...) → resolved class name,
|
|
130
206
|
// e.g. `var p = Portfolio.Init(...)` → coreVariables.set('p', 'Portfolio').
|
|
131
207
|
const coreVariables = new Map();
|
|
208
|
+
// Every Platform.Load("core", <version>) in the file, as { line, version }.
|
|
209
|
+
const coreLoads = [];
|
|
210
|
+
// ErrorUtil call sites, resolved to the applicable Core version on Program:exit
|
|
211
|
+
// (a load may appear after the usage in source order).
|
|
212
|
+
const errorUtilityUsages = [];
|
|
132
213
|
|
|
133
214
|
return {
|
|
134
215
|
VariableDeclaration(node) {
|
|
@@ -160,6 +241,13 @@ export default {
|
|
|
160
241
|
CallExpression(node) {
|
|
161
242
|
const callee = node.callee;
|
|
162
243
|
|
|
244
|
+
// ── Platform.Load("core", <version>) — remember for ErrorUtil ──
|
|
245
|
+
const loadedVersion = getCoreLoadVersion(node);
|
|
246
|
+
if (loadedVersion !== null) {
|
|
247
|
+
coreLoads.push({ line: node.loc.start.line, version: loadedVersion });
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
163
251
|
// ── Bare globals: ContentArea(…) and ContentAreaByName(…) ──────
|
|
164
252
|
if (callee.type === 'Identifier') {
|
|
165
253
|
const entry = DEPRECATED_GLOBALS.get(callee.name.toLowerCase());
|
|
@@ -203,16 +291,14 @@ export default {
|
|
|
203
291
|
}
|
|
204
292
|
|
|
205
293
|
// ── ErrorUtil.ThrowWSProxyError(…) — deprecated ───────────────
|
|
294
|
+
// Reported on Program:exit: the wording depends on the loaded Core
|
|
295
|
+
// version, which may be declared after this call site.
|
|
206
296
|
if (
|
|
207
297
|
callee.object.type === 'Identifier' &&
|
|
208
298
|
callee.object.name === 'ErrorUtil' &&
|
|
209
299
|
ERRORUTIL_DEPRECATED.has(methodName.toLowerCase())
|
|
210
300
|
) {
|
|
211
|
-
|
|
212
|
-
node: property,
|
|
213
|
-
messageId: 'deprecatedErrorUtil',
|
|
214
|
-
data: { name: methodName },
|
|
215
|
-
});
|
|
301
|
+
errorUtilityUsages.push({ node: property, name: methodName });
|
|
216
302
|
return;
|
|
217
303
|
}
|
|
218
304
|
|
|
@@ -271,6 +357,44 @@ export default {
|
|
|
271
357
|
});
|
|
272
358
|
}
|
|
273
359
|
},
|
|
360
|
+
|
|
361
|
+
'Program:exit'() {
|
|
362
|
+
const maxCoreVersion = maxCoreVersionLookup.get('errorutil')?.maxCoreVersion;
|
|
363
|
+
for (const usage of errorUtilityUsages) {
|
|
364
|
+
// The applicable load is the nearest preceding one; when the file
|
|
365
|
+
// only loads Core after the usage, that load still governs at
|
|
366
|
+
// runtime, so fall back to the first load in the file.
|
|
367
|
+
const usageLine = usage.node.loc.start.line;
|
|
368
|
+
const preceding = coreLoads.filter((l) => l.line <= usageLine);
|
|
369
|
+
const applicable = preceding.length > 0 ? preceding.at(-1) : coreLoads[0];
|
|
370
|
+
|
|
371
|
+
if (
|
|
372
|
+
maxCoreVersion &&
|
|
373
|
+
applicable &&
|
|
374
|
+
applicable.version &&
|
|
375
|
+
compareCoreVersions(applicable.version, maxCoreVersion) > 0
|
|
376
|
+
) {
|
|
377
|
+
context.report({
|
|
378
|
+
node: usage.node,
|
|
379
|
+
messageId: 'unavailableInCoreVersion',
|
|
380
|
+
data: {
|
|
381
|
+
name: usage.name,
|
|
382
|
+
version: applicable.version,
|
|
383
|
+
max: maxCoreVersion,
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// No core load at all, no version argument, or a version within the
|
|
390
|
+
// supported range — ssjs-require-platform-load owns the missing-load case.
|
|
391
|
+
context.report({
|
|
392
|
+
node: usage.node,
|
|
393
|
+
messageId: 'deprecatedErrorUtil',
|
|
394
|
+
data: { name: usage.name },
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
},
|
|
274
398
|
};
|
|
275
399
|
},
|
|
276
400
|
};
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
* Warns when Platform.Load("Core", version) uses a version string other
|
|
5
5
|
* than the recommended "1.1.5". Older versions like "1" or "1.1.1" miss
|
|
6
6
|
* bug-fixes and features available in the latest Core library release.
|
|
7
|
+
*
|
|
8
|
+
* The autofix is withheld for files that use `ErrorUtil`, which only exists
|
|
9
|
+
* under Core "1" — bumping the version there would turn working code into a
|
|
10
|
+
* runtime TypeError. Such files must migrate off ErrorUtil first.
|
|
7
11
|
*/
|
|
8
12
|
|
|
9
13
|
const DEFAULT_VERSION = '1.1.5';
|
|
@@ -36,8 +40,18 @@ export default {
|
|
|
36
40
|
create(context) {
|
|
37
41
|
const options = context.options[0] || {};
|
|
38
42
|
const expectedVersion = options.version || DEFAULT_VERSION;
|
|
43
|
+
// Pending reports — resolved on Program:exit so the ErrorUtil scan is
|
|
44
|
+
// complete before deciding whether to attach a fixer.
|
|
45
|
+
const pendingReports = [];
|
|
46
|
+
let isUsesErrorUtility = false;
|
|
39
47
|
|
|
40
48
|
return {
|
|
49
|
+
MemberExpression(node) {
|
|
50
|
+
if (node.object.type === 'Identifier' && node.object.name === 'ErrorUtil') {
|
|
51
|
+
isUsesErrorUtility = true;
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
41
55
|
CallExpression(node) {
|
|
42
56
|
const callee = node.callee;
|
|
43
57
|
if (
|
|
@@ -61,13 +75,11 @@ export default {
|
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
if (arguments_.length < 2) {
|
|
64
|
-
|
|
78
|
+
pendingReports.push({
|
|
65
79
|
node,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return fixer.insertTextAfter(arguments_[0], `, "${expectedVersion}"`);
|
|
70
|
-
},
|
|
80
|
+
actual: '(none)',
|
|
81
|
+
fix: (fixer) =>
|
|
82
|
+
fixer.insertTextAfter(arguments_[0], `, "${expectedVersion}"`),
|
|
71
83
|
});
|
|
72
84
|
return;
|
|
73
85
|
}
|
|
@@ -78,13 +90,23 @@ export default {
|
|
|
78
90
|
typeof versionArgument.value === 'string' &&
|
|
79
91
|
versionArgument.value !== expectedVersion
|
|
80
92
|
) {
|
|
81
|
-
|
|
93
|
+
pendingReports.push({
|
|
82
94
|
node: versionArgument,
|
|
95
|
+
actual: versionArgument.value,
|
|
96
|
+
fix: (fixer) => fixer.replaceText(versionArgument, `"${expectedVersion}"`),
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
'Program:exit'() {
|
|
102
|
+
for (const report of pendingReports) {
|
|
103
|
+
context.report({
|
|
104
|
+
node: report.node,
|
|
83
105
|
messageId: 'outdatedVersion',
|
|
84
|
-
data: { actual:
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
106
|
+
data: { actual: report.actual, expected: expectedVersion },
|
|
107
|
+
// Bumping the Core version would make ErrorUtil undefined at
|
|
108
|
+
// runtime, so the fix is withheld and only the report remains.
|
|
109
|
+
...(!isUsesErrorUtility && { fix: report.fix }),
|
|
88
110
|
});
|
|
89
111
|
}
|
|
90
112
|
},
|