eslint-plugin-sfmc 5.1.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 (37) hide show
  1. package/README.md +38 -36
  2. package/docs/rules/amp/arg-types.md +13 -2
  3. package/docs/rules/amp/prefer-boolean-literal.md +50 -0
  4. package/docs/unicorn-compatibility.md +22 -15
  5. package/package.json +11 -11
  6. package/src/ampscript-processor.js +1 -5
  7. package/src/index.js +12 -4
  8. package/src/processor.js +1 -5
  9. package/src/rules/amp/argument-types.js +48 -12
  10. package/src/rules/amp/function-arity.js +6 -11
  11. package/src/rules/amp/naming-convention.js +7 -9
  12. package/src/rules/amp/no-loop-counter-assign.js +12 -11
  13. package/src/rules/amp/prefer-attribute-value.js +6 -11
  14. package/src/rules/amp/prefer-boolean-literal.js +99 -0
  15. package/src/rules/amp/require-variable-declaration.js +15 -14
  16. package/src/rules/hbs/_shared.js +8 -18
  17. package/src/rules/hbs/no-mcn-unsupported.js +3 -4
  18. package/src/rules/ssjs/cache-loop-length.js +8 -11
  19. package/src/rules/ssjs/http-property-value.js +7 -11
  20. package/src/rules/ssjs/no-clr-header-access.js +7 -16
  21. package/src/rules/ssjs/no-deprecated-function.js +9 -14
  22. package/src/rules/ssjs/no-invalid-property-access.js +7 -11
  23. package/src/rules/ssjs/no-mcn-unsupported.js +5 -4
  24. package/src/rules/ssjs/no-property-call.js +4 -4
  25. package/src/rules/ssjs/no-treatascontent-injection.js +7 -10
  26. package/src/rules/ssjs/no-unavailable-method.js +14 -14
  27. package/src/rules/ssjs/no-unknown-function.js +39 -37
  28. package/src/rules/ssjs/platform-function-arity.js +54 -57
  29. package/src/rules/ssjs/prefer-parsejson-safe-argument.js +1 -4
  30. package/src/rules/ssjs/require-hasownproperty.js +70 -91
  31. package/src/rules/ssjs/require-platform-load-order.js +3 -7
  32. package/src/rules/ssjs/require-platform-load.js +1 -4
  33. package/src/rules/ssjs/require-string-clr-content.js +5 -14
  34. package/src/rules/ssjs/ssjs-argument-types.js +22 -28
  35. package/src/rules/ssjs/ssjs-core-method-arity.js +20 -24
  36. package/src/rules/ssjs/ssjs-no-nonfunctional-method.js +20 -26
  37. package/src/ssjs-processor.js +1 -5
@@ -4,9 +4,10 @@
4
4
  * Validates literal arguments passed to AMPscript functions against the
5
5
  * constraints declared in the ampscript-data catalog. Currently it checks
6
6
  * parameters that declare an `enum` of allowed values: a static literal
7
- * argument (string, number, or boolean) must be one of those values
8
- * (case-insensitive). Variables and expressions are skipped because their
9
- * value cannot be determined statically.
7
+ * argument (string, number, or boolean) must be one of those values. Primitive
8
+ * types are preserved; string values compare case-insensitively only with other
9
+ * strings. Variables and expressions are skipped because their value cannot be
10
+ * determined statically.
10
11
  *
11
12
  * This rule is the AMPscript counterpart of `ssjs-arg-types` and may be
12
13
  * expanded later to cover additional argument-type checks.
@@ -20,19 +21,52 @@ import { functionLookup } from 'ampscript-data';
20
21
  const STATIC_LITERAL_TYPES = new Set(['StringLiteral', 'NumberLiteral', 'BooleanLiteral']);
21
22
 
22
23
  /**
23
- * Returns the comparable string value of a static AMPscript literal node
24
- * (string, number, or boolean), or null when the argument is not a static
25
- * literal (e.g. a variable or expression) and cannot be validated against an
26
- * enum.
24
+ * Returns the primitive value of a static AMPscript literal node, or null when
25
+ * the argument is not a static literal (e.g. a variable or expression) and
26
+ * cannot be validated against an enum.
27
27
  *
28
28
  * @param {object} argument - AMPscript argument AST node.
29
- * @returns {string | null} The literal value as a string, or null.
29
+ * @returns {string | number | boolean | null} The type-preserved literal value, or null.
30
30
  */
