eslint-plugin-sfmc 0.1.3 → 1.0.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.
Files changed (55) hide show
  1. package/README.md +43 -47
  2. package/docs/rules/ssjs/arg-types.md +72 -0
  3. package/docs/rules/ssjs/core-method-arity.md +72 -0
  4. package/docs/rules/ssjs/no-deprecated-function.md +56 -0
  5. package/docs/rules/ssjs/no-property-call.md +95 -0
  6. package/docs/rules/ssjs/no-unknown-function.md +57 -0
  7. package/package.json +18 -5
  8. package/src/ampscript-parser.js +11 -4
  9. package/src/ampscript-processor.js +9 -3
  10. package/src/index.js +23 -33
  11. package/src/processor.js +12 -4
  12. package/src/rules/amp/function-arity.js +3 -1
  13. package/src/rules/amp/naming-convention.js +7 -3
  14. package/src/rules/amp/no-deprecated-function.js +6 -2
  15. package/src/rules/amp/no-email-excluded-function.js +3 -1
  16. package/src/rules/amp/no-inline-statement.js +3 -1
  17. package/src/rules/amp/no-nested-ampscript-delimiter.js +5 -5
  18. package/src/rules/amp/no-nested-script-tag.js +3 -1
  19. package/src/rules/amp/no-smart-quotes.js +1 -1
  20. package/src/rules/amp/prefer-attribute-value.js +10 -4
  21. package/src/rules/amp/require-rowcount-check.js +3 -1
  22. package/src/rules/amp/require-variable-declaration.js +7 -3
  23. package/src/rules/ssjs/cache-loop-length.js +10 -4
  24. package/src/rules/ssjs/no-deprecated-function.js +181 -0
  25. package/src/rules/ssjs/no-hardcoded-credentials.js +3 -1
  26. package/src/rules/ssjs/no-property-call.js +136 -0
  27. package/src/rules/ssjs/no-treatascontent-injection.js +8 -4
  28. package/src/rules/ssjs/no-unavailable-method.js +30 -10
  29. package/src/rules/ssjs/no-unknown-function.js +236 -0
  30. package/src/rules/ssjs/no-unsupported-syntax.js +10 -5
  31. package/src/rules/ssjs/platform-function-arity.js +6 -2
  32. package/src/rules/ssjs/prefer-parsejson-safe-arg.js +17 -9
  33. package/src/rules/ssjs/prefer-platform-load-version.js +1 -4
  34. package/src/rules/ssjs/require-hasownproperty.js +34 -27
  35. package/src/rules/ssjs/require-platform-load-order.js +6 -2
  36. package/src/rules/ssjs/require-platform-load.js +32 -12
  37. package/src/rules/ssjs/ssjs-arg-types.js +345 -0
  38. package/src/rules/ssjs/ssjs-core-method-arity.js +176 -0
  39. package/src/ssjs-processor.js +3 -1
  40. package/docs/rules/ssjs/no-unknown-core-method.md +0 -46
  41. package/docs/rules/ssjs/no-unknown-http-method.md +0 -44
  42. package/docs/rules/ssjs/no-unknown-platform-client-browser.md +0 -44
  43. package/docs/rules/ssjs/no-unknown-platform-function.md +0 -44
  44. package/docs/rules/ssjs/no-unknown-platform-request.md +0 -43
  45. package/docs/rules/ssjs/no-unknown-platform-response.md +0 -43
  46. package/docs/rules/ssjs/no-unknown-platform-variable.md +0 -43
  47. package/docs/rules/ssjs/no-unknown-wsproxy-method.md +0 -46
  48. package/src/rules/ssjs/no-unknown-core-method.js +0 -103
  49. package/src/rules/ssjs/no-unknown-http-method.js +0 -41
  50. package/src/rules/ssjs/no-unknown-platform-client-browser.js +0 -50
  51. package/src/rules/ssjs/no-unknown-platform-function.js +0 -49
  52. package/src/rules/ssjs/no-unknown-platform-request.js +0 -50
  53. package/src/rules/ssjs/no-unknown-platform-response.js +0 -50
  54. package/src/rules/ssjs/no-unknown-platform-variable.js +0 -50
  55. package/src/rules/ssjs/no-unknown-wsproxy-method.js +0 -71
