eslint-plugin-sfmc 4.7.0 → 4.8.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
@@ -128,7 +128,7 @@ export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-n
128
128
  | [`sfmc/ssjs-no-unsupported-syntax`](docs/rules/ssjs/no-unsupported-syntax.md) | `error` | Flag ES6+ syntax not supported by SFMC |
129
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
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 use of deprecated SFMC SSJS APIs (e.g. ContentArea, ErrorUtil) |
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
132
  | [`sfmc/ssjs-no-nonexistent-global`](docs/rules/ssjs/no-nonexistent-global.md) | `error` | Flag documented SSJS globals that throw ReferenceError at runtime |
133
133
  | [`sfmc/ssjs-no-property-call`](docs/rules/ssjs/no-property-call.md) | `error` | Disallow calling Platform.Request/Response properties as functions |
134
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` |
@@ -1,8 +1,9 @@
1
1
  # `sfmc/ssjs-no-deprecated-function`
2
2
 
3
- Flags calls to deprecated SFMC SSJS APIs, chiefly the **Content Areas** feature,
4
- which has been retired and no longer allows creating or updating content, plus the
5
- legacy `ErrorUtil` helper that only exists under the oldest Core version.
3
+ Flags calls to deprecated SFMC SSJS APIs, chiefly legacy **Classic Content / Classic
4
+ Email Studio** Core Library classes (Content Areas, Portfolios, Templates, Sends, and
5
+ Send Definitions), which have been superseded by Content Builder and Journey Builder,
6
+ plus the legacy `ErrorUtil` helper that only exists under the oldest Core version.
6
7
 
7
8
  ## What is flagged
8
9
 
@@ -12,11 +13,13 @@ legacy `ErrorUtil` helper that only exists under the oldest Core version.
12
13
  | `ContentAreaByName(…)` | Global alias; Content Areas are deprecated |
13
14
  | `Platform.Function.ContentArea(…)` | Content Areas are deprecated |
14
15
  | `Platform.Function.ContentAreaByName(…)` | Content Areas are deprecated |
15
- | `ContentAreaObj.Init(…)` | ContentAreaObj class is deprecated |
16
- | `ContentAreaObj.Add(…)` | ContentAreaObj class is deprecated |
17
- | `ContentAreaObj.Retrieve(…)` | ContentAreaObj class is deprecated |
18
- | `<contentAreaVar>.Update(…)` | Instance method on a deprecated ContentAreaObj variable |
19
- | `<contentAreaVar>.Remove()` | Instance method on a deprecated ContentAreaObj variable |
16
+ | `ContentAreaObj.Init(…)` / `.Add(…)` / `.Retrieve(…)` | `ContentAreaObj` class is deprecated |
17
+ | `<contentAreaVar>.Update(…)` / `.Remove()` | Instance method on a deprecated `ContentAreaObj` variable |
18
+ | `Portfolio.Init(…)` / `.Add(…)` / `.Retrieve(…)` (and instance `.Update(…)` / `.Remove()`) | `Portfolio` class is deprecated (legacy Classic Content) |
19
+ | `Template.Init(…)` / `.Add(…)` / `.Retrieve(…)` (and instance `.Update(…)`) | `Template` class is deprecated (legacy Classic Content) |
20
+ | `Send.Init(…)` / `.Add(…)` / `.Retrieve(…)` (and instance `.RetrieveLists(…)` / `.Remove()` / `.CancelSend()`) | `Send` class is deprecated (legacy Classic Content send) |
21
+ | `Send.Definition.Init(…)` / `.Add(…)` (and instance methods, e.g. `.Send()`) | `Send.Definition` class is deprecated (legacy Classic Content send definition) |
22
+ | `Email.*` | `Email` class is deprecated in favor of Content Builder / Journey Builder sends |
20
23
  | `ErrorUtil.ThrowWSProxyError(…)` | Only exists under `Platform.Load("Core", "1")`; undefined in newer Core versions — check `result.Status` and `throw new Error(…)` instead |
21
24
 
22
25
  ## Examples
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-sfmc",
3
- "version": "4.7.0",
3
+ "version": "4.8.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.0",
44
44
  "mso-conditional-parser": "^2.0.1",
45
- "ssjs-data": "^1.0.0"
45
+ "ssjs-data": "^1.1.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "eslint": ">=9.0.0"
@@ -7,18 +7,19 @@
7
7
  * - ContentAreaByName(...) — bare alias (use Platform.Function.ContentAreaByName instead)
8
8
  * - Platform.Function.ContentArea(...)
9
9
  * - Platform.Function.ContentAreaByName(...)
10
- * - ContentAreaObj.Init(...) — static method (class is deprecated)
11
- * - ContentAreaObj.Add(...) — static method
12
- * - ContentAreaObj.Retrieve(...) — static method
13
- * - <contentAreaObjVar>.Update(...) — instance method on a tracked ContentAreaObj variable
14
- * - <contentAreaObjVar>.Remove() — instance method on a tracked ContentAreaObj variable
10
+ * - Any Core Library class flagged `deprecated` in ssjs-data's coreDeprecatedMethodLookup
11
+ * (currently ContentAreaObj, Email, Portfolio, Template, Send, Send.Definition) —
12
+ * both static (`Portfolio.Retrieve(...)`) and instance
13
+ * (`var p = Portfolio.Init(...); p.Update(...)`) call styles, including
14
+ * multi-part static/instance paths (`Send.Definition.Add(...)`).
15
15
  * - ErrorUtil.ThrowWSProxyError(...) — deprecated; only exists under Platform.Load("Core", "1")
16
16
  */
17
17
 
18
18
  import {
19
19
  platformFunctionLookup,
20
20
  SSJS_GLOBALS,
21
- CONTENT_AREA_OBJ_METHODS,
21
+ coreObjectNames,
22
+ coreDeprecatedMethodLookup,
22
23
  ERROR_UTIL_METHODS,
23
24
  } from 'ssjs-data';
24
25
 
@@ -28,28 +29,83 @@ const DEPRECATED_GLOBALS = new Map(
28
29
  SSJS_GLOBALS.filter((g) => g.deprecated).map((g) => [g.name.toLowerCase(), g]),
29
30
  );
30
31
 
31
- // Build sets of deprecated static and instance methods from ssjs-data.
32
- // Exclude 'Init' — that call is already implicitly covered when we track the
33
- // returned instance and flag its instance methods. Reporting it here as well
34
- // would produce a duplicate error on the same statement.
35
- const CONTENT_AREA_STATIC_DEPRECATED = new Set(
36
- CONTENT_AREA_OBJ_METHODS.filter(
37
- (m) => m.deprecated && m.isStatic && m.name.toLowerCase() !== 'init',
38
- ).map((m) => m.name.toLowerCase()),
39
- );
40
-
41
- const CONTENT_AREA_INSTANCE_DEPRECATED = new Set(
42
- CONTENT_AREA_OBJ_METHODS.filter((m) => m.deprecated && !m.isStatic).map((m) =>
43
- m.name.toLowerCase(),
44
- ),
45
- );
46
-
47
32
  // Deprecated ErrorUtil methods (e.g. ThrowWSProxyError). Used to flag calls like
48
33
  // ErrorUtil.ThrowWSProxyError(result), which only exists under Platform.Load("Core", "1").
34
+ // ErrorUtil is not part of ssjs-data's coreObjectNames / coreDeprecatedMethodLookup (it has
35
+ // no Init-based instance form), so it is handled as its own special case.
49
36
  const ERRORUTIL_DEPRECATED = new Set(
50
37
  ERROR_UTIL_METHODS.filter((m) => m.deprecated).map((m) => m.name.toLowerCase()),
51
38
  );
52
39
 
40
+ /**
41
+ * Look up a deprecated method entry for a Core Library class.
42
+ *
43
+ * @param {string} className - Core Library class name (e.g. "Portfolio", "Send.Definition")
44
+ * @param {string} methodName - method name (e.g. "Retrieve")
45
+ * @returns {object|null} the ssjs-data method entry, or null when not deprecated
46
+ */
47
+ function findDeprecatedEntry(className, methodName) {
48
+ const classLookup = coreDeprecatedMethodLookup.get(className.toLowerCase());
49
+ if (!classLookup) {
50
+ return null;
51
+ }
52
+ return classLookup.get(methodName.toLowerCase()) || null;
53
+ }
54
+
55
+ /**
56
+ * Build a dotted member path string from a MemberExpression / Identifier chain.
57
+ *
58
+ * @param {object} node - the object node
59
+ * @returns {string|null} The dotted path, or null when the chain contains
60
+ * anything other than plain identifiers/member accesses.
61
+ */
62
+ function getMemberPath(node) {
63
+ if (node.type === 'Identifier') {
64
+ return node.name;
65
+ }
66
+ if (node.type === 'MemberExpression' && node.property.type === 'Identifier') {
67
+ const object = getMemberPath(node.object);
68
+ return object ? `${object}.${node.property.name}` : null;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ /**
74
+ * Resolve the Core Library class name for a `Class.Init(...)` /
75
+ * `A.B.Init(...)` call expression, e.g. `Portfolio.Init(...)` or
76
+ * `Send.Definition.Init(...)`.
77
+ *
78
+ * @param {object} node - the init expression node
79
+ * @returns {string|null} The resolved core class name, or null
80
+ */
81
+ function getCoreInitType(node) {
82
+ if (!node || node.type !== 'CallExpression') {
83
+ return null;
84
+ }
85
+ const callee = node.callee;
86
+ if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
87
+ return null;
88
+ }
89
+ if (callee.property.name !== 'Init') {
90
+ return null;
91
+ }
92
+ const objectPath = getMemberPath(callee.object);
93
+ return objectPath && coreObjectNames.has(objectPath) ? objectPath : null;
94
+ }
95
+
96
+ /**
97
+ * Extract the trailing "Deprecated — ..." sentence from a deprecated
98
+ * method's `description` so the message surfaces each class's specific
99
+ * reasoning (falls back to a generic note when none is present).
100
+ *
101
+ * @param {object} entry - ssjs-data method entry
102
+ * @returns {string} The deprecation sentence
103
+ */
104
+ function deprecationNote(entry) {
105
+ const match = /deprecated\s*—\s*(.+)$/i.exec(entry.description || '');
106
+ return match ? `Deprecated — ${match[1]}` : 'This API is deprecated.';
107
+ }
108
+
53
109
  export default {
54
110
  meta: {
55
111
  type: 'suggestion',
@@ -60,10 +116,9 @@ export default {
60
116
  deprecatedGlobal: "'{{name}}' is deprecated. {{replacement}}",
61
117
  deprecatedPlatformFunction:
62
118
  "'Platform.Function.{{name}}' is deprecated. Use a supported alternative.",
63
- deprecatedCoreStatic:
64
- "'ContentAreaObj.{{name}}' is deprecated. Content Areas are no longer supported.",
119
+ deprecatedCoreStatic: "'{{name}}' is deprecated. {{note}}",
65
120
  deprecatedCoreInstance:
66
- "'{{method}}' called on a ContentAreaObj variable is deprecated. Content Areas are no longer supported.",
121
+ "'{{method}}' called on a {{className}} variable is deprecated. {{note}}",
67
122
  deprecatedErrorUtil:
68
123
  "'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.",
69
124
  },
@@ -71,26 +126,34 @@ export default {
71
126
  },
72
127
 
73
128
  create(context) {
74
- // Track variable names assigned via ContentAreaObj.Init()
75
- const contentAreaVariables = new Set();
129
+ // Track variable names assigned via <CoreClass>.Init(...) → resolved class name,
130
+ // e.g. `var p = Portfolio.Init(...)` → coreVariables.set('p', 'Portfolio').
131
+ const coreVariables = new Map();
76
132
 
77
133
  return {
78
134
  VariableDeclaration(node) {
79
135
  for (const declaration of node.declarations) {
80
136
  if (
81
- declaration.init &&
82
- declaration.id &&
83
- declaration.id.type === 'Identifier' &&
84
- isContentAreaObjectInit(declaration.init)
137
+ !declaration.init ||
138
+ !declaration.id ||
139
+ declaration.id.type !== 'Identifier'
85
140
  ) {
86
- contentAreaVariables.add(declaration.id.name);
141
+ continue;
142
+ }
143
+ const coreType = getCoreInitType(declaration.init);
144
+ if (coreType) {
145
+ coreVariables.set(declaration.id.name, coreType);
87
146
  }
88
147
  }
89
148
  },
90
149
 
91
150
  AssignmentExpression(node) {
92
- if (node.left.type === 'Identifier' && isContentAreaObjectInit(node.right)) {
93
- contentAreaVariables.add(node.left.name);
151
+ if (node.left.type !== 'Identifier') {
152
+ return;
153
+ }
154
+ const coreType = getCoreInitType(node.right);
155
+ if (coreType) {
156
+ coreVariables.set(node.left.name, coreType);
94
157
  }
95
158
  },
96
159
 
@@ -113,15 +176,11 @@ export default {
113
176
  return;
114
177
  }
115
178
 
116
- if (callee.type !== 'MemberExpression') {
179
+ if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
117
180
  return;
118
181
  }
119
182
 
120
183
  const property = callee.property;
121
- if (property.type !== 'Identifier') {
122
- return;
123
- }
124
-
125
184
  const methodName = property.name;
126
185
 
127
186
  // ── Platform.Function.ContentArea(…) / ContentAreaByName(…) ───
@@ -143,20 +202,6 @@ export default {
143
202
  return;
144
203
  }
145
204
 
146
- // ── ContentAreaObj.Init/Add/Retrieve(…) — static deprecated ───
147
- if (
148
- callee.object.type === 'Identifier' &&
149
- callee.object.name === 'ContentAreaObj' &&
150
- CONTENT_AREA_STATIC_DEPRECATED.has(methodName.toLowerCase())
151
- ) {
152
- context.report({
153
- node: property,
154
- messageId: 'deprecatedCoreStatic',
155
- data: { name: methodName },
156
- });
157
- return;
158
- }
159
-
160
205
  // ── ErrorUtil.ThrowWSProxyError(…) — deprecated ───────────────
161
206
  if (
162
207
  callee.object.type === 'Identifier' &&
@@ -171,39 +216,52 @@ export default {
171
216
  return;
172
217
  }
173
218
 
174
- // ── <contentAreaVar>.Update/Remove() — instance deprecated ─────
175
- if (
176
- callee.object.type === 'Identifier' &&
177
- contentAreaVariables.has(callee.object.name) &&
178
- CONTENT_AREA_INSTANCE_DEPRECATED.has(methodName.toLowerCase())
179
- ) {
219
+ const objectPath = getMemberPath(callee.object);
220
+ if (!objectPath) {
221
+ return;
222
+ }
223
+
224
+ // ── Static call: Portfolio.Retrieve(…) / Send.Definition.Add(…) ──
225
+ // Exclude Init — that call is already implicitly covered when we
226
+ // track the returned instance and flag its instance methods.
227
+ // Reporting it here as well would produce a duplicate error on
228
+ // the same statement (e.g. `var p = Portfolio.Init(...)`).
229
+ if (coreObjectNames.has(objectPath) && methodName.toLowerCase() !== 'init') {
230
+ const entry = findDeprecatedEntry(objectPath, methodName);
231
+ if (entry) {
232
+ context.report({
233
+ node: property,
234
+ messageId: 'deprecatedCoreStatic',
235
+ data: {
236
+ name: `${objectPath}.${methodName}`,
237
+ note: deprecationNote(entry),
238
+ },
239
+ });
240
+ }
241
+ return;
242
+ }
243
+
244
+ // ── Instance call: <var>.Update(…) / <var>.SubPath.Method(…) where
245
+ // `var` was assigned from a tracked <CoreClass>.Init(...) call ────
246
+ const segments = objectPath.split('.');
247
+ const rootCoreType = coreVariables.get(segments[0]);
248
+ if (!rootCoreType) {
249
+ return;
250
+ }
251
+ const resolvedClass = [rootCoreType, ...segments.slice(1)].join('.');
252
+ const entry = findDeprecatedEntry(resolvedClass, methodName);
253
+ if (entry) {
180
254
  context.report({
181
255
  node: property,
182
256
  messageId: 'deprecatedCoreInstance',
183
- data: { method: methodName },
257
+ data: {
258
+ method: methodName,
259
+ className: resolvedClass,
260
+ note: deprecationNote(entry),
261
+ },
184
262
  });
185
263
  }
186
264
  },
187
265
  };
188
266
  },
189
267
  };
190
-
191
- /**
192
- * Returns true if `node` is a `ContentAreaObj.Init(…)` call.
193
- *
194
- * @param {import('eslint').Rule.Node} node - AST node to inspect
195
- * @returns {boolean} true when the node is a ContentAreaObj.Init call
196
- */
197
- function isContentAreaObjectInit(node) {
198
- if (!node || node.type !== 'CallExpression') {
199
- return false;
200
- }
201
- const callee = node.callee;
202
- return (
203
- callee.type === 'MemberExpression' &&
204
- callee.object.type === 'Identifier' &&
205
- callee.object.name === 'ContentAreaObj' &&
206
- callee.property.type === 'Identifier' &&
207
- callee.property.name === 'Init'
208
- );
209
- }