31
31
  function staticLiteralValue(argument) {
32
32
  if (!argument || !STATIC_LITERAL_TYPES.has(argument.type)) {
33
33
  return null;
34
34
  }
35
- return String(argument.value);
35
+ if (argument.type === 'NumberLiteral') {
36
+ return Number(argument.value);
37
+ }
38
+ return argument.type === 'BooleanLiteral'
39
+ ? String(argument.value).toLowerCase() === 'true'
40
+ : String(argument.value);
41
+ }
42
+
43
+ /**
44
+ * Compare a static literal with one catalog enum member without collapsing
45
+ * strings, numbers, and booleans into the same textual value. String matching
46
+ * remains case-insensitive.
47
+ *
48
+ * @param {string | number | boolean} allowed - Catalog enum member.
49
+ * @param {string | number | boolean} actual - Static AMPscript literal value.
50
+ * @returns {boolean} Whether the values match with type-sensitive semantics.
51
+ */
52
+ function enumValueMatches(allowed, actual) {
53
+ if (typeof allowed !== typeof actual) {
54
+ return false;
55
+ }
56
+ return typeof allowed === 'string' && typeof actual === 'string'
57
+ ? allowed.toLowerCase() === actual.toLowerCase()
58
+ : allowed === actual;
59
+ }
60
+
61
+ /**
62
+ * Format a catalog enum member as an AMPscript literal so string members are
63
+ * visibly distinct from number and boolean members in diagnostics.
64
+ *
65
+ * @param {string | number | boolean} value - Catalog enum member.
66
+ * @returns {string} AMPscript literal text.
67
+ */
68
+ function formatEnumLiteral(value) {
69
+ return typeof value === 'string' ? `"${value}"` : String(value);
36
70
  }
37
71
 