@@ -1,50 +0,0 @@
1
- /**
2
- * Rule: no-unknown-platform-client-browser
3
- *
4
- * Flags calls to Platform.ClientBrowser.* where the method name does not
5
- * exist in the known SFMC Platform.ClientBrowser catalog.
6
- */
7
-
8
- import { PLATFORM_CLIENT_BROWSER_METHODS } from 'ssjs-data';
9
-
10
- const knownMethods = new Set(PLATFORM_CLIENT_BROWSER_METHODS.map((m) => m.name.toLowerCase()));
11
-
12
- export default {
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Disallow calls to unknown Platform.ClientBrowser methods',
17
- },
18
- messages: {
19
- unknownMethod: "'Platform.ClientBrowser.{{name}}' is not a recognized method.",
20
- },
21
- schema: [],
22
- },
23
-
24
- create(context) {
25
- return {
26
- CallExpression(node) {
27
- const callee = node.callee;
28
- if (callee.type !== 'MemberExpression') return;
29
-
30
- if (
31
- callee.object.type === 'MemberExpression' &&
32
- callee.object.object.type === 'Identifier' &&
33
- callee.object.object.name === 'Platform' &&
34
- callee.object.property.type === 'Identifier' &&
35
- callee.object.property.name === 'ClientBrowser' &&
36
- callee.property.type === 'Identifier'
37
- ) {
38
- const methodName = callee.property.name;
39
- if (!knownMethods.has(methodName.toLowerCase())) {
40
- context.report({
41
- node: callee.property,
42
- messageId: 'unknownMethod',
43
- data: { name: methodName },
44
- });
45
- }
46
- }
47
- },
48
- };
49
- },
50
- };
@@ -1,49 +0,0 @@
1
- /**
2
- * Rule: no-unknown-platform-function
3
- *
4
- * Flags calls to Platform.Function.* where the method name does not
5
- * exist in the known SFMC Platform.Function catalog.
6
- */
7
-
8
- import { platformFunctionNames } from 'ssjs-data';
9
-
10
- export default {
11
- meta: {
12
- type: 'problem',
13
- docs: {
14
- description: 'Disallow calls to unknown Platform.Function methods',
15
- },
16
- messages: {
17
- unknownFunction:
18
- "'Platform.Function.{{name}}' is not a recognized SFMC Platform function.",
19
- },
20
- schema: [],
21
- },
22
-
23
- create(context) {
24
- return {
25
- CallExpression(node) {
26
- const callee = node.callee;
27
- if (callee.type !== 'MemberExpression') return;
28
-
29
- if (
30
- callee.object.type === 'MemberExpression' &&
31
- callee.object.object.type === 'Identifier' &&
32
- callee.object.object.name === 'Platform' &&
33
- callee.object.property.type === 'Identifier' &&
34
- callee.object.property.name === 'Function' &&
35
- callee.property.type === 'Identifier'
36
- ) {
37
- const methodName = callee.property.name;
38
- if (!platformFunctionNames.has(methodName.toLowerCase())) {
39
- context.report({
40
- node: callee.property,
41
- messageId: 'unknownFunction',
42
- data: { name: methodName },
43
- });
44
- }
45
- }
46
- },
47
- };
48
- },
49
- };
@@ -1,50 +0,0 @@
1
- /**
2
- * Rule: no-unknown-platform-request
3
- *
4
- * Flags calls to Platform.Request.* where the method name does not
5
- * exist in the known SFMC Platform.Request catalog.
6
- */
7
-
8
- import { PLATFORM_REQUEST_METHODS } from 'ssjs-data';
9
-
10
- const knownMethods = new Set(PLATFORM_REQUEST_METHODS.map((m) => m.name.toLowerCase()));
11
-
12
- export default {
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Disallow calls to unknown Platform.Request methods',
17
- },
18
- messages: {
19
- unknownMethod: "'Platform.Request.{{name}}' is not a recognized method.",
20
- },
21
- schema: [],
22
- },
23
-
24
- create(context) {
25
- return {
26
- CallExpression(node) {
27
- const callee = node.callee;
28
- if (callee.type !== 'MemberExpression') return;
29
-
30
- if (
31
- callee.object.type === 'MemberExpression' &&
32
- callee.object.object.type === 'Identifier' &&
33
- callee.object.object.name === 'Platform' &&
34
- callee.object.property.type === 'Identifier' &&
35
- callee.object.property.name === 'Request' &&
36
- callee.property.type === 'Identifier'
37
- ) {
38
- const methodName = callee.property.name;
39
- if (!knownMethods.has(methodName.toLowerCase())) {
40
- context.report({
41
- node: callee.property,
42
- messageId: 'unknownMethod',
43
- data: { name: methodName },
44
- });
45
- }
46
- }
47
- },
48
- };
49
- },
50
- };
@@ -1,50 +0,0 @@
1
- /**
2
- * Rule: no-unknown-platform-response
3
- *
4
- * Flags calls to Platform.Response.* where the method name does not
5
- * exist in the known SFMC Platform.Response catalog.
6
- */
7
-
8
- import { PLATFORM_RESPONSE_METHODS } from 'ssjs-data';
9
-
10
- const knownMethods = new Set(PLATFORM_RESPONSE_METHODS.map((m) => m.name.toLowerCase()));
11
-
12
- export default {
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Disallow calls to unknown Platform.Response methods',
17
- },
18
- messages: {
19
- unknownMethod: "'Platform.Response.{{name}}' is not a recognized method.",
20
- },
21
- schema: [],
22
- },
23
-
24
- create(context) {
25
- return {
26
- CallExpression(node) {
27
- const callee = node.callee;
28
- if (callee.type !== 'MemberExpression') return;
29
-
30
- if (
31
- callee.object.type === 'MemberExpression' &&
32
- callee.object.object.type === 'Identifier' &&
33
- callee.object.object.name === 'Platform' &&
34
- callee.object.property.type === 'Identifier' &&
35
- callee.object.property.name === 'Response' &&
36
- callee.property.type === 'Identifier'
37
- ) {
38
- const methodName = callee.property.name;
39
- if (!knownMethods.has(methodName.toLowerCase())) {
40
- context.report({
41
- node: callee.property,
42
- messageId: 'unknownMethod',
43
- data: { name: methodName },
44
- });
45
- }
46
- }
47
- },
48
- };
49
- },
50
- };
@@ -1,50 +0,0 @@
1
- /**
2
- * Rule: no-unknown-platform-variable
3
- *
4
- * Flags calls to Platform.Variable.* where the method name does not
5
- * exist in the known SFMC Platform.Variable catalog.
6
- */
7
-
8
- import { PLATFORM_VARIABLE_METHODS } from 'ssjs-data';
9
-
10
- const knownMethods = new Set(PLATFORM_VARIABLE_METHODS.map((m) => m.name.toLowerCase()));
11
-
12
- export default {
13
- meta: {
14
- type: 'problem',
15
- docs: {
16
- description: 'Disallow calls to unknown Platform.Variable methods',
17
- },
18
- messages: {
19
- unknownMethod: "'Platform.Variable.{{name}}' is not a recognized method.",
20
- },
21
- schema: [],
22
- },
23
-
24
- create(context) {
25
- return {
26
- CallExpression(node) {
27
- const callee = node.callee;
28
- if (callee.type !== 'MemberExpression') return;
29
-
30
- if (
31
- callee.object.type === 'MemberExpression' &&
32
- callee.object.object.type === 'Identifier' &&
33
- callee.object.object.name === 'Platform' &&
34
- callee.object.property.type === 'Identifier' &&
35
- callee.object.property.name === 'Variable' &&
36
- callee.property.type === 'Identifier'
37
- ) {
38
- const methodName = callee.property.name;
39
- if (!knownMethods.has(methodName.toLowerCase())) {
40
- context.report({
41
- node: callee.property,
42
- messageId: 'unknownMethod',
43
- data: { name: methodName },
44
- });
45
- }
46
- }
47
- },
48
- };
49
- },
50
- };
@@ -1,71 +0,0 @@
1
- /**
2
- * Rule: no-unknown-wsproxy-method
3
- *
4
- * Flags calls to WSProxy instances where the method name does not
5
- * exist in the known SFMC WSProxy method catalog.
6
- */
7
-
8
- import { wsproxyMethodNames } from 'ssjs-data';
9
-
10
- export default {
11
- meta: {
12
- type: 'problem',
13
- docs: {
14
- description: 'Disallow calls to unknown WSProxy methods',
15
- },
16
- messages: {
17
- unknownMethod: "'{{name}}' is not a recognized WSProxy method.",
18
- },
19
- schema: [],
20
- },
21
-
22
- create(context) {
23
- const wsproxyVariables = new Set();
24
-
25
- return {
26
- VariableDeclaration(node) {
27
- for (const decl of node.declarations) {
28
- if (
29
- decl.id &&
30
- decl.id.type === 'Identifier' &&
31
- decl.init &&
32
- decl.init.type === 'NewExpression' &&
33
- decl.init.callee.type === 'Identifier' &&
34
- decl.init.callee.name === 'WSProxy'
35
- ) {
36
- wsproxyVariables.add(decl.id.name);
37
- }
38
- }
39
- },
40
-
41
- AssignmentExpression(node) {
42
- if (
43
- node.left.type === 'Identifier' &&
44
- node.right.type === 'NewExpression' &&
45
- node.right.callee.type === 'Identifier' &&
46
- node.right.callee.name === 'WSProxy'
47
- ) {
48
- wsproxyVariables.add(node.left.name);
49
- }
50
- },
51
-
52
- CallExpression(node) {
53
- const callee = node.callee;
54
- if (callee.type !== 'MemberExpression') return;
55
- if (callee.object.type !== 'Identifier') return;
56
- if (callee.property.type !== 'Identifier') return;
57
-
58
- if (!wsproxyVariables.has(callee.object.name)) return;
59
-
60
- const methodName = callee.property.name;
61
- if (!wsproxyMethodNames.has(methodName.toLowerCase())) {
62
- context.report({
63
- node: callee.property,
64
- messageId: 'unknownMethod',
65
- data: { name: methodName },
66
- });
67
- }
68
- },
69
- };
70
- },
71
- };