eslint-plugin-sfmc 5.2.0 → 5.2.1

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.
Files changed (35) hide show
  1. package/README.md +7 -7
  2. package/docs/unicorn-compatibility.md +22 -15
  3. package/package.json +9 -9
  4. package/src/ampscript-processor.js +1 -5
  5. package/src/index.js +8 -4
  6. package/src/processor.js +1 -5
  7. package/src/rules/amp/argument-types.js +6 -8
  8. package/src/rules/amp/function-arity.js +6 -11
  9. package/src/rules/amp/naming-convention.js +7 -9
  10. package/src/rules/amp/no-loop-counter-assign.js +12 -11
  11. package/src/rules/amp/prefer-attribute-value.js +6 -11
  12. package/src/rules/amp/prefer-boolean-literal.js +6 -5
  13. package/src/rules/amp/require-variable-declaration.js +15 -14
  14. package/src/rules/hbs/_shared.js +8 -18
  15. package/src/rules/hbs/no-mcn-unsupported.js +3 -4
  16. package/src/rules/ssjs/cache-loop-length.js +8 -11
  17. package/src/rules/ssjs/http-property-value.js +7 -11
  18. package/src/rules/ssjs/no-clr-header-access.js +7 -16
  19. package/src/rules/ssjs/no-deprecated-function.js +9 -14
  20. package/src/rules/ssjs/no-invalid-property-access.js +7 -11
  21. package/src/rules/ssjs/no-mcn-unsupported.js +5 -4
  22. package/src/rules/ssjs/no-property-call.js +4 -4
  23. package/src/rules/ssjs/no-treatascontent-injection.js +7 -10
  24. package/src/rules/ssjs/no-unavailable-method.js +14 -14
  25. package/src/rules/ssjs/no-unknown-function.js +39 -37
  26. package/src/rules/ssjs/platform-function-arity.js +54 -57
  27. package/src/rules/ssjs/prefer-parsejson-safe-argument.js +1 -4
  28. package/src/rules/ssjs/require-hasownproperty.js +70 -91
  29. package/src/rules/ssjs/require-platform-load-order.js +3 -7
  30. package/src/rules/ssjs/require-platform-load.js +1 -4
  31. package/src/rules/ssjs/require-string-clr-content.js +5 -14
  32. package/src/rules/ssjs/ssjs-argument-types.js +22 -28
  33. package/src/rules/ssjs/ssjs-core-method-arity.js +20 -24
  34. package/src/rules/ssjs/ssjs-no-nonfunctional-method.js +20 -26
  35. package/src/ssjs-processor.js +1 -5