38
72
  export default {
@@ -73,8 +107,8 @@ export default {
73
107
  if (actual === null) {
74
108
  continue;
75
109
  }
76
- const isAllowed = parameter.enum.some(
77
- (v) => String(v).toLowerCase() === actual.toLowerCase(),
110
+ const isAllowed = parameter.enum.some((value) =>
111
+ enumValueMatches(value, actual),
78
112
  );
79
113
  if (!isAllowed) {
80
114
  context.report({
@@ -83,7 +117,9 @@ export default {
83
117
  data: {
84
118
  name: entry.name,
85
119
  param: parameter.name,
86
- allowed: parameter.enum.join(', '),
120
+ allowed: parameter.enum
121
+ .map((value) => formatEnumLiteral(value))
122
+ .join(', '),
87
123
  actual,
88
124
  },
89
125
  });
@@ -45,13 +45,9 @@ function checkRepeatGroups(entry, callArguments) {
45
45
  : null;
46
46
  }
47
47
  const trailing = actual - startIndex;
48
- if (trailing % groupSize !== 0) {
49
- return incompleteGroup(entry, groupSize);
50
- }
51
- if (trailing / groupSize < minGroups) {
52
- return incompleteGroup(entry, groupSize);
53
- }
54
- return null;
48
+ return trailing % groupSize !== 0 || trailing / groupSize < minGroups
49
+ ? incompleteGroup(entry, groupSize)
50
+ : null;
55
51
  }
56
52
 
57
53
  // Two repeating groups (DataExtension Update/Upsert family): the first group's
@@ -71,10 +67,9 @@ function checkRepeatGroups(entry, callArguments) {
71
67
  const group1Arguments = countArgument * g1.groupSize;
72
68
  const group2Start = g1.startIndex + group1Arguments;
73
69
  const group2Count = actual - group2Start;
74
- if (group2Count <= 0 || group2Count % g2.groupSize !== 0) {
75
- return incompleteGroup(entry, g2.groupSize);
76
- }
77
- return null;
70
+ return group2Count <= 0 || group2Count % g2.groupSize !== 0
71
+ ? incompleteGroup(entry, g2.groupSize)
72
+ : null;
78
73
  }
79
74
 
80
75
  /**
@@ -44,18 +44,16 @@ export default {
44
44
  }
45
45
 
46
46
  const key = name.toLowerCase();
47
- if (reported.has(key)) {
47
+ if (reported.has(key) || pattern.test(name)) {
48
48
  return;
49
49
  }
50
50
 
51
- if (!pattern.test(name)) {
52
- reported.add(key);
53
- context.report({
54
- node,
55
- messageId: 'badName',
56
- data: { name, format },
57
- });
58
- }
51
+ reported.add(key);
52
+ context.report({
53
+ node,
54
+ messageId: 'badName',
55
+ data: { name, format },
56
+ });
59
57
  },
60
58
  };
61
59
  },
@@ -34,17 +34,18 @@ export default {
34
34
  });
35
35
  }
36
36
  }
37
- if (statement.type === 'VarDeclaration') {
38
- const current = counterStack.at(-1);
39
- if (current) {
40
- for (const v of statement.variables) {
41
- if (v.value.toLowerCase() === current.toLowerCase()) {
42
- context.report({
43
- node: v,
44
- messageId: 'counterAssign',
45
- data: { name: v.value },
46
- });
47
- }
37
+ if (statement.type !== 'VarDeclaration') {
38
+ continue;
39
+ }
40
+ const current = counterStack.at(-1);
41
+ if (current) {
42
+ for (const v of statement.variables) {
43
+ if (v.value.toLowerCase() === current.toLowerCase()) {
44
+ context.report({
45
+ node: v,
46
+ messageId: 'counterAssign',
47
+ data: { name: v.value },
48
+ });
48
49
  }
49
50
  }
50
51
  }
@@ -47,19 +47,14 @@ function personalizationName(node) {
47
47
  }
48
48
  if (node.type === 'Identifier') {
49
49
  const lower = node.value.toLowerCase();
50
- if (functionNames.has(lower) || AMPSCRIPT_KEYWORDS.has(lower)) {
51
- return null;
52
- }
53
- if (isSystemPersonalizationString(node.value)) {
54
- return null;
55
- }
56
- return node.value;
50
+ return functionNames.has(lower) ||
51
+ AMPSCRIPT_KEYWORDS.has(lower) ||
52
+ isSystemPersonalizationString(node.value)
53
+ ? null
54
+ : node.value;
57
55
  }
58
56
  if (node.type === 'PersonalizationString') {
59
- if (isSystemPersonalizationString(node.value)) {
60
- return null;
61
- }
62
- return node.value;
57
+ return isSystemPersonalizationString(node.value) ? null : node.value;
63
58
  }
64
59
  return null;
65
60
  }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Rule: prefer-boolean-literal
3
+ *
4
+ * Recommends and safely fixes bare boolean literals for every catalogued
5
+ * boolean-like parameter, all of which accept the same eight static forms.
6
+ */
7
+
8
+ import { functionLookup } from 'ampscript-data';
9
+
10
+ const BOOLEAN_LIKE_ENUM = [true, false, 1, 0, 'true', 'false', '1', '0'];
11
+
12
+ /**
13
+ * Return the preferred boolean for an accepted alternative literal.
14
+ *
15
+ * @param {object} argument - AMPscript argument AST node.
16
+ * @returns {boolean | null} Preferred boolean, or null when no recommendation applies.
17
+ */
18
+ function preferredBoolean(argument) {
19
+ if (argument?.type === 'NumberLiteral') {
20
+ const value = Number(argument.value);
21
+ return value === 1 || (value !== 0 && null);
22
+ }
23
+ if (argument?.type === 'StringLiteral') {
24
+ const value = String(argument.value).toLowerCase();
25
+ if (value === 'true' || value === '1') {
26
+ return true;
27
+ }
28
+ if (value === 'false' || value === '0') {
29
+ return false;
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+
35
+ /**
36
+ * Check whether catalog metadata marks a parameter as boolean-like.
37
+ *
38
+ * @param {object} parameter - AMPscript catalog parameter.
39
+ * @returns {boolean} Whether the enum contains exactly the complete eight-value set.
40
+ */
41
+ export function isBooleanLikeParameter(parameter) {
42
+ return (
43
+ Array.isArray(parameter?.enum) &&
44
+ parameter.enum.length === BOOLEAN_LIKE_ENUM.length &&
45
+ BOOLEAN_LIKE_ENUM.every((value) => parameter.enum.includes(value))
46
+ );
47
+ }
48
+
49
+ export default {
50
+ meta: {
51
+ type: 'suggestion',
52
+ docs: {
53
+ description:
54
+ 'Auto-fix accepted boolean-like AMPscript alternatives to recommended bare booleans',
55
+ recommended: true,
56
+ },
57
+ fixable: 'code',
58
+ messages: {
59
+ preferBooleanLiteral:
60
+ "Use bare {{preferred}} for boolean-like argument '{{param}}' of '{{name}}' instead of {{actual}}.",
61
+ },
62
+ schema: [],
63
+ },
64
+
65
+ create(context) {
66
+ return {
67
+ FunctionCall(node) {
68
+ const entry = functionLookup.get(node.name.toLowerCase());
69
+ if (!entry || !Array.isArray(entry.params)) {
70
+ return;
71
+ }
72
+
73
+ for (const [index, argument] of node.arguments.entries()) {
74
+ const parameter = entry.params[index];
75
+ if (!isBooleanLikeParameter(parameter)) {
76
+ continue;
77
+ }
78
+ const preferred = preferredBoolean(argument);
79
+ if (preferred === null) {
80
+ continue;
81
+ }
82
+ context.report({
83
+ node: argument,
84
+ messageId: 'preferBooleanLiteral',
85
+ data: {
86
+ name: entry.name,
87
+ param: parameter.name,
88
+ preferred: String(preferred),
89
+ actual: context.sourceCode.getText(argument),
90
+ },
91
+ fix(fixer) {
92
+ return fixer.replaceText(argument, String(preferred));
93
+ },
94
+ });
95
+ }
96
+ },
97
+ };
98
+ },
99
+ };
@@ -43,21 +43,22 @@ export default {
43
43
  return;
44
44
  }
45
45
  const lower = name.toLowerCase();
46
- if (!declared.has(lower)) {
47
- const isFirstFix = !fixedVariables.has(lower);
48
- if (isFirstFix) {
49
- fixedVariables.add(lower);
50
- }
51
-
52
- context.report({
53
- node: node.target,
54
- messageId: 'undeclared',
55
- data: { name },
56
- fix: isFirstFix
57
- ? (fixer) => fixer.insertTextBefore(node, `var ${name}\n`)
58
- : undefined,
59
- });
46
+ if (declared.has(lower)) {
47
+ return;
60
48
  }
49
+ const isFirstFix = !fixedVariables.has(lower);
50
+ if (isFirstFix) {
51
+ fixedVariables.add(lower);
52
+ }
53
+
54
+ context.report({
55
+ node: node.target,
56
+ messageId: 'undeclared',
57
+ data: { name },
58
+ fix: isFirstFix
59
+ ? (fixer) => fixer.insertTextBefore(node, `var ${name}\n`)
60
+ : undefined,
61
+ });
61
62
  },
62
63
  };
63
64
  },
@@ -19,13 +19,7 @@ export const BINDING_PATTERN = /\{!\$([A-Za-z0-9_.]+)\}/g;
19
19
  * @returns {string | null} The simple helper name, or null.
20
20
  */
21
21
  export function simpleHelperName(path) {
22
- if (!path || path.type !== 'PathExpression') {
23
- return null;
24
- }
25
- if (path.data) {
26
- return null;
27
- }
28
- if ((path.depth ?? 0) > 0) {
22
+ if (!path || path.type !== 'PathExpression' || path.data || (path.depth ?? 0) > 0) {
29
23
  return null;
30
24
  }
31
25
  const parts = path.parts ?? [];
@@ -33,10 +27,7 @@ export function simpleHelperName(path) {
33
27
  return null;
34
28
  }
35
29
  const name = parts[0];
36
- if (!name || name === 'this') {
37
- return null;
38
- }
39
- return name;
30
+ return !name || name === 'this' ? null : name;
40
31
  }
41
32
 
42
33
  /**
@@ -105,14 +96,13 @@ export function closestMatch(word, candidates) {
105
96
 
106
97
  for (const candidate of candidates) {
107
98
  const distance = levenshtein(lowerWord, candidate.toLowerCase());
108
- if (distance < bestDistance) {
109
- bestDistance = distance;
110
- best = candidate;
99
+ if (!(distance < bestDistance)) {
100
+ continue;
111
101
  }
112
- }
113
102
 
114
- if (best !== null && bestDistance > 0 && bestDistance <= maxDistance) {
115
- return best;
103
+ bestDistance = distance;
104
+ best = candidate;
116
105
  }
117
- return null;
106
+
107
+ return best !== null && bestDistance > 0 && bestDistance <= maxDistance ? best : null;
118
108
  }
@@ -63,10 +63,9 @@ export default {
63
63
  * @returns {boolean} True when the item must be flagged.
64
64
  */
65
65
  function isUnsupported(since) {
66
- if (since === null || since === undefined) {
67
- return true;
68
- }
69
- return apiVersion !== null && since > apiVersion;
66
+ return (
67
+ since === null || since === undefined || (apiVersion !== null && since > apiVersion)
68
+ );
70
69
  }
71
70
 
72
71
  /**
@@ -35,9 +35,9 @@ export default {
35
35
  }
36
36
 
37
37
  let lengthExpression = null;
38
- if (containsMemberLength(test.right)) {
38
+ if (hasMemberLength(test.right)) {
39
39
  lengthExpression = test.right;
40
- } else if (containsMemberLength(test.left)) {
40
+ } else if (hasMemberLength(test.left)) {
41
41
  lengthExpression = test.left;
42
42
  }
43
43
 
@@ -57,15 +57,12 @@ export default {
57
57
  },
58
58
  };
59
59
 
60
- function containsMemberLength(node) {
61
- if (!node) {
62
- return false;
63
- }
64
- return (
65
- node.type === 'MemberExpression' &&
66
- node.property.type === 'Identifier' &&
67
- node.property.name === 'length'
68
- );
60
+ function hasMemberLength(node) {
61
+ return node
62
+ ? node.type === 'MemberExpression' &&
63
+ node.property.type === 'Identifier' &&
64
+ node.property.name === 'length'
65
+ : false;
69
66
  }
70
67
 
71
68
  function buildCacheFix(forNode, lengthExpression, context) {
@@ -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
  }