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.
- package/README.md +7 -7
- package/docs/unicorn-compatibility.md +22 -15
- package/package.json +9 -9
- package/src/ampscript-processor.js +1 -5
- package/src/index.js +8 -4
- package/src/processor.js +1 -5
- package/src/rules/amp/argument-types.js +6 -8
- package/src/rules/amp/function-arity.js +6 -11
- package/src/rules/amp/naming-convention.js +7 -9
- package/src/rules/amp/no-loop-counter-assign.js +12 -11
- package/src/rules/amp/prefer-attribute-value.js +6 -11
- package/src/rules/amp/prefer-boolean-literal.js +6 -5
- package/src/rules/amp/require-variable-declaration.js +15 -14
- package/src/rules/hbs/_shared.js +8 -18
- package/src/rules/hbs/no-mcn-unsupported.js +3 -4
- package/src/rules/ssjs/cache-loop-length.js +8 -11
- package/src/rules/ssjs/http-property-value.js +7 -11
- package/src/rules/ssjs/no-clr-header-access.js +7 -16
- package/src/rules/ssjs/no-deprecated-function.js +9 -14
- package/src/rules/ssjs/no-invalid-property-access.js +7 -11
- package/src/rules/ssjs/no-mcn-unsupported.js +5 -4
- package/src/rules/ssjs/no-property-call.js +4 -4
- package/src/rules/ssjs/no-treatascontent-injection.js +7 -10
- package/src/rules/ssjs/no-unavailable-method.js +14 -14
- package/src/rules/ssjs/no-unknown-function.js +39 -37
- package/src/rules/ssjs/platform-function-arity.js +54 -57
- package/src/rules/ssjs/prefer-parsejson-safe-argument.js +1 -4
- package/src/rules/ssjs/require-hasownproperty.js +70 -91
- package/src/rules/ssjs/require-platform-load-order.js +3 -7
- package/src/rules/ssjs/require-platform-load.js +1 -4
- package/src/rules/ssjs/require-string-clr-content.js +5 -14
- package/src/rules/ssjs/ssjs-argument-types.js +22 -28
- package/src/rules/ssjs/ssjs-core-method-arity.js +20 -24
- package/src/rules/ssjs/ssjs-no-nonfunctional-method.js +20 -26
- 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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
127
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
128
|
-
versionArgument &&
|
|
125
|
+
return versionArgument &&
|
|
129
126
|
versionArgument.type === 'Literal' &&
|
|
130
127
|
typeof versionArgument.value === 'string'
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
112
|
-
|
|
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 (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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 (
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
115
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
|
143
|
-
|
|
142
|
+
if (callee.object.type !== 'Identifier') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const objectName = callee.object.name;
|
|
144
146
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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 (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
19
|
-
|
|
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.
|
|
51
|
-
callee.object.
|
|
52
|
-
callee.object.object.
|
|
53
|
-
callee.object.
|
|
54
|
-
callee.object.property.
|
|
55
|
-
callee.property.
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
61
|
+
const actual = node.arguments.length;
|
|
64
62
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
};
|