Skip to content

Commit 06e3b62

Browse files
authored
Merge pull request #39 from reedham-aws/lint
ci: Add linter action and fix lint errors
2 parents 0f31dc4 + 7676c85 commit 06e3b62

13 files changed

+406
-486
lines changed

.github/workflows/check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
on:
2-
[pull_request]
3-
41
name: Check
52

3+
on:
4+
pull_request:
5+
66
jobs:
77
check:
88
name: Run Unit Tests

.github/workflows/lint.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
lint:
8+
name: Run Linter
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v5
13+
- name: Run eslint
14+
run: |
15+
npm ci
16+
npm run lint

__tests__/deep_equal.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('Deep Equal Tests', () => {
107107
});
108108

109109
test('Handle lambda function configuration objects', () => {
110-
const lambdaConfig1 = {
110+
const lambdaConfig1 = {
111111
FunctionName: 'test-function',
112112
Runtime: 'nodejs18.x',
113113
MemorySize: 512,

__tests__/function_create.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require('fs/promises');
2-
const path = require('path');
32
const core = require('@actions/core');
4-
const { LambdaClient, GetFunctionConfigurationCommand, CreateFunctionCommand, UpdateFunctionCodeCommand, GetFunctionCommand} = require('@aws-sdk/client-lambda');
3+
const { LambdaClient, GetFunctionConfigurationCommand, CreateFunctionCommand } = require('@aws-sdk/client-lambda');
54
const index = require('../index');
65
const { checkFunctionExists } = index;
76

__tests__/has_configuration_changed.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const core = require('@actions/core');
2-
const { isEmptyValue, cleanNullKeys, hasConfigurationChanged, deepEqual } = require('../index');
2+
const { isEmptyValue, cleanNullKeys, hasConfigurationChanged } = require('../index');
33

44
jest.mock('@actions/core');
55

__tests__/package_artifacts.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ describe('Package Artifacts Tests', () => {
176176

177177
test('should handle error during directory cleanup', async () => {
178178

179-
const expectedTempDir = '/mock/tmp/lambda-temp-1234567890';
180179
const expectedZipPath = '/mock/tmp/lambda-function-1234567890.zip';
181180

182181
const rmError = new Error('Failed to remove directory');
@@ -212,7 +211,7 @@ describe('Package Artifacts Tests', () => {
212211

213212
test('should handle error during file copying', async () => {
214213

215-
fs.cp.mockImplementation((src, dest, options) => {
214+
fs.cp.mockImplementation((src, _dest, _options) => {
216215
if (src.includes('file1.js')) {
217216
return Promise.reject(new Error('Failed to copy file'));
218217
}

__tests__/s3_bucket_operations.test.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,13 @@ describe('S3 Bucket Operations Tests', () => {
242242

243243
jest.spyOn(mainModule, 'createBucket').mockResolvedValue(true);
244244
mockS3Send.mockResolvedValueOnce({});
245-
try {
246-
await mainModule.uploadToS3(
247-
'/path/to/deployment.zip',
248-
'new-bucket',
249-
'lambda/function.zip',
250-
'us-east-1',
251-
'123456789012'
252-
);
253-
} catch (error) {
254-
throw error;
255-
}
245+
await mainModule.uploadToS3(
246+
'/path/to/deployment.zip',
247+
'new-bucket',
248+
'lambda/function.zip',
249+
'us-east-1',
250+
'123456789012'
251+
);
256252
expect(core.info).toHaveBeenCalledWith(expect.stringContaining('Bucket new-bucket does not exist. Attempting to create it'));
257253
expect(mockS3Send).toHaveBeenCalledWith(expect.any(PutObjectCommand));
258254
});
@@ -649,7 +645,6 @@ describe('S3 Bucket Operations Tests', () => {
649645

650646
mainModule.uploadToS3.mockReset();
651647

652-
const functionName = core.getInput('function-name');
653648
const s3Bucket = core.getInput('s3-bucket');
654649
if (s3Bucket) {
655650
await mainModule.uploadToS3('file.zip', s3Bucket, 'key.zip', 'region');

__tests__/update_function_code.test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,6 @@ describe('Lambda Function Code Tests', () => {
8585
const originalUpdateFunctionCode = index.updateFunctionCode;
8686

8787
index.updateFunctionCode = jest.fn().mockImplementation(async (client, params) => {
88-
const s3Result = {
89-
bucket: params.s3Bucket,
90-
key: params.s3Key
91-
};
92-
9388
const command = new UpdateFunctionCodeCommand({
9489
FunctionName: params.functionName,
9590
S3Bucket: params.s3Bucket,

__tests__/validations.test.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ describe('Validations Tests', () => {
4040
test('should handle empty memory size input', () => {
4141
jest.clearAllMocks();
4242
core.getInput.mockImplementation((name) => {
43-
if (name === 'memory-size') return '';
44-
if (name === 'function-name') return 'test-function';
45-
if (name === 'region') return 'us-east-1';
46-
if (name === 'code-artifacts-dir') return './artifacts';
47-
if (name === 'handler') return 'index.handler';
48-
if (name === 'runtime') return 'nodejs18.x';
43+
if (name === 'memory-size') return '';
44+
if (name === 'function-name') return 'test-function';
45+
if (name === 'region') return 'us-east-1';
46+
if (name === 'code-artifacts-dir') return './artifacts';
47+
if (name === 'handler') return 'index.handler';
48+
if (name === 'runtime') return 'nodejs18.x';
4949
return '';
5050
});
5151
const result = originalValidations.validateAllInputs();
@@ -56,12 +56,12 @@ describe('Validations Tests', () => {
5656
test('should handle non-numeric memory size input', () => {
5757
jest.clearAllMocks();
5858
core.getInput.mockImplementation((name) => {
59-
if (name === 'memory-size') return 'hello';
60-
if (name === 'function-name') return 'test-function';
61-
if (name === 'region') return 'us-east-1';
62-
if (name === 'code-artifacts-dir') return './artifacts';
63-
if (name === 'handler') return 'index.handler';
64-
if (name === 'runtime') return 'nodejs18.x';
59+
if (name === 'memory-size') return 'hello';
60+
if (name === 'function-name') return 'test-function';
61+
if (name === 'region') return 'us-east-1';
62+
if (name === 'code-artifacts-dir') return './artifacts';
63+
if (name === 'handler') return 'index.handler';
64+
if (name === 'runtime') return 'nodejs18.x';
6565
return '';
6666
});
6767
const result = originalValidations.validateAllInputs();
@@ -93,13 +93,13 @@ describe('Validations Tests', () => {
9393
test('should handle non-numeric memory size input', () => {
9494
jest.clearAllMocks();
9595
core.getInput.mockImplementation((name) => {
96-
if (name === 'timeout') return 'hello';
97-
if (name === 'function-name') return 'test-function';
98-
if (name === 'region') return 'us-east-1';
99-
if (name === 'code-artifacts-dir') return './artifacts';
100-
if (name === 'handler') return 'index.handler';
101-
if (name === 'runtime') return 'nodejs18.x';
102-
return '';
96+
if (name === 'timeout') return 'hello';
97+
if (name === 'function-name') return 'test-function';
98+
if (name === 'region') return 'us-east-1';
99+
if (name === 'code-artifacts-dir') return './artifacts';
100+
if (name === 'handler') return 'index.handler';
101+
if (name === 'runtime') return 'nodejs18.x';
102+
return '';
103103
});
104104
const result = originalValidations.validateAllInputs();
105105
expect(result.valid).toBe(false);
@@ -130,13 +130,13 @@ describe('Validations Tests', () => {
130130
test('should handle non-numeric memory size input', () => {
131131
jest.clearAllMocks();
132132
core.getInput.mockImplementation((name) => {
133-
if (name === 'ephemeral-storage') return 'hello';
134-
if (name === 'function-name') return 'test-function';
135-
if (name === 'region') return 'us-east-1';
136-
if (name === 'code-artifacts-dir') return './artifacts';
137-
if (name === 'handler') return 'index.handler';
138-
if (name === 'runtime') return 'nodejs18.x';
139-
return '';
133+
if (name === 'ephemeral-storage') return 'hello';
134+
if (name === 'function-name') return 'test-function';
135+
if (name === 'region') return 'us-east-1';
136+
if (name === 'code-artifacts-dir') return './artifacts';
137+
if (name === 'handler') return 'index.handler';
138+
if (name === 'runtime') return 'nodejs18.x';
139+
return '';
140140
});
141141
const result = originalValidations.validateAllInputs();
142142
expect(result.valid).toBe(false);
@@ -353,7 +353,7 @@ describe('Validations Tests', () => {
353353
test('should reject invalid source KMS key ARN format', () => {
354354
core.getInput.mockImplementation((name) => {
355355
if (name === 'kms-key-arn') return 'invalid:kms:key:arn';
356-
if (name === 'source-kms-key-arn') return 'invalid:kms:key:arn'
356+
if (name === 'source-kms-key-arn') return 'invalid:kms:key:arn';
357357
if (name === 'function-name') return 'test-function';
358358
if (name === 'region') return 'us-east-1';
359359
if (name === 'code-artifacts-dir') return './artifacts';
@@ -402,7 +402,7 @@ describe('Validations Tests', () => {
402402
test('should accept valid environment variables', () => {
403403
const mockGetInput = jest.fn((name) => {
404404
if (name === 'environment') {
405-
return '{"ENV":"prod","DEBUG":"true","API_URL":"https://api.example.com"}'
405+
return '{"ENV":"prod","DEBUG":"true","API_URL":"https://api.example.com"}';
406406
}
407407
const inputs = {
408408
'function-name': 'test-function',
@@ -889,7 +889,7 @@ describe('Validations Tests', () => {
889889
describe('VPC Configuration Edge Cases', () => {
890890
test('should reject vpc-config with malformed SubnetIds', () => {
891891
const invalidVpcConfig = JSON.stringify({
892-
SubnetIds: "subnet-123",
892+
SubnetIds: 'subnet-123',
893893
SecurityGroupIds: ['sg-123']
894894
});
895895
core.getInput.mockImplementation((name) => {
@@ -906,7 +906,7 @@ describe('Validations Tests', () => {
906906
const result = originalValidations.validateAllInputs();
907907
expect(result.valid).toBe(false);
908908
expect(core.setFailed).toHaveBeenCalledWith(
909-
expect.stringContaining("vpc-config must include 'SubnetIds' as an array")
909+
expect.stringContaining('vpc-config must include \'SubnetIds\' as an array')
910910
);
911911
});
912912
test('should reject vpc-config with empty SecurityGroupIds array', () => {
@@ -1010,7 +1010,7 @@ describe('Validations Tests', () => {
10101010
const result = originalValidations.validateAllInputs();
10111011
expect(result.valid).toBe(false);
10121012
expect(core.setFailed).toHaveBeenCalledWith(
1013-
expect.stringContaining("tracing-config Mode must be 'Active' or 'PassThrough'")
1013+
expect.stringContaining('tracing-config Mode must be \'Active\' or \'PassThrough\'')
10141014
);
10151015
});
10161016
});
@@ -1057,7 +1057,7 @@ describe('Validations Tests', () => {
10571057
const result = originalValidations.validateAllInputs();
10581058
expect(result.valid).toBe(false);
10591059
expect(core.setFailed).toHaveBeenCalledWith(
1060-
expect.stringContaining("snap-start ApplyOn must be 'PublishedVersions' or 'None'")
1060+
expect.stringContaining('snap-start ApplyOn must be \'PublishedVersions\' or \'None\'')
10611061
);
10621062
});
10631063
});
@@ -1077,7 +1077,7 @@ describe('Validations Tests', () => {
10771077
const result = originalValidations.validateAllInputs();
10781078
expect(result.valid).toBe(false);
10791079
expect(core.setFailed).toHaveBeenCalledWith(
1080-
expect.stringContaining("file-system-configs must be an array")
1080+
expect.stringContaining('file-system-configs must be an array')
10811081
);
10821082
});
10831083
test('should reject file-system-configs with missing Arn', () => {
@@ -1096,7 +1096,7 @@ describe('Validations Tests', () => {
10961096
const result = originalValidations.validateAllInputs();
10971097
expect(result.valid).toBe(false);
10981098
expect(core.setFailed).toHaveBeenCalledWith(
1099-
expect.stringContaining("Each file-system-config must include 'Arn' and 'LocalMountPath'")
1099+
expect.stringContaining('Each file-system-config must include \'Arn\' and \'LocalMountPath\'')
11001100
);
11011101
});
11021102
test('should validate multiple file system configs', () => {
@@ -1154,7 +1154,7 @@ describe('Validations Tests', () => {
11541154
const result = originalValidations.validateAllInputs();
11551155
expect(result.valid).toBe(false);
11561156
expect(core.setFailed).toHaveBeenCalledWith(
1157-
expect.stringContaining("tags must be an object of key-value pairs")
1157+
expect.stringContaining('tags must be an object of key-value pairs')
11581158
);
11591159
});
11601160
});

0 commit comments

Comments
 (0)