eslint-plugin-sfmc 4.14.0 → 4.16.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
@@ -109,6 +109,7 @@ export default [...sfmc.configs['recommended-next'], ...sfmc.configs['embedded-n
109
109
  | [`sfmc/amp-no-loop-counter-assign`](docs/rules/amp/no-loop-counter-assign.md) | `warn` | Disallow assigning to the `for` loop counter |
110
110
  | [`sfmc/amp-no-inline-statement`](docs/rules/amp/no-inline-statement.md) | `warn` | Disallow statements inside inline expressions |
111
111
  | [`sfmc/amp-no-deprecated-function`](docs/rules/amp/no-deprecated-function.md) | `warn` | Flag deprecated functions and suggest replacements |
112
+ | [`sfmc/amp-no-nonfunctional-function`](docs/rules/amp/no-nonfunctional-function.md) | `error` | Flag functions that resolve but have no working runtime invocation |
112
113
  | [`sfmc/amp-naming-convention`](docs/rules/amp/naming-convention.md) | `warn` | Enforce variable naming convention |
113
114
  | [`sfmc/amp-no-empty-then`](docs/rules/amp/no-empty-then.md) | `warn` | Disallow IF with empty THEN branch |
114
115
  | [`sfmc/amp-require-rowcount-check`](docs/rules/amp/require-rowcount-check.md) | `warn` | Require RowCount check before FOR on LookupRows |
@@ -0,0 +1,55 @@
1
+ # `sfmc/amp-no-nonfunctional-function`
2
+
3
+ > Flag AMPscript functions that resolve at runtime but have no known working invocation.
4
+
5
+ | | |
6
+ |---|---|
7
+ | **Type** | `problem` |
8
+ | **Default severity** | `error` in `recommended` and `strict` |
9
+ | **Fixable** | No — there is no replacement to auto-apply |
10
+
11
+ ## Why This Rule Exists
12
+
13
+ A handful of catalogued AMPscript functions still parse and resolve, yet every reached call aborts the page at runtime. This happens when the platform capability the function depends on has been retired (for example Classic Portfolio behind `GetPortfolioItem`, or Classic Content behind `GetPublishedSocialContent`), or when the integration it targets has no working call shape (the MSCRM family).
14
+
15
+ These functions are deliberately kept in completions and hover — they exist in the language — but calling one is always a bug, so the call site is flagged. This is distinct from deprecation: Salesforce never issued a formal sunset notice or a drop-in replacement, so `amp-no-deprecated-function` does not cover them.
16
+
17
+ In Marketing Cloud Next targets these same functions are already reported by `amp-no-mcn-unsupported`, so this rule is disabled in the `-next` configs to avoid a duplicate diagnostic.
18
+
19
+ ## Settings
20
+
21
+ | Setting | Values | Default |
22
+ |---------|--------|---------|
23
+ | severity | `"error"` \| `"warn"` \| `"off"` | `"error"` |
24
+
25
+ This rule has no configuration options.
26
+
27
+ ### Examples
28
+
29
+ **Not allowed:**
30
+
31
+ ```ampscript
32
+ %%[
33
+ var @item
34
+ set @item = GetPortfolioItem("my-portfolio-key")
35
+
36
+ var @social
37
+ set @social = GetPublishedSocialContent("socialContentId")
38
+ ]%%
39
+ ```
40
+
41
+ **Allowed:**
42
+
43
+ ```ampscript
44
+ %%[
45
+ var @block
46
+ set @block = ContentBlockByKey("my-block-key")
47
+ ]%%
48
+ ```
49
+
50
+ ## When to Disable
51
+
52
+ ```js
53
+ // eslint.config.js
54
+ rules: { 'sfmc/amp-no-nonfunctional-function': 'off' }
55
+ ```
@@ -1,37 +1,51 @@
1
1
  # `sfmc/ssjs-no-switch-default`
2
2
 
3
- Disallow `default` case in `switch` statements.
3
+ Discourage relying on a `default` case in `switch` statements.
4
4
 
5
5
  ## Why
6
6
 
7
- SFMC's SSJS engine may silently skip the `default` case in `switch` statements. This is a known engine bug that causes code in the `default` block to never execute, leading to hard-to-debug logic errors.
7
+ Community lore held that the `default` case of a `switch` "may not execute" in SFMC SSJS. Live CloudPage probing disproved that framing: a last-clause `default` on a no-match path executes reliably.
8
+
9
+ The real defect is in the underlying [Jint](https://github.com/sebastienros/jint) engine that SFMC SSJS runs on. Because of [jint#2607](https://github.com/sebastienros/jint/pull/2607), an executed `break` inside a `switch` that sits inside a **function** can abnormally complete the function — the function returns `undefined` and any statements after the `switch` are skipped. The fault is intermittent across compilations. When the swallowed code was the caller's fallback (often reached via `default`), it looks like "`default` didn't run", but the trigger is the executed `break`, not the `default` keyword.
10
+
11
+ Detecting the `break`-in-function-scoped-`switch` case precisely is out of scope for a lint rule, so this rule flags the `default` clause as a cheap heuristic hint: a `switch` that leans on `default` is exactly the shape most likely to depend on this fragile control flow.
8
12
 
9
13
  ## Recommended approach
10
14
 
11
- Enumerate all expected values as explicit `case` labels:
15
+ Prefer a lookup map or `if`/`else if` for control flow that must survive a `break`:
12
16
 
13
17
  ```js
14
- // Bad -- 'default' may not execute
15
- switch (status) {
16
- case 'active':
17
- doActive();
18
- break;
19
- default:
20
- doFallback();
21
- break;
18
+ // Bad -- function-scoped switch/break; return may be skipped, caller sees undefined
19
+ function classify(status) {
20
+ var out = 'PRE';
21
+ switch (status) {
22
+ case 'active':
23
+ out = 'A';
24
+ break;
25
+ default:
26
+ out = 'DEF';
27
+ }
28
+ return out;
29
+ }
30
+
31
+ // Good -- lookup map, no switch/break to escape
32
+ function classify(status) {
33
+ var map = { active: 'A' };
34
+ return map[status] || 'DEF';
22
35
  }
23
36
 
24
- // Good -- explicit cases
25
- switch (status) {
26
- case 'active':
27
- doActive();
28
- break;
29
- case 'inactive':
30
- doFallback();
31
- break;
37
+ // Good -- if / else if
38
+ function classify(status) {
39
+ if (status === 'active') return 'A';
40
+ return 'DEF';
32
41
  }
33
42
  ```
34
43
 
44
+ ## Related
45
+
46
+ - ssjs.guide known bug: [`switch` `break` can escape a function](https://ssjs.guide/engine-limitations/known-bugs/#switch-break-escape)
47
+ - Upstream fix: [jint#2607](https://github.com/sebastienros/jint/pull/2607)
48
+
35
49
  ## Settings
36
50
 
37
51
  This rule has no options.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-sfmc",
3
- "version": "4.14.0",
3
+ "version": "4.16.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",
@@ -37,12 +37,12 @@
37
37
  ],
38
38
  "dependencies": {
39
39
  "@handlebars/parser": "^2.2.2",
40
- "ampscript-data": "^3.4.0",
40
+ "ampscript-data": "^4.0.0",
41
41
  "ampscript-parser": "^0.3.1",
42
42
  "eslint-plugin-mso-email": "^2.0.0",
43
- "handlebars-data": "^0.3.1",
43
+ "handlebars-data": "^0.4.0",
44
44
  "mso-conditional-parser": "^2.0.1",
45
- "ssjs-data": "^1.6.0"
45
+ "ssjs-data": "^2.0.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "eslint": ">=9.0.0"
package/src/index.js CHANGED
@@ -28,6 +28,7 @@ import ampFunctionArity from './rules/amp/function-arity.js';
28
28
  import ampArgumentTypes from './rules/amp/argument-types.js';
29
29
  import ampNoEmailExcludedFunction from './rules/amp/no-email-excluded-function.js';
30
30
  import ampNoDeprecatedFunction from './rules/amp/no-deprecated-function.js';
31
+ import ampNoNonfunctionalFunction from './rules/amp/no-nonfunctional-function.js';
31
32
  import ampNamingConvention from './rules/amp/naming-convention.js';
32
33
  import ampNoEmptyThen from './rules/amp/no-empty-then.js';
33
34
  import ampRequireRowcountCheck from './rules/amp/require-rowcount-check.js';
@@ -54,6 +55,7 @@ import ssjsPreferPlatformLoadVersion from './rules/ssjs/prefer-platform-load-ver
54
55
  import ssjsNoUnavailableMethod from './rules/ssjs/no-unavailable-method.js';
55
56
  import ssjsPreferParsejsonSafeArgument from './rules/ssjs/prefer-parsejson-safe-argument.js';
56
57
  import ssjsNoSwitchDefault from './rules/ssjs/no-switch-default.js';
58
+ import ssjsNoSwitchFallthrough from './rules/ssjs/no-switch-fallthrough.js';
57
59
  import ssjsNoTreatAsContentInjection from './rules/ssjs/no-treatascontent-injection.js';
58
60
  import ssjsArgumentTypes from './rules/ssjs/ssjs-argument-types.js';
59
61
  import ssjsCoreMethodArity from './rules/ssjs/ssjs-core-method-arity.js';
@@ -114,6 +116,7 @@ const plugin = {
114
116
  'amp-arg-types': ampArgumentTypes,
115
117
  'amp-no-email-excluded-function': ampNoEmailExcludedFunction,
116
118
  'amp-no-deprecated-function': ampNoDeprecatedFunction,
119
+ 'amp-no-nonfunctional-function': ampNoNonfunctionalFunction,
117
120
  'amp-naming-convention': ampNamingConvention,
118
121
  'amp-no-empty-then': ampNoEmptyThen,
119
122
  'amp-require-rowcount-check': ampRequireRowcountCheck,
@@ -139,6 +142,7 @@ const plugin = {
139
142
  'ssjs-no-unavailable-method': ssjsNoUnavailableMethod,
140
143
  'ssjs-prefer-parsejson-safe-arg': ssjsPreferParsejsonSafeArgument,
141
144
  'ssjs-no-switch-default': ssjsNoSwitchDefault,
145
+ 'ssjs-no-switch-fallthrough': ssjsNoSwitchFallthrough,
142
146
  'ssjs-no-treatascontent-injection': ssjsNoTreatAsContentInjection,
143
147
  'ssjs-arg-types': ssjsArgumentTypes,
144
148
  'ssjs-core-method-arity': ssjsCoreMethodArity,
@@ -188,6 +192,7 @@ const ssjsMcnRules = {
188
192
  'sfmc/ssjs-no-unavailable-method': 'off',
189
193
  'sfmc/ssjs-prefer-parsejson-safe-arg': 'off',
190
194
  'sfmc/ssjs-no-switch-default': 'off',
195
+ 'sfmc/ssjs-no-switch-fallthrough': 'off',
191
196
  'sfmc/ssjs-no-treatascontent-injection': 'off',
192
197
  'sfmc/ssjs-arg-types': 'off',
193
198
  'sfmc/ssjs-core-method-arity': 'off',
@@ -212,6 +217,7 @@ const ampRecommendedRules = {
212
217
  'sfmc/amp-function-arity': 'error',
213
218
  'sfmc/amp-arg-types': 'error',
214
219
  'sfmc/amp-no-deprecated-function': 'warn',
220
+ 'sfmc/amp-no-nonfunctional-function': 'error',
215
221
  'sfmc/amp-naming-convention': 'warn',
216
222
  'sfmc/amp-no-empty-then': 'warn',
217
223
  'sfmc/amp-require-rowcount-check': 'warn',
@@ -235,6 +241,7 @@ const ampStrictRules = {
235
241
  'sfmc/amp-arg-types': 'error',
236
242
  'sfmc/amp-no-email-excluded-function': 'off',
237
243
  'sfmc/amp-no-deprecated-function': 'warn',
244
+ 'sfmc/amp-no-nonfunctional-function': 'error',
238
245
  'sfmc/amp-naming-convention': ['error', { format: 'camelCase' }],
239
246
  'sfmc/amp-no-empty-then': 'error',
240
247
  'sfmc/amp-require-rowcount-check': 'error',
@@ -262,6 +269,7 @@ const ssjsRecommendedRules = {
262
269
  'sfmc/ssjs-no-unavailable-method': 'warn',
263
270
  'sfmc/ssjs-prefer-parsejson-safe-arg': 'warn',
264
271
  'sfmc/ssjs-no-switch-default': 'warn',
272
+ 'sfmc/ssjs-no-switch-fallthrough': 'warn',
265
273
  'sfmc/ssjs-no-treatascontent-injection': 'warn',
266
274
  'sfmc/ssjs-arg-types': 'warn',
267
275
  'sfmc/ssjs-core-method-arity': 'warn',
@@ -289,6 +297,7 @@ const ssjsStrictRules = {
289
297
  'sfmc/ssjs-no-unavailable-method': 'warn',
290
298
  'sfmc/ssjs-prefer-parsejson-safe-arg': 'error',
291
299
  'sfmc/ssjs-no-switch-default': 'error',
300
+ 'sfmc/ssjs-no-switch-fallthrough': 'error',
292
301
  'sfmc/ssjs-no-treatascontent-injection': 'error',
293
302
  'sfmc/ssjs-arg-types': 'warn',
294
303
  'sfmc/ssjs-core-method-arity': 'error',
@@ -639,6 +648,9 @@ plugin.configs = {
639
648
  rules: {
640
649
  ...ampRecommendedRules,
641
650
  'sfmc/amp-no-mcn-unsupported': 'error',
651
+ // Already covered by amp-no-mcn-unsupported in MCN (these functions
652
+ // are mcnSince:null); disabled here to avoid double-reporting.
653
+ 'sfmc/amp-no-nonfunctional-function': 'off',
642
654
  },
643
655
  },
644
656
 
@@ -670,6 +682,9 @@ plugin.configs = {
670
682
  rules: {
671
683
  ...ampRecommendedRules,
672
684
  'sfmc/amp-no-mcn-unsupported': 'error',
685
+ // Already covered by amp-no-mcn-unsupported in MCN (these
686
+ // functions are mcnSince:null); disabled to avoid double-reporting.
687
+ 'sfmc/amp-no-nonfunctional-function': 'off',
673
688
  },
674
689
  },
675
690
  {
@@ -705,6 +720,9 @@ plugin.configs = {
705
720
  rules: {
706
721
  ...ampRecommendedRules,
707
722
  'sfmc/amp-no-mcn-unsupported': 'error',
723
+ // Already covered by amp-no-mcn-unsupported in MCN (these
724
+ // functions are mcnSince:null); disabled to avoid double-reporting.
725
+ 'sfmc/amp-no-nonfunctional-function': 'off',
708
726
  },
709
727
  },
710
728
  {
@@ -744,6 +762,9 @@ plugin.configs = {
744
762
  rules: {
745
763
  ...ampStrictRules,
746
764
  'sfmc/amp-no-mcn-unsupported': 'error',
765
+ // Already covered by amp-no-mcn-unsupported in MCN (these
766
+ // functions are mcnSince:null); disabled to avoid double-reporting.
767
+ 'sfmc/amp-no-nonfunctional-function': 'off',
747
768
  },
748
769
  },
749
770
  {
@@ -771,6 +792,9 @@ plugin.configs = {
771
792
  rules: {
772
793
  ...ampStrictRules,
773
794
  'sfmc/amp-no-mcn-unsupported': 'error',
795
+ // Already covered by amp-no-mcn-unsupported in MCN (these
796
+ // functions are mcnSince:null); disabled to avoid double-reporting.
797
+ 'sfmc/amp-no-nonfunctional-function': 'off',
774
798
  },
775
799
  },
776
800
  {
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Rule: no-nonfunctional-function
3
+ *
4
+ * Flags calls to AMPscript functions that resolve at runtime but have no known
5
+ * working invocation (ampscript-data `nonFunctionalAtRuntime`). Unlike an unknown
6
+ * function, these DO exist in the catalog (so they remain in completions and
7
+ * hover), but every reached call aborts the page — e.g. `GetPortfolioItem` and
8
+ * the MSCRM family, whose underlying Classic feature is retired.
9
+ *
10
+ * Kept separate from `no-deprecated-function` because these functions were never
11
+ * formally deprecated by Salesforce; the failure is a retired platform feature,
12
+ * not a sunset notice. Reported as a problem with no auto-fix (no replacement
13
+ * exists). Mirrors the SSJS `ssjs-no-nonfunctional-method` rule.
14
+ */
15
+
16
+ import { nonFunctionalFunctionLookup } from 'ampscript-data';
17
+
18
+ /**
19
+ * Extract a short factual pointer from an entry's officialDocsNote (first
20
+ * sentence) for the warning message. Returns an empty string when absent.
21
+ *
22
+ * @param {object} entry - ampscript-data function entry
23
+ * @returns {string} A short note, or empty string
24
+ */
25
+ function shortNote(entry) {
26
+ if (!entry || typeof entry.officialDocsNote !== 'string') {
27
+ return '';
28
+ }
29
+ const trimmed = entry.officialDocsNote.trim();
30
+ if (trimmed === '') {
31
+ return '';
32
+ }
33
+ const sentenceEnd = trimmed.indexOf('. ');
34
+ return sentenceEnd === -1 ? trimmed : trimmed.slice(0, sentenceEnd + 1);
35
+ }
36
+
37
+ export default {
38
+ meta: {
39
+ type: 'problem',
40
+ docs: {
41
+ description:
42
+ 'Disallow AMPscript functions that resolve at runtime but have no known working invocation',
43
+ },
44
+ hasSuggestions: false,
45
+ messages: {
46
+ nonFunctional:
47
+ "'{{name}}' exists in SFMC but has no known working invocation at runtime (every tested call aborts the page). {{note}}",
48
+ },
49
+ schema: [],
50
+ },
51
+
52
+ create(context) {
53
+ return {
54
+ FunctionCall(node) {
55
+ const functionName = node.name || (node.callee && node.callee.name) || '';
56
+ if (!functionName) {
57
+ return;
58
+ }
59
+
60
+ const entry = nonFunctionalFunctionLookup.get(functionName.toLowerCase());
61
+ if (!entry) {
62
+ return;
63
+ }
64
+
65
+ context.report({
66
+ node,
67
+ messageId: 'nonFunctional',
68
+ data: { name: functionName, note: shortNote(entry) },
69
+ });
70
+ },
71
+ };
72
+ },
73
+ };
@@ -1,8 +1,16 @@
1
1
  /**
2
2
  * Rule: no-switch-default
3
3
  *
4
- * The `default` case in switch statements may silently fail to execute in
5
- * SFMC's SSJS engine. Explicitly enumerate all expected values instead.
4
+ * SFMC's SSJS runs on an old Jint build affected by jint#2607: an executed
5
+ * `break` inside a `switch` that sits inside a function can abnormally complete
6
+ * the function, so it returns `undefined` and statements after the `switch` are
7
+ * skipped (intermittent across compilations). Community lore mis-reported this
8
+ * as "the `default` case may not execute", but a last-clause `default` itself
9
+ * runs fine — the trigger is the executed `break`.
10
+ *
11
+ * Flagging the `default` clause is a cheap heuristic hint to avoid relying on a
12
+ * function-scoped `switch`/`break` for critical control flow. Prefer a lookup
13
+ * map or `if`/`else if`.
6
14
  */
7
15
 
8
16
  export default {
@@ -10,12 +18,14 @@ export default {
10
18
  type: 'problem',
11
19
  docs: {
12
20
  description:
13
- "Disallow 'default' case in switch statements because SFMC SSJS may not process it",
21
+ "Discourage relying on a 'default' case in switch statements: a function-scoped switch/break can abnormally complete the function in SFMC SSJS (Jint bug)",
14
22
  },
15
23
  messages: {
16
24
  noDefault:
17
- "The 'default' case in a switch statement may not execute in SFMC SSJS. " +
18
- 'List all expected values as explicit cases instead.',
25
+ 'A `break` inside a function-scoped `switch` can abnormally complete the ' +
26
+ 'function in SFMC SSJS (Jint bug), skipping code after the `switch` — often ' +
27
+ 'the `default` fallback. Prefer a lookup map or `if`/`else if` for critical ' +
28
+ 'control flow.',
19
29
  },
20
30
  schema: [],
21
31
  },
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Rule: no-switch-fallthrough
3
+ *
4
+ * SFMC's SSJS engine has NO switch fall-through. A matched `case` runs only its
5
+ * own statements up to the next `case`/`default` — an empty leading label does
6
+ * not share the next label's body, a break-less body does not cascade into the
7
+ * following case, and a matched case never falls into `default`. Give every
8
+ * clause its own break-terminated body, or use if / a lookup map instead.
9
+ */
10
+
11
+ // Statement types that stop execution before the next clause, so a body ending
12
+ // in one of them is not relying on fall-through.
13
+ const TERMINATING_STATEMENTS = new Set([
14
+ 'BreakStatement',
15
+ 'ReturnStatement',
16
+ 'ThrowStatement',
17
+ 'ContinueStatement',
18
+ ]);
19
+
20
+ export default {
21
+ meta: {
22
+ type: 'problem',
23
+ docs: {
24
+ description:
25
+ 'Disallow reliance on switch fall-through because SFMC SSJS never falls through',
26
+ },
27
+ messages: {
28
+ emptyLabelFallthrough:
29
+ 'This empty case relies on fall-through into the next label, but SFMC SSJS has no ' +
30
+ 'fall-through — the shared body never runs. Give this case its own break-terminated ' +
31
+ 'body, or use if / a lookup map.',
32
+ bodyFallthrough:
33
+ 'This case body has no terminating break/return/throw, so it relies on cascading ' +
34
+ 'into the next case — but SFMC SSJS has no fall-through and each case runs only its ' +
35
+ 'own statements. End every case with break, or use if / a lookup map.',
36
+ },
37
+ schema: [],
38
+ },
39
+
40
+ create(context) {
41
+ return {
42
+ SwitchStatement(node) {
43
+ const clauses = node.cases;
44
+ for (let index = 0; index < clauses.length; index++) {
45
+ // The last clause has nothing to fall into, so it is never a problem.
46
+ if (index === clauses.length - 1) {
47
+ continue;
48
+ }
49
+ const clause = clauses[index];
50
+ if (clause.consequent.length === 0) {
51
+ // Empty label stacked before another case/default.
52
+ context.report({ node: clause, messageId: 'emptyLabelFallthrough' });
53
+ continue;
54
+ }
55
+ // Non-empty body: flag when it does not end in a terminating statement.
56
+ const last = clause.consequent.at(-1);
57
+ if (!TERMINATING_STATEMENTS.has(last.type)) {
58
+ context.report({ node: clause, messageId: 'bodyFallthrough' });
59
+ }
60
+ }
61
+ },
62
+ };
63
+ },
64
+ };
@@ -7,7 +7,6 @@
7
7
  * Auto-fix:
8
8
  * - let/const declarations → var
9
9
  * - nullish coalescing (??) → || (semantics differ for 0, '', false)
10
- * - direct object literal return → extract to variable
11
10
  */
12
11
 
13
12
  import { unsupportedByNodeType } from 'ssjs-data';
@@ -32,14 +31,6 @@ function nullishCoalescingFix(context, node) {
32
31
  };
33
32
  }
34
33
 
35
- function directObjectReturnFix(context, node) {
36
- return (fixer) => {
37
- const objectText = context.sourceCode.getText(node.argument);
38
- const indent = ' '.repeat(node.loc.start.column);
39
- return fixer.replaceText(node, `var _result = ${objectText};\n${indent}return _result;`);
40
- };
41
- }
42
-
43
34
  export default {
44
35
  meta: {
45
36
  type: 'problem',
@@ -96,8 +87,6 @@ export default {
96
87
  report.fix = AUTO_FIX[entry.feature](node);
97
88
  } else if (entry.feature === 'NullishCoalescing') {
98
89
  report.fix = nullishCoalescingFix(context, node);
99
- } else if (entry.feature === 'DirectObjectReturn') {
100
- report.fix = directObjectReturnFix(context, node);
101
90
  }
102
91
 
103
92
  context.report(report);