@@ -65,13 +65,10 @@ function isHttpConstructorMember(node) {
65
65
  * @returns {boolean} Whether the expression yields an HTTP request instance
66
66
  */
67
67
  function isHttpRequestInit(node) {
68
- if (!node) {
69
- return false;
70
- }
71
- if (node.type === 'NewExpression' || node.type === 'CallExpression') {
72
- return isHttpConstructorMember(node.callee);
73
- }
74
- return false;
68
+ return node
69
+ ? (node.type === 'NewExpression' || node.type === 'CallExpression') &&
70
+ isHttpConstructorMember(node.callee)
71
+ : false;
75
72
  }
76
73
 
77
74
  /**
@@ -123,10 +120,9 @@ function checkConstraint(value, constraint) {
123
120
  if (constraint.numeric === 'integer' && !Number.isSafeInteger(value)) {
124
121
  return 'must be an integer';
125
122
  }
126
- if (typeof constraint.min === 'number' && value < constraint.min) {
127
- return `must be >= ${constraint.min}`;
128
- }
129
- return null;
123
+ return typeof constraint.min === 'number' && value < constraint.min
124
+ ? `must be >= ${constraint.min}`
125
+ : null;
130
126
  }
131
127
  return null;
132
128
  }
@@ -73,16 +73,10 @@ function isHttpConstructorMember(node) {
73
73
  * @returns {boolean} Whether the expression yields an HTTP request instance
74
74
  */
75
75
  function isHttpRequestInit(node) {
76
- if (!node) {
77
- return false;
78
- }
79
- if (node.type === 'NewExpression') {
80
- return isHttpConstructorMember(node.callee);
81
- }
82
- if (node.type === 'CallExpression') {
83
- return isHttpConstructorMember(node.callee);
84
- }
85
- return false;
76
+ return node
77
+ ? (node.type === 'NewExpression' || node.type === 'CallExpression') &&
78
+ isHttpConstructorMember(node.callee)
79
+ : false;
86
80
  }
87
81
 
88
82
  export default {
@@ -139,16 +133,13 @@ export default {
139
133
  * @returns {string|null} Response variable name or null
140
134
  */
141
135
  function trackedResponseName(headersMember) {
142
- if (
143
- headersMember.type === 'MemberExpression' &&
136
+ return headersMember.type === 'MemberExpression' &&
144
137
  headersMember.property.type === 'Identifier' &&
145
138
  headersMember.property.name === 'headers' &&
146
139
  headersMember.object.type === 'Identifier' &&
147
140
  responseVariables.has(headersMember.object.name)
148
- ) {
149
- return headersMember.object.name;
150
- }
151
- return null;
141
+ ? headersMember.object.name
142
+ : null;
152
143
  }
153
144
 
154
145
  /**
@@ -49,10 +49,7 @@ const ERRORUTIL_DEPRECATED = new Set(
49
49
  */
50
50
  function findDeprecatedEntry(className, methodName) {
51
51
  const classLookup = coreDeprecatedMethodLookup.get(className.toLowerCase());
52
- if (!classLookup) {
53
- return null;
54
- }
55
- return classLookup.get(methodName.toLowerCase()) || null;
52
+ return classLookup ? classLookup.get(methodName.toLowerCase()) || null : null;
56
53
  }
57
54
 
58
55
  /**
@@ -86,10 +83,11 @@ function getCoreInitType(node) {
86
83
  return null;
87
84
  }
88
85
  const callee = node.callee;
89
- if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
90
- return null;
91
- }
92
- if (callee.property.name !== 'Init') {
86
+ if (
87
+ callee.type !== 'MemberExpression' ||
88
+ callee.property.type !== 'Identifier' ||
89
+ callee.property.name !== 'Init'
90
+ ) {
93
91
  return null;
94
92
  }
95
93
  const objectPath = getMemberPath(callee.object);
@@ -124,14 +122,11 @@ function getCoreLoadVersion(node) {
124
122
  return null;
125
123
  }
126
124
  const versionArgument = arguments_[1];
127
- if (
128
- versionArgument &&
125
+ return versionArgument &&
129
126
  versionArgument.type === 'Literal' &&
130
127
  typeof versionArgument.value === 'string'
131
- ) {
132
- return versionArgument.value;
133
- }
134
- return '';
128
+ ? versionArgument.value
129
+ : '';
135
130
  }
136
131
 
137
132
  /**
@@ -58,13 +58,10 @@ function isHttpConstructorMember(node) {
58
58
  * @returns {boolean} Whether the expression yields an HTTP request instance
59
59
  */
60
60
  function isHttpRequestInit(node) {
61
- if (!node) {
62
- return false;
63
- }
64
- if (node.type === 'NewExpression' || node.type === 'CallExpression') {
65
- return isHttpConstructorMember(node.callee);
66
- }
67
- return false;
61
+ return node
62
+ ? (node.type === 'NewExpression' || node.type === 'CallExpression') &&
63
+ isHttpConstructorMember(node.callee)
64
+ : false;
68
65
  }
69
66
 
70
67
  /**
@@ -108,10 +105,9 @@ function lookupAccess(node, requestVariables) {
108
105
  return null;
109
106
  }
110
107
  const owner = resolveOwner(node.object, requestVariables);
111
- if (!owner) {
112
- return null;
113
- }
114
- return propertyAccessLookup.get(`${owner}.${node.property.name}`.toLowerCase()) ?? null;
108
+ return owner
109
+ ? (propertyAccessLookup.get(`${owner}.${node.property.name}`.toLowerCase()) ?? null)
110
+ : null;
115
111
  }
116
112
 
117
113
  /**
@@ -136,10 +136,11 @@ function getCoreInitType(node) {
136
136
  return null;
137
137
  }
138
138
  const callee = node.callee;
139
- if (callee.type !== 'MemberExpression') {
140
- return null;
141
- }
142
- if (callee.property.type !== 'Identifier' || callee.property.name !== 'Init') {
139
+ if (
140
+ callee.type !== 'MemberExpression' ||
141
+ callee.property.type !== 'Identifier' ||
142
+ callee.property.name !== 'Init'
143
+ ) {
143
144
  return null;
144
145
  }
145
146
  if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
@@ -35,10 +35,10 @@ const REQUEST_PROPERTIES = new Set(
35
35
  */
36
36
  function canReplaceCallWithAssignment(node) {
37
37
  const parent = node.parent;
38
- if (parent.type === 'ExpressionStatement' && parent.expression === node) {
39
- return true;
40
- }
41
- return Boolean(parent.type === 'SequenceExpression' && parent.expressions.includes(node));
38
+ return (
39
+ (parent.type === 'ExpressionStatement' && parent.expression === node) ||
40
+ Boolean(parent.type === 'SequenceExpression' && parent.expressions.includes(node))
41
+ );
42
42
  }
43
43
 
44
44
  export default {
@@ -28,15 +28,12 @@ export default {
28
28
  create(context) {
29
29
  return {
30
30
  CallExpression(node) {
31
- if (!isTreatAsContentCall(node)) {
32
- return;
33
- }
34
- if (node.arguments.length === 0) {
31
+ if (!isTreatAsContentCall(node) || node.arguments.length === 0) {
35
32
  return;
36
33
  }
37
34
 
38
35
  const argument = node.arguments[0];
39
- if (containsConcatenation(argument)) {
36
+ if (hasConcatenation(argument)) {
40
37
  context.report({ node: argument, messageId: 'injection' });
41
38
  }
42
39
  },
@@ -65,9 +62,9 @@ function isTreatAsContentCall(node) {
65
62
  );
66
63
  }
67
64
 
68
- function containsConcatenation(node) {
69
- if (node.type === 'BinaryExpression' && node.operator === '+') {
70
- return true;
71
- }
72
- return node.type === 'TemplateLiteral' && node.expressions.length > 0;
65
+ function hasConcatenation(node) {
66
+ return (
67
+ (node.type === 'BinaryExpression' && node.operator === '+') ||
68
+ (node.type === 'TemplateLiteral' && node.expressions.length > 0)
69
+ );
73
70
  }
@@ -111,10 +111,9 @@ export default {
111
111
  (c) =>
112
112
  c.type === 'Block' && c.range[0] === 0 && /^\s*global\b/.test(c.value),
113
113
  );
114
- if (leadingGlobal) {
115
- return fixer.insertTextAfterRange(leadingGlobal.range, '\n\n' + entry.polyfill);
116
- }
117
- return fixer.insertTextBeforeRange([0, 0], entry.polyfill + '\n\n');
114
+ return leadingGlobal
115
+ ? fixer.insertTextAfterRange(leadingGlobal.range, '\n\n' + entry.polyfill)
116
+ : fixer.insertTextBeforeRange([0, 0], entry.polyfill + '\n\n');
118
117
  };
119
118
  }
120
119
 
@@ -230,17 +229,18 @@ export default {
230
229
  }
231
230
 
232
231
  // ── Prototype methods with NO polyfill: .trimStart(), .flat(), … ─
233
- if (knownUnsupportedByPrototypeName.has(lowerMethod)) {
234
- if (ignored.has(methodName)) {
235
- return;
236
- }
237
- // Skip known SFMC top-level objects to avoid false positives.
238
- if (receiver.type === 'Identifier' && SFMC_RECEIVERS.has(receiver.name)) {
239
- return;
240
- }
241
- const entry = knownUnsupportedByPrototypeName.get(lowerMethod);
242
- pendingReports.push({ node: property, entry, noPolyfill: true });
232
+ if (!knownUnsupportedByPrototypeName.has(lowerMethod)) {
233
+ return;
234
+ }
235
+ if (ignored.has(methodName)) {
236
+ return;
237
+ }
238
+ // Skip known SFMC top-level objects to avoid false positives.
239
+ if (receiver.type === 'Identifier' && SFMC_RECEIVERS.has(receiver.name)) {
240
+ return;
243
241
  }
242
+ const entry = knownUnsupportedByPrototypeName.get(lowerMethod);
243
+ pendingReports.push({ node: property, entry, noPolyfill: true });
244
244
  },
245
245
 
246
246
  'Program:exit'() {
@@ -139,43 +139,44 @@ export default {
139
139
  }
140
140
 
141
141
  // ── Instance method calls (Core Library / WSProxy) ────────────
142
- if (callee.object.type === 'Identifier') {
143
- const objectName = callee.object.name;
142
+ if (callee.object.type !== 'Identifier') {
143
+ return;
144
+ }
145
+ const objectName = callee.object.name;
144
146
 
145
- // Core library: var de = DataExtension.Init("key"); de.Foo();
146
- const coreType = coreVariables.get(objectName);
147
- if (coreType) {
148
- const objectDefinition = coreObjectLookup.get(coreType);
149
- if (objectDefinition) {
150
- const knownMethods = new Set(
151
- objectDefinition.methods.map((m) => m.toLowerCase()),
152
- );
153
- if (!knownMethods.has(methodName.toLowerCase())) {
154
- context.report({
155
- node: property,
156
- messageId: 'unknownCoreMethod',
157
- data: {
158
- method: methodName,
159
- objectType: coreType,
160
- available: objectDefinition.methods.join(', '),
161
- },
162
- });
163
- }
147
+ // Core library: var de = DataExtension.Init("key"); de.Foo();
148
+ const coreType = coreVariables.get(objectName);
149
+ if (coreType) {
150
+ const objectDefinition = coreObjectLookup.get(coreType);
151
+ if (objectDefinition) {
152
+ const knownMethods = new Set(
153
+ objectDefinition.methods.map((m) => m.toLowerCase()),
154
+ );
155
+ if (!knownMethods.has(methodName.toLowerCase())) {
156
+ context.report({
157
+ node: property,
158
+ messageId: 'unknownCoreMethod',
159
+ data: {
160
+ method: methodName,
161
+ objectType: coreType,
162
+ available: objectDefinition.methods.join(', '),
163
+ },
164
+ });
164
165
  }
165
- return;
166
166
  }
167
+ return;
168
+ }
167
169
 
168
- // WSProxy: var api = new Script.Util.WSProxy(); api.Foo();
169
- if (
170
- wsproxyVariables.has(objectName) &&
171
- !wsproxyMethodNames.has(methodName.toLowerCase())
172
- ) {
173
- context.report({
174
- node: property,
175
- messageId: 'unknownWsproxyMethod',
176
- data: { name: methodName },
177
- });
178
- }
170
+ // WSProxy: var api = new Script.Util.WSProxy(); api.Foo();
171
+ if (
172
+ wsproxyVariables.has(objectName) &&
173
+ !wsproxyMethodNames.has(methodName.toLowerCase())
174
+ ) {
175
+ context.report({
176
+ node: property,
177
+ messageId: 'unknownWsproxyMethod',
178
+ data: { name: methodName },
179
+ });
179
180
  }
180
181
  },
181
182
  };
@@ -194,10 +195,11 @@ function getCoreInitType(node) {
194
195
  return null;
195
196
  }
196
197
  const callee = node.callee;
197
- if (callee.type !== 'MemberExpression') {
198
- return null;
199
- }
200
- if (callee.property.type !== 'Identifier' || callee.property.name !== 'Init') {
198
+ if (
199
+ callee.type !== 'MemberExpression' ||
200
+ callee.property.type !== 'Identifier' ||
201
+ callee.property.name !== 'Init'
202
+ ) {
201
203
  return null;
202
204
  }
203
205
  if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
@@ -15,10 +15,9 @@ import { platformFunctionLookup } from 'ssjs-data';
15
15
  * @returns {string} The rendered list.
16
16
  */
17
17
  function formatArities(arities) {
18
- if (arities.length === 1) {
19
- return String(arities[0]);
20
- }
21
- return `${arities.slice(0, -1).join(', ')} or ${arities.at(-1)}`;
18
+ return arities.length === 1
19
+ ? String(arities[0])
20
+ : `${arities.slice(0, -1).join(', ')} or ${arities.at(-1)}`;
22
21
  }
23
22
 
24
23
  export default {
@@ -42,63 +41,61 @@ export default {
42
41
  return {
43
42
  CallExpression(node) {
44
43
  const callee = node.callee;
45
- if (callee.type !== 'MemberExpression') {
46
- return;
47
- }
48
-
49
44
  if (
50
- callee.object.type === 'MemberExpression' &&
51
- callee.object.object.type === 'Identifier' &&
52
- callee.object.object.name === 'Platform' &&
53
- callee.object.property.type === 'Identifier' &&
54
- callee.object.property.name === 'Function' &&
55
- callee.property.type === 'Identifier'
45
+ callee.type !== 'MemberExpression' ||
46
+ callee.object.type !== 'MemberExpression' ||
47
+ callee.object.object.type !== 'Identifier' ||
48
+ callee.object.object.name !== 'Platform' ||
49
+ callee.object.property.type !== 'Identifier' ||
50
+ callee.object.property.name !== 'Function' ||
51
+ callee.property.type !== 'Identifier'
56
52
  ) {
57
- const methodName = callee.property.name;
58
- const entry = platformFunctionLookup.get(methodName.toLowerCase());
59
- if (!entry) {
60
- return;
61
- }
53
+ return;
54
+ }
55
+ const methodName = callee.property.name;
56
+ const entry = platformFunctionLookup.get(methodName.toLowerCase());
57
+ if (!entry) {
58
+ return;
59
+ }
62
60
 
63
- const actual = node.arguments.length;
61
+ const actual = node.arguments.length;
64
62
 
65
- if (actual < entry.minArgs) {
66
- context.report({
67
- node: callee.property,
68
- messageId: 'tooFewArgs',
69
- data: {
70
- name: entry.name,
71
- min: String(entry.minArgs),
72
- actual: String(actual),
73
- },
74
- });
75
- } else if (actual > entry.maxArgs) {
76
- context.report({
77
- node: callee.property,
78
- messageId: 'tooManyArgs',
79
- data: {
80
- name: entry.name,
81
- max: String(entry.maxArgs),
82
- actual: String(actual),
83
- },
84
- });
85
- } else if (
86
- Array.isArray(entry.validArities) &&
87
- !entry.validArities.includes(actual)
88
- ) {
89
- // Discontinuous overload: actual is within [minArgs, maxArgs]
90
- // but not one of the exact permitted arities (e.g. HTTPGet
91
- // accepts only 1 or 6 arguments; 2-5 throw at runtime).
92
- context.report({
93
- node: callee.property,
94
- messageId: 'invalidArity',
95
- data: {
96
- name: entry.name,
97
- arities: formatArities(entry.validArities),
98
- actual: String(actual),
99
- },
100
- });
101
- }
63
+ if (actual < entry.minArgs) {
64
+ context.report({
65
+ node: callee.property,
66
+ messageId: 'tooFewArgs',
67
+ data: {
68
+ name: entry.name,
69
+ min: String(entry.minArgs),
70
+ actual: String(actual),
71
+ },
72
+ });
73
+ } else if (actual > entry.maxArgs) {
74
+ context.report({
75
+ node: callee.property,
76
+ messageId: 'tooManyArgs',
77
+ data: {
78
+ name: entry.name,
79
+ max: String(entry.maxArgs),
80
+ actual: String(actual),
81
+ },
82
+ });
83
+ } else if (
84
+ Array.isArray(entry.validArities) &&
85
+ !entry.validArities.includes(actual)
86
+ ) {
87
+ // Discontinuous overload: actual is within [minArgs, maxArgs]
88
+ // but not one of the exact permitted arities (e.g. HTTPGet
89
+ // accepts only 1 or 6 arguments; 2-5 throw at runtime).
90
+ context.report({
91
+ node: callee.property,
92
+ messageId: 'invalidArity',
93
+ data: {
94
+ name: entry.name,
95
+ arities: formatArities(entry.validArities),
96
+ actual: String(actual),
97
+ },
98
+ });
102
99
  }
103
100
  },
104
101
  };
@@ -27,10 +27,7 @@ export default {
27
27
  create(context) {
28
28
  return {
29
29
  CallExpression(node) {
30
- if (!isParseJSONCall(node)) {
31
- return;
32
- }
33
- if (node.arguments.length === 0) {
30
+ if (!isParseJSONCall(node) || node.arguments.length === 0) {
34
31
  return;
35
32
  }
36
33