eslint-plugin-lambda-security 1.2.3 → 1.2.4

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.
@@ -12,7 +12,10 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
12
12
  meta: {
13
13
  type: 'problem',
14
14
  docs: {
15
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-error-swallowing.md',
15
16
  description: 'Detects empty catch blocks and missing error logging in Lambda handlers',
17
+ cwe: 'CWE-390',
18
+ cvss: 5,
16
19
  },
17
20
  hasSuggestions: true,
18
21
  messages: {
@@ -55,7 +58,7 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
55
58
  defaultOptions: [{ allowInTests: true, allowWithComment: true }],
56
59
  create(context, [options = {}]) {
57
60
  const { allowInTests = true, allowWithComment = true } = options;
58
- const filename = context.filename || context.getFilename();
61
+ const filename = context.filename;
59
62
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
60
63
  if (allowInTests && isTestFile) {
61
64
  return {};
@@ -64,54 +67,21 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
64
67
  * Check if a catch block has any logging
65
68
  */
66
69
  function hasLogging(block) {
67
- let found = false;
68
- function checkNode(node) {
69
- if (node.type === eslint_devkit_1.AST_NODE_TYPES.CallExpression) {
70
- const callee = node.callee;
71
- // console.log, console.error, console.warn
72
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
73
- callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
74
- callee.object.name === 'console') {
75
- found = true;
76
- return;
77
- }
78
- // logger.error, logger.warn, etc.
79
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
80
- callee.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
81
- ['logger', 'log', 'winston', 'pino', 'bunyan'].includes(callee.object.name)) {
82
- found = true;
83
- return;
84
- }
85
- // Direct function call that includes 'log' or 'error'
86
- if (callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
87
- /log|error|warn/i.test(callee.name)) {
88
- found = true;
89
- return;
90
- }
91
- }
92
- // Recursively check child nodes
93
- for (const key of Object.keys(node)) {
94
- const child = node[key];
95
- if (child && typeof child === 'object' && 'type' in child) {
96
- checkNode(child);
97
- }
98
- else if (Array.isArray(child)) {
99
- for (const item of child) {
100
- // Use Object.prototype.hasOwnProperty to avoid 'in' operator narrowing issues
101
- if (item !== null &&
102
- item !== undefined &&
103
- typeof item === 'object' &&
104
- Object.prototype.hasOwnProperty.call(item, 'type')) {
105
- checkNode(item);
106
- }
107
- }
108
- }
109
- }
70
+ const sourceCode = context.sourceCode;
71
+ const blockText = sourceCode.getText(block);
72
+ // console.log/error/warn/info/debug
73
+ if (/console\.\s*(log|error|warn|info|debug)\s*\(/.test(blockText)) {
74
+ return true;
75
+ }
76
+ // logger.error, winston.error, pino.error, bunyan.error, log.error
77
+ if (/(logger|log|winston|pino|bunyan)\.\s*(error|warn|info|debug|log)\s*\(/.test(blockText)) {
78
+ return true;
110
79
  }
111
- for (const stmt of block.body) {
112
- checkNode(stmt);
80
+ // Direct function call: logError(), reportError(), warnUser()
81
+ if (/\b(log|error|warn)\w*\s*\(/.test(blockText)) {
82
+ return true;
113
83
  }
114
- return found;
84
+ return false;
115
85
  }
116
86
  /**
117
87
  * Check if block has comments indicating intentional swallowing
@@ -119,7 +89,7 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
119
89
  function hasIntentionalComment(node) {
120
90
  if (!allowWithComment)
121
91
  return false;
122
- const sourceCode = context.sourceCode || context.getSourceCode();
92
+ const sourceCode = context.sourceCode;
123
93
  const comments = sourceCode.getCommentsInside(node.body);
124
94
  return comments.some((comment) => /intentional|expected|ignore|suppress|handled|silent/i.test(comment.value));
125
95
  }
@@ -171,7 +141,7 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
171
141
  const returnStmt = body.body.find((s) => s.type === eslint_devkit_1.AST_NODE_TYPES.ReturnStatement);
172
142
  if (returnStmt?.argument) {
173
143
  // Check if return includes status 500 or error body
174
- const sourceCode = context.sourceCode || context.getSourceCode();
144
+ const sourceCode = context.sourceCode;
175
145
  const returnText = sourceCode.getText(returnStmt.argument);
176
146
  if (/500|error|fail/i.test(returnText)) {
177
147
  return; // Acceptable error handling
@@ -182,12 +152,6 @@ exports.noErrorSwallowing = (0, eslint_devkit_1.createRule)({
182
152
  context.report({
183
153
  node,
184
154
  messageId: 'emptyCatchBlock',
185
- suggest: [
186
- {
187
- messageId: 'addErrorLogging',
188
- fix: () => null,
189
- },
190
- ],
191
155
  });
192
156
  }
193
157
  }
@@ -16,7 +16,10 @@ exports.noExposedDebugEndpoints = (0, eslint_devkit_1.createRule)({
16
16
  meta: {
17
17
  type: 'problem',
18
18
  docs: {
19
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-debug-endpoints.md',
19
20
  description: 'Detect debug endpoints without auth in AWS Lambda handlers',
21
+ cwe: 'CWE-489',
22
+ cvss: 7.5,
20
23
  },
21
24
  messages: {
22
25
  violationDetected: (0, eslint_devkit_1.formatLLMMessage)({
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noExposedErrorDetails = void 0;
9
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
10
  // Properties that expose internal details
11
- const SENSITIVE_ERROR_PROPERTIES = [
11
+ const SENSITIVE_ERROR_PROPERTIES = new Set([
12
12
  'stack',
13
13
  'stackTrace',
14
14
  'trace',
@@ -19,13 +19,16 @@ const SENSITIVE_ERROR_PROPERTIES = [
19
19
  'hostname',
20
20
  'config',
21
21
  'env',
22
- ];
22
+ ]);
23
23
  exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
24
24
  name: 'no-exposed-error-details',
25
25
  meta: {
26
26
  type: 'problem',
27
27
  docs: {
28
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-exposed-error-details.md',
28
29
  description: 'Detects Lambda handlers exposing internal error details in responses',
30
+ cwe: 'CWE-209',
31
+ cvss: 4.3,
29
32
  },
30
33
  hasSuggestions: true,
31
34
  messages: {
@@ -64,7 +67,7 @@ exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
64
67
  defaultOptions: [{ allowInTests: true }],
65
68
  create(context, [options = {}]) {
66
69
  const { allowInTests = true } = options;
67
- const filename = context.filename || context.getFilename();
70
+ const filename = context.filename;
68
71
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
69
72
  if (allowInTests && isTestFile) {
70
73
  return {};
@@ -84,7 +87,7 @@ exports.noExposedErrorDetails = (0, eslint_devkit_1.createRule)({
84
87
  */
85
88
  function getSensitiveProperty(node) {
86
89
  if (node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
87
- if (SENSITIVE_ERROR_PROPERTIES.includes(node.property.name)) {
90
+ if (SENSITIVE_ERROR_PROPERTIES.has(node.property.name)) {
88
91
  return node.property.name;
89
92
  }
90
93
  }
@@ -22,7 +22,7 @@ const CREDENTIAL_PROPERTY_NAMES = [
22
22
  'awsSecretAccessKey',
23
23
  ];
24
24
  // AWS SDK v3 client names
25
- const AWS_SDK_V3_CLIENTS = [
25
+ const AWS_SDK_V3_CLIENTS = new Set([
26
26
  'S3Client',
27
27
  'DynamoDBClient',
28
28
  'LambdaClient',
@@ -43,13 +43,16 @@ const AWS_SDK_V3_CLIENTS = [
43
43
  'StepFunctionsClient',
44
44
  'RDSClient',
45
45
  'ElastiCacheClient',
46
- ];
46
+ ]);
47
47
  exports.noHardcodedCredentialsSdk = (0, eslint_devkit_1.createRule)({
48
48
  name: 'no-hardcoded-credentials-sdk',
49
49
  meta: {
50
50
  type: 'problem',
51
51
  docs: {
52
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-hardcoded-credentials-sdk.md',
52
53
  description: 'Detects hardcoded AWS credentials in SDK client configurations',
54
+ cwe: 'CWE-798',
55
+ cvss: 9.5,
53
56
  },
54
57
  hasSuggestions: true,
55
58
  messages: {
@@ -92,7 +95,7 @@ exports.noHardcodedCredentialsSdk = (0, eslint_devkit_1.createRule)({
92
95
  ],
93
96
  create(context, [options = {}]) {
94
97
  const { allowInTests = true } = options;
95
- const filename = context.filename || context.getFilename();
98
+ const filename = context.filename;
96
99
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
97
100
  if (allowInTests && isTestFile) {
98
101
  return {};
@@ -117,7 +120,7 @@ exports.noHardcodedCredentialsSdk = (0, eslint_devkit_1.createRule)({
117
120
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
118
121
  const name = node.callee.name;
119
122
  // Known AWS SDK v3 clients
120
- if (AWS_SDK_V3_CLIENTS.includes(name)) {
123
+ if (AWS_SDK_V3_CLIENTS.has(name)) {
121
124
  return name;
122
125
  }
123
126
  // Only match *Client if it looks like AWS (contains common AWS service prefixes)
@@ -26,7 +26,7 @@ const AUTHORIZATION_CHECK_PATTERNS = [
26
26
  'permissions',
27
27
  ];
28
28
  // Sensitive operations that require authorization
29
- const SENSITIVE_OPERATIONS = [
29
+ const SENSITIVE_OPERATIONS = new Set([
30
30
  // Database operations
31
31
  'query',
32
32
  'put',
@@ -45,15 +45,18 @@ const SENSITIVE_OPERATIONS = [
45
45
  'deleteItem',
46
46
  'updateItem',
47
47
  'getItem',
48
- ];
48
+ ]);
49
49
  // Event parameter names
50
- const EVENT_PARAM_NAMES = ['event', 'evt', 'e', 'request', 'req'];
50
+ const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
51
51
  exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
52
52
  name: 'no-missing-authorization-check',
53
53
  meta: {
54
54
  type: 'problem',
55
55
  docs: {
56
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-missing-authorization-check.md',
56
57
  description: 'Detects Lambda handlers without authorization checks',
58
+ cwe: 'CWE-862',
59
+ cvss: 7.5,
57
60
  },
58
61
  hasSuggestions: true,
59
62
  messages: {
@@ -103,7 +106,7 @@ exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
103
106
  ],
104
107
  create(context, [options = {}]) {
105
108
  const { allowInTests = true } = options;
106
- const filename = context.filename || context.getFilename();
109
+ const filename = context.filename;
107
110
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
108
111
  if (allowInTests && isTestFile) {
109
112
  return {};
@@ -119,7 +122,7 @@ exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
119
122
  function enterFunction(node) {
120
123
  // Check if this function has an event parameter
121
124
  const hasEvent = node.params.some((param) => param.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
122
- EVENT_PARAM_NAMES.includes(param.name));
125
+ EVENT_PARAM_NAMES.has(param.name));
123
126
  if (hasEvent) {
124
127
  currentFunctionNode = node;
125
128
  hasAuthCheck = false;
@@ -156,7 +159,7 @@ exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
156
159
  * Check if a member expression chain indicates auth check
157
160
  */
158
161
  function isAuthorizationAccess(node) {
159
- const sourceCode = context.sourceCode || context.getSourceCode();
162
+ const sourceCode = context.sourceCode;
160
163
  const text = sourceCode.getText(node);
161
164
  return AUTHORIZATION_CHECK_PATTERNS.some((pattern) => text.includes(pattern) ||
162
165
  text.toLowerCase().includes(pattern.toLowerCase()));
@@ -168,7 +171,7 @@ exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
168
171
  if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression) {
169
172
  const property = node.callee.property;
170
173
  if (property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
171
- if (SENSITIVE_OPERATIONS.includes(property.name)) {
174
+ if (SENSITIVE_OPERATIONS.has(property.name)) {
172
175
  return property.name;
173
176
  }
174
177
  }
@@ -179,7 +182,13 @@ exports.noMissingAuthorizationCheck = (0, eslint_devkit_1.createRule)({
179
182
  'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
180
183
  enterFunction(node);
181
184
  },
182
- 'ArrowFunctionExpression:exit, FunctionExpression:exit, FunctionDeclaration:exit'(node) {
185
+ 'ArrowFunctionExpression:exit'(node) {
186
+ exitFunction(node);
187
+ },
188
+ 'FunctionExpression:exit'(node) {
189
+ exitFunction(node);
190
+ },
191
+ 'FunctionDeclaration:exit'(node) {
183
192
  exitFunction(node);
184
193
  },
185
194
  // Detect authorization checks
@@ -8,15 +8,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noOverlyPermissiveIamPolicy = void 0;
9
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
10
  // IAM policy property names
11
- const POLICY_PROPERTIES = ['Resource', 'Action', 'Principal'];
11
+ const POLICY_PROPERTIES = new Set(['Resource', 'Action', 'Principal']);
12
12
  // Wildcards that indicate overly permissive
13
- const DANGEROUS_WILDCARDS = ['*', 'arn:aws:*', 'arn:*:*:*:*:*'];
13
+ const DANGEROUS_WILDCARDS = new Set(['*', 'arn:aws:*', 'arn:*:*:*:*:*']);
14
14
  exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
15
15
  name: 'no-overly-permissive-iam-policy',
16
16
  meta: {
17
17
  type: 'problem',
18
18
  docs: {
19
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-overly-permissive-iam-policy.md',
19
20
  description: 'Detects IAM policies with overly broad permissions (wildcards)',
21
+ cwe: 'CWE-732',
22
+ cvss: 6.5,
20
23
  },
21
24
  hasSuggestions: true,
22
25
  messages: {
@@ -55,7 +58,7 @@ exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
55
58
  defaultOptions: [{ allowInTests: true }],
56
59
  create(context, [options = {}]) {
57
60
  const { allowInTests = true } = options;
58
- const filename = context.filename || context.getFilename();
61
+ const filename = context.filename;
59
62
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
60
63
  if (allowInTests && isTestFile) {
61
64
  return {};
@@ -64,7 +67,7 @@ exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
64
67
  * Check if a value is a dangerous wildcard
65
68
  */
66
69
  function isDangerousWildcard(value) {
67
- return (DANGEROUS_WILDCARDS.includes(value) ||
70
+ return (DANGEROUS_WILDCARDS.has(value) ||
68
71
  (value.endsWith('*') && value.includes(':*:')));
69
72
  }
70
73
  /**
@@ -121,7 +124,7 @@ exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
121
124
  // Check for IAM policy properties
122
125
  if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier) {
123
126
  const keyName = node.key.name;
124
- if (POLICY_PROPERTIES.includes(keyName)) {
127
+ if (POLICY_PROPERTIES.has(keyName)) {
125
128
  checkPolicyProperty(node, keyName);
126
129
  }
127
130
  }
@@ -129,7 +132,7 @@ exports.noOverlyPermissiveIamPolicy = (0, eslint_devkit_1.createRule)({
129
132
  if (node.key.type === eslint_devkit_1.AST_NODE_TYPES.Literal &&
130
133
  typeof node.key.value === 'string') {
131
134
  const keyName = node.key.value;
132
- if (POLICY_PROPERTIES.includes(keyName)) {
135
+ if (POLICY_PROPERTIES.has(keyName)) {
133
136
  checkPolicyProperty(node, keyName);
134
137
  }
135
138
  }
@@ -12,7 +12,10 @@ exports.noPermissiveCorsMidly = (0, eslint_devkit_1.createRule)({
12
12
  meta: {
13
13
  type: 'problem',
14
14
  docs: {
15
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-middy.md',
15
16
  description: 'Detects @middy/http-cors middleware with permissive origin (*)',
17
+ cwe: 'CWE-942',
18
+ cvss: 7.5,
16
19
  },
17
20
  hasSuggestions: true,
18
21
  messages: {
@@ -50,7 +53,7 @@ exports.noPermissiveCorsMidly = (0, eslint_devkit_1.createRule)({
50
53
  defaultOptions: [{ allowInTests: true }],
51
54
  create(context, [options = {}]) {
52
55
  const { allowInTests = true } = options;
53
- const filename = context.filename || context.getFilename();
56
+ const filename = context.filename;
54
57
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
55
58
  if (allowInTests && isTestFile) {
56
59
  return {};
@@ -12,7 +12,10 @@ exports.noPermissiveCorsResponse = (0, eslint_devkit_1.createRule)({
12
12
  meta: {
13
13
  type: 'problem',
14
14
  docs: {
15
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-permissive-cors-response.md',
15
16
  description: 'Detects permissive CORS (Access-Control-Allow-Origin: *) in Lambda response headers',
17
+ cwe: 'CWE-942',
18
+ cvss: 7.5,
16
19
  },
17
20
  fixable: 'code',
18
21
  messages: {
@@ -62,7 +65,7 @@ exports.noPermissiveCorsResponse = (0, eslint_devkit_1.createRule)({
62
65
  ],
63
66
  create(context, [options = {}]) {
64
67
  const { allowInTests = true } = options;
65
- const filename = context.filename || context.getFilename();
68
+ const filename = context.filename;
66
69
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
67
70
  if (allowInTests && isTestFile) {
68
71
  return {};
@@ -72,6 +75,7 @@ exports.noPermissiveCorsResponse = (0, eslint_devkit_1.createRule)({
72
75
  * { statusCode, headers, body }
73
76
  */
74
77
  function isLambdaResponse(obj) {
78
+ // oxlint-disable-next-line prefer-set-has
75
79
  const propNames = obj.properties
76
80
  .filter((p) => p.type === eslint_devkit_1.AST_NODE_TYPES.Property)
77
81
  .map(p => (p.key.type === eslint_devkit_1.AST_NODE_TYPES.Identifier ? p.key.name : ''));
@@ -29,7 +29,10 @@ exports.noSecretsInEnv = (0, eslint_devkit_1.createRule)({
29
29
  meta: {
30
30
  type: 'problem',
31
31
  docs: {
32
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-secrets-in-env.md',
32
33
  description: 'Detects secrets directly assigned to environment variables',
34
+ cwe: 'CWE-798',
35
+ cvss: 9.5,
33
36
  },
34
37
  hasSuggestions: true,
35
38
  messages: {
@@ -65,7 +68,7 @@ exports.noSecretsInEnv = (0, eslint_devkit_1.createRule)({
65
68
  defaultOptions: [{ allowInTests: true, additionalPatterns: [] }],
66
69
  create(context, [options = {}]) {
67
70
  const { allowInTests = true, additionalPatterns = [] } = options;
68
- const filename = context.filename || context.getFilename();
71
+ const filename = context.filename;
69
72
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
70
73
  if (allowInTests && isTestFile) {
71
74
  return {};
@@ -8,20 +8,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.noUnboundedBatchProcessing = void 0;
9
9
  const eslint_devkit_1 = require("@interlace/eslint-devkit");
10
10
  // Event sources with Records array
11
- const BATCH_SOURCE_PROPERTIES = [
11
+ const BATCH_SOURCE_PROPERTIES = new Set([
12
12
  'Records', // SQS, SNS, DynamoDB Streams, Kinesis, S3
13
13
  'records', // Some custom structures
14
14
  'items', // Custom batches
15
15
  'messages', // Custom message batches
16
- ];
16
+ ]);
17
17
  // Event parameter names
18
- const EVENT_PARAM_NAMES = ['event', 'evt', 'e', 'request', 'req'];
18
+ const EVENT_PARAM_NAMES = new Set(['event', 'evt', 'e', 'request', 'req']);
19
19
  exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
20
20
  name: 'no-unbounded-batch-processing',
21
21
  meta: {
22
22
  type: 'problem',
23
23
  docs: {
24
+ url: 'https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin-lambda-security/docs/rules/no-unbounded-batch-processing.md',
24
25
  description: 'Detects processing batch records without size validation',
26
+ cwe: 'CWE-770',
27
+ cvss: 5.5,
25
28
  },
26
29
  hasSuggestions: true,
27
30
  messages: {
@@ -64,7 +67,7 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
64
67
  defaultOptions: [{ allowInTests: true, maxBatchSize: 100 }],
65
68
  create(context, [options = {}]) {
66
69
  const { allowInTests = true } = options;
67
- const filename = context.filename || context.getFilename();
70
+ const filename = context.filename;
68
71
  const isTestFile = /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(filename);
69
72
  if (allowInTests && isTestFile) {
70
73
  return {};
@@ -77,7 +80,7 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
77
80
  function enterFunction(node) {
78
81
  const hasEvent = node.params.some((p) => {
79
82
  if (p.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
80
- EVENT_PARAM_NAMES.includes(p.name)) {
83
+ EVENT_PARAM_NAMES.has(p.name)) {
81
84
  eventParamName.push(p.name);
82
85
  return true;
83
86
  }
@@ -115,7 +118,13 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
115
118
  'ArrowFunctionExpression, FunctionExpression, FunctionDeclaration'(node) {
116
119
  enterFunction(node);
117
120
  },
118
- 'ArrowFunctionExpression:exit, FunctionExpression:exit, FunctionDeclaration:exit'(node) {
121
+ 'ArrowFunctionExpression:exit'(node) {
122
+ exitFunction(node);
123
+ },
124
+ 'FunctionExpression:exit'(node) {
125
+ exitFunction(node);
126
+ },
127
+ 'FunctionDeclaration:exit'(node) {
119
128
  exitFunction(node);
120
129
  },
121
130
  // Detect event.Records access
@@ -126,7 +135,7 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
126
135
  if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
127
136
  eventParamName.includes(node.object.name) &&
128
137
  node.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
129
- BATCH_SOURCE_PROPERTIES.includes(node.property.name)) {
138
+ BATCH_SOURCE_PROPERTIES.has(node.property.name)) {
130
139
  batchAccessNodes.push({
131
140
  node,
132
141
  source: `${node.object.name}.${node.property.name}`,
@@ -138,7 +147,7 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
138
147
  // Check if this is Records.length
139
148
  if (node.object.type === eslint_devkit_1.AST_NODE_TYPES.MemberExpression &&
140
149
  node.object.property.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
141
- BATCH_SOURCE_PROPERTIES.includes(node.object.property.name)) {
150
+ BATCH_SOURCE_PROPERTIES.has(node.object.property.name)) {
142
151
  hasBatchSizeCheck = true;
143
152
  }
144
153
  }
@@ -152,13 +161,18 @@ exports.noUnboundedBatchProcessing = (0, eslint_devkit_1.createRule)({
152
161
  ['slice', 'splice', 'take', 'chunk'].includes(node.callee.property.name)) {
153
162
  hasBatchSizeCheck = true;
154
163
  }
164
+ // Also detect top-level function calls: chunk(arr, n), take(arr, n)
165
+ if (node.callee.type === eslint_devkit_1.AST_NODE_TYPES.Identifier &&
166
+ ['slice', 'splice', 'take', 'chunk'].includes(node.callee.name)) {
167
+ hasBatchSizeCheck = true;
168
+ }
155
169
  },
156
170
  // Detect size comparisons
157
171
  BinaryExpression(node) {
158
172
  if (!currentHandlerNode)
159
173
  return;
160
174
  if (['<', '<=', '>', '>='].includes(node.operator)) {
161
- const sourceCode = context.sourceCode || context.getSourceCode();
175
+ const sourceCode = context.sourceCode;
162
176
  const text = sourceCode.getText(node);
163
177
  if (/\.length|Records|records/.test(text)) {
164
178
  hasBatchSizeCheck = true;