eslint-plugin-sfmc 5.4.4 → 5.6.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 +7 -11
- package/docs/unicorn-compatibility.md +182 -50
- package/package.json +11 -5
- package/src/index.js +381 -7
- package/src/rules/amp/argument-types.js +2 -2
- package/src/rules/ssjs/cache-loop-length.js +6 -5
- package/src/rules/ssjs/http-property-value.js +5 -4
- package/src/rules/ssjs/no-clr-header-access.js +5 -4
- package/src/rules/ssjs/no-invalid-property-access.js +5 -4
- package/src/rules/ssjs/no-nonexistent-global.js +1 -1
- package/src/rules/ssjs/no-treatascontent-injection.js +11 -14
- package/src/rules/ssjs/no-unavailable-method.js +6 -4
- package/src/rules/ssjs/prefer-parsejson-safe-argument.js +19 -25
- package/src/rules/ssjs/require-string-clr-content.js +5 -4
- package/src/rules/ssjs/ssjs-argument-types.js +5 -5
|
@@ -54,36 +54,30 @@ export default {
|
|
|
54
54
|
function isParseJSONCall(node) {
|
|
55
55
|
const callee = node.callee;
|
|
56
56
|
|
|
57
|
-
// ParseJSON(...)
|
|
58
|
-
if (callee.type === 'Identifier' && callee.name === 'ParseJSON') {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Platform.Function.ParseJSON(...)
|
|
63
57
|
return (
|
|
64
|
-
|
|
65
|
-
callee.
|
|
66
|
-
|
|
67
|
-
callee.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
// ParseJSON(...)
|
|
59
|
+
(callee.type === 'Identifier' && callee.name === 'ParseJSON') ||
|
|
60
|
+
// Platform.Function.ParseJSON(...)
|
|
61
|
+
(callee.type === 'MemberExpression' &&
|
|
62
|
+
callee.property.type === 'Identifier' &&
|
|
63
|
+
callee.property.name === 'ParseJSON' &&
|
|
64
|
+
callee.object.type === 'MemberExpression' &&
|
|
65
|
+
callee.object.property.type === 'Identifier' &&
|
|
66
|
+
callee.object.property.name === 'Function' &&
|
|
67
|
+
callee.object.object.type === 'Identifier' &&
|
|
68
|
+
callee.object.object.name === 'Platform')
|
|
72
69
|
);
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
function isAlreadySafe(argument) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
argument.type === 'BinaryExpression' &&
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// String literal passed directly — already a string
|
|
86
|
-
return argument.type === 'Literal' && typeof argument.value === 'string';
|
|
73
|
+
return (
|
|
74
|
+
// arg + '' or '' + arg
|
|
75
|
+
(argument.type === 'BinaryExpression' &&
|
|
76
|
+
argument.operator === '+' &&
|
|
77
|
+
(isEmptyString(argument.left) || isEmptyString(argument.right))) ||
|
|
78
|
+
// String literal passed directly — already a string
|
|
79
|
+
(argument.type === 'Literal' && typeof argument.value === 'string')
|
|
80
|
+
);
|
|
87
81
|
}
|
|
88
82
|
|
|
89
83
|
function isEmptyString(node) {
|
|
@@ -46,10 +46,11 @@ function isHttpConstructorMember(node) {
|
|
|
46
46
|
* @returns {boolean} Whether the expression yields an HTTP request instance
|
|
47
47
|
*/
|
|
48
48
|
function isHttpRequestInit(node) {
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
return (
|
|
50
|
+
Boolean(node) &&
|
|
51
|
+
(node.type === 'NewExpression' || node.type === 'CallExpression') &&
|
|
52
|
+
isHttpConstructorMember(node.callee)
|
|
53
|
+
);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
/**
|
|
@@ -327,11 +327,11 @@ function isTypeCompatible(actual, expected) {
|
|
|
327
327
|
return true;
|
|
328
328
|
}
|
|
329
329
|
const allowed = expected.split('|').map((t) => t.trim());
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
return (
|
|
331
|
+
allowed.includes(actual) ||
|
|
332
|
+
// 'array' is compatible with typed array variants
|
|
333
|
+
(allowed.includes('array') && (actual === 'string[]' || actual === 'number[]'))
|
|
334
|
+
);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
function isWSProxyConstructor(node) {
|