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
@@ -79,10 +79,7 @@ export default {
79
79
 
80
80
  CallExpression(node) {
81
81
  const callee = node.callee;
82
- if (callee.type !== 'MemberExpression') {
83
- return;
84
- }
85
- if (callee.property.type !== 'Identifier') {
82
+ if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
86
83
  return;
87
84
  }
88
85
  const methodName = callee.property.name;
@@ -141,23 +138,21 @@ export default {
141
138
  // Instance sub-path: de.Rows.Add(...) where `de` is a tracked
142
139
  // DataExtension.Init(...) instance. Substitute the instance's
143
140
  // core type for the leftmost identifier and resolve the class key.
144
- if (objectPath) {
145
- const segments = objectPath.split('.');
146
- const rootCoreType = coreVariables.get(segments[0]);
147
- if (rootCoreType) {
148
- const resolvedPath = [rootCoreType, ...segments.slice(1)].join('.');
149
- const classLookup = coreMethodArityLookup.get(resolvedPath.toLowerCase());
150
- if (classLookup) {
151
- const entry = classLookup.get(methodName.toLowerCase());
152
- checkArity(
153
- entry,
154
- node.arguments,
155
- `${resolvedPath}.${methodName}`,
156
- callee.property,
157
- );
158
- }
159
- }
141
+ if (!objectPath) {
142
+ return;
143
+ }
144
+ const segments = objectPath.split('.');
145
+ const rootCoreType = coreVariables.get(segments[0]);
146
+ if (!rootCoreType) {
147
+ return;
148
+ }
149
+ const resolvedPath = [rootCoreType, ...segments.slice(1)].join('.');
150
+ const classLookup = coreMethodArityLookup.get(resolvedPath.toLowerCase());
151
+ if (!classLookup) {
152
+ return;
160
153
  }
154
+ const entry = classLookup.get(methodName.toLowerCase());
155
+ checkArity(entry, node.arguments, `${resolvedPath}.${methodName}`, callee.property);
161
156
  },
162
157
  };
163
158
  },
@@ -168,10 +163,11 @@ function getCoreInitType(node) {
168
163
  return null;
169
164
  }
170
165
  const callee = node.callee;
171
- if (callee.type !== 'MemberExpression') {
172
- return null;
173
- }
174
- if (callee.property.type !== 'Identifier' || callee.property.name !== 'Init') {
166
+ if (
167
+ callee.type !== 'MemberExpression' ||
168
+ callee.property.type !== 'Identifier' ||
169
+ callee.property.name !== 'Init'
170
+ ) {
175
171
  return null;
176
172
  }
177
173
  if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
@@ -101,10 +101,7 @@ export default {
101
101
 
102
102
  CallExpression(node) {
103
103
  const callee = node.callee;
104
- if (callee.type !== 'MemberExpression') {
105
- return;
106
- }
107
- if (callee.property.type !== 'Identifier') {
104
+ if (callee.type !== 'MemberExpression' || callee.property.type !== 'Identifier') {
108
105
  return;
109
106
  }
110
107
  const methodName = callee.property.name;
@@ -167,25 +164,21 @@ export default {
167
164
  // Instance sub-path: de.Rows.Add(...) where `de` is a tracked
168
165
  // Init(...) instance. Substitute the instance's core type for the
169
166
  // leftmost identifier and resolve the class key.
170
- if (objectPath) {
171
- const segments = objectPath.split('.');
172
- const rootCoreType = coreVariables.get(segments[0]);
173
- if (rootCoreType) {
174
- const resolvedPath = [rootCoreType, ...segments.slice(1)].join('.');
175
- const classLookup = coreNonFunctionalMethodLookup.get(
176
- resolvedPath.toLowerCase(),
177
- );
178
- if (classLookup) {
179
- const entry = classLookup.get(methodName.toLowerCase());
180
- checkNonFunctional(
181
- entry,
182
- `${resolvedPath}.${methodName}`,
183
- callee.property,
184
- true,
185
- );
186
- }
187
- }
167
+ if (!objectPath) {
168
+ return;
188
169
  }
170
+ const segments = objectPath.split('.');
171
+ const rootCoreType = coreVariables.get(segments[0]);
172
+ if (!rootCoreType) {
173
+ return;
174
+ }
175
+ const resolvedPath = [rootCoreType, ...segments.slice(1)].join('.');
176
+ const classLookup = coreNonFunctionalMethodLookup.get(resolvedPath.toLowerCase());
177
+ if (!classLookup) {
178
+ return;
179
+ }
180
+ const entry = classLookup.get(methodName.toLowerCase());
181
+ checkNonFunctional(entry, `${resolvedPath}.${methodName}`, callee.property, true);
189
182
  },
190
183
  };
191
184
  },
@@ -202,10 +195,11 @@ function getCoreInitType(node) {
202
195
  return null;
203
196
  }
204
197
  const callee = node.callee;
205
- if (callee.type !== 'MemberExpression') {
206
- return null;
207
- }
208
- 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
+ ) {
209
203
  return null;
210
204
  }
211
205
  if (callee.object.type === 'Identifier' && coreObjectNames.has(callee.object.name)) {
@@ -36,11 +36,7 @@ export function preprocess(text, filename) {
36
36
  });
37
37
  }
38
38
 
39
- if (blocks.length === 0) {
40
- return [text];
41
- }
42
-
43
- return blocks;
39
+ return blocks.length === 0 ? [text] : blocks;
44
40
  }
45
41
 
46
42
  export function postprocess(messages, _filename) {