Skip to content

Commit 4d989bc

Browse files
author
Doug Toppin
committed
Address eslint, CodeQL recommendations and issues
1 parent b6c02f4 commit 4d989bc

18 files changed

+63
-34
lines changed

.github/workflows/cdk-nag.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
node-version: ${{ matrix.node-version }}
2424
- run: |
2525
cd source/constructs && npm i --only=dev
26-
npx cdk synth
26+
npx cdk synth

.github/workflows/code-style-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
node-version: ${{ matrix.node-version }}
3434
- run: |
3535
cd source && npm i --only=dev
36-
npx --y eslint . --ext .ts
36+
npx --y eslint . --ext .ts

.github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
- uses: github/codeql-action/init@v2
2222
with:
2323
languages: ${{ matrix.language }}
24-
- uses: github/codeql-action/analyze@v2
24+
- uses: github/codeql-action/analyze@v2

.github/workflows/run-unit-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
node-version: ${{ matrix.node-version }}
2424
- run: |
2525
cd deployment
26-
chmod +x ./run-unit-tests.sh && DEBUG=true ./run-unit-tests.sh
26+
chmod +x ./run-unit-tests.sh && DEBUG=true ./run-unit-tests.sh

.viperlightignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/*
2+
CONTRIBUTING.md:46
3+
CODE_OF_CONDUCT.md:4
4+
coverage/*
5+
.zip

.viperlightrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"all": true,
3+
"failOn": "medium"
4+
}

CONTRIBUTING.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ When filing an issue, please check [existing open](https://github.com/aws-soluti
2222
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2323

2424
1. You are working against the latest source on the _main_ branch.
25-
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
26-
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.
25+
1. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
26+
1. You open an issue to discuss any significant work - we would hate for your time to be wasted.
2727

2828
To send us a pull request, please:
2929

3030
1. Fork the repository.
31-
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
32-
3. Ensure local tests pass.
33-
4. Commit to your fork using clear commit messages.
34-
5. Send us a pull request, answering any default questions in the pull request interface.
35-
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
31+
1. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
32+
1. Ensure local tests pass.
33+
1. Commit to your fork using clear commit messages.
34+
1. Send us a pull request, answering any default questions in the pull request interface.
35+
1. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
3636

3737
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
3838

source/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.d.ts
33
node_modules
44
coverage
5+
**/test/*

source/.eslintrc.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"sourceType": "module",
1212
"project": "**/tsconfig.json"
1313
},
14-
"ignorePatterns": ["**/*.js"],
14+
"ignorePatterns": ["**/*.js", "**/node_modules/**"],
1515
"extends": [
1616
"eslint:recommended",
1717
"plugin:@typescript-eslint/recommended",
@@ -38,6 +38,8 @@
3838

3939
"jsdoc/require-param-type": ["off"],
4040
"jsdoc/require-returns-type": ["off"],
41-
"jsdoc/newline-after-description": ["off"]
41+
"jsdoc/newline-after-description": ["off"],
42+
43+
"import/no-unresolved": 1 // warn only on Unable to resolve path import/no-unresolved
4244
}
4345
}

source/constructs/lib/back-end/back-end-construct.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ export class BackEnd extends Construct {
155155
const cloudFrontDistributionProps: DistributionProps = {
156156
comment: "Image Handler Distribution for Serverless Image Handler",
157157
defaultBehavior: {
158-
origin: origin,
158+
origin,
159159
allowedMethods: AllowedMethods.ALLOW_GET_HEAD,
160160
viewerProtocolPolicy: ViewerProtocolPolicy.HTTPS_ONLY,
161-
originRequestPolicy: originRequestPolicy,
162-
cachePolicy: cachePolicy,
161+
originRequestPolicy,
162+
cachePolicy,
163163
},
164164
priceClass: props.cloudFrontPriceClass as PriceClass,
165165
enableLogging: true,
@@ -192,9 +192,9 @@ export class BackEnd extends Construct {
192192
{
193193
existingLambdaObj: imageHandlerLambdaFunction,
194194
insertHttpSecurityHeaders: false,
195-
logGroupProps: logGroupProps,
196-
cloudFrontDistributionProps: cloudFrontDistributionProps,
197-
apiGatewayProps: apiGatewayProps,
195+
logGroupProps,
196+
cloudFrontDistributionProps,
197+
apiGatewayProps,
198198
}
199199
);
200200

source/constructs/lib/common-resources/common-resources-construct.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class CommonResources extends Construct {
107107
attributeGroupName: Aws.STACK_NAME,
108108
description: "Attribute group for solution information",
109109
attributes: {
110-
applicationType: applicationType,
110+
applicationType,
111111
version: props.solutionVersion,
112112
solutionID: props.solutionId,
113113
solutionName: props.applicationName,

source/constructs/lib/serverless-image-stack.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ export class ServerlessImageHandlerStack extends Stack {
169169
solutionId: props.solutionId,
170170
solutionVersion: props.solutionVersion,
171171
solutionDisplayName: props.solutionDisplayName,
172-
sourceCodeBucketName: sourceCodeBucketName,
173-
sourceCodeKeyPrefix: sourceCodeKeyPrefix,
172+
sourceCodeBucketName,
173+
sourceCodeKeyPrefix,
174174
...solutionConstructProps,
175175
});
176176

@@ -180,8 +180,8 @@ export class ServerlessImageHandlerStack extends Stack {
180180
});
181181

182182
const backEnd = new BackEnd(this, "BackEnd", {
183-
sourceCodeBucketName: sourceCodeBucketName,
184-
sourceCodeKeyPrefix: sourceCodeKeyPrefix,
183+
sourceCodeBucketName,
184+
sourceCodeKeyPrefix,
185185
solutionVersion: props.solutionVersion,
186186
solutionDisplayName: props.solutionDisplayName,
187187
secretsManagerPolicy: commonResources.secretsManagerPolicy,

source/custom-resource/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export async function handler(event: CustomResourceRequest, context: LambdaConte
162162
* @param resourceProperties the parameters to include in the function to be performed
163163
*/
164164
async function performRequest(
165+
// eslint-disable-next-line @typescript-eslint/ban-types
165166
functionToPerform: Function,
166167
requestType: CustomResourceRequestTypes,
167168
allowedRequestTypes: CustomResourceRequestTypes[],

source/image-handler/image-handler.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class ImageHandler {
3030
* @param options Additional sharp options to be applied
3131
* @returns A Sharp image object
3232
*/
33+
// eslint-disable-next-line @typescript-eslint/ban-types
3334
private async instantiateSharpImage(originalImage: Buffer, edits: ImageEdits, options: Object): Promise<sharp.Sharp> {
3435
let image: sharp.Sharp = null;
3536

@@ -294,7 +295,7 @@ export class ImageHandler {
294295
}
295296

296297
/**
297-
* @param param
298+
* @param param Value of corner to check
298299
* @returns Boolean identifying whether roundCrop parameters are valid
299300
*/
300301
private validRoundCropParam(param: number) {
@@ -508,8 +509,8 @@ export class ImageHandler {
508509

509510
// Calculate the smart crop area
510511
return {
511-
left: left,
512-
top: top,
512+
left,
513+
top,
513514
width: extractWidth,
514515
height: extractHeight,
515516
};
@@ -520,6 +521,10 @@ export class ImageHandler {
520521
* @param response the response from a Rekognition detectFaces API call
521522
* @param faceIndex the index number of the face detected
522523
* @param boundingBox the box bounds
524+
* @param boundingBox.Height height of bounding box
525+
* @param boundingBox.Left left side of bounding box
526+
* @param boundingBox.Top top of bounding box
527+
* @param boundingBox.Width width of bounding box
523528
*/
524529
private handleBounds(
525530
response: Rekognition.DetectFacesResponse,
@@ -664,6 +669,6 @@ export class ImageHandler {
664669
imageBuffer = await image.toBuffer({ resolveWithObject: true });
665670
}
666671

667-
return { imageBuffer: imageBuffer, format: format };
672+
return { imageBuffer, format };
668673
}
669674
}

source/image-handler/image-request.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,12 @@ export class ImageRequest {
348348
}
349349
}
350350

351+
// eslint-disable-next-line jsdoc/require-returns-check
351352
/**
352353
* Parses the headers to be sent with the response.
353354
* @param event Lambda request body.
354355
* @param requestType Image handler request type.
355-
* @returns The headers to be sent with the response.
356+
* @returns (optional) The headers to be sent with the response.
356357
*/
357358
public parseImageHeaders(event: ImageHandlerEvent, requestType: RequestTypes): Headers {
358359
if (requestType === RequestTypes.DEFAULT) {

source/image-handler/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function handler(event: ImageHandlerEvent): Promise<ImageHandlerExe
5151
return {
5252
statusCode: StatusCodes.OK,
5353
isBase64Encoded: true,
54-
headers: headers,
54+
headers,
5555
body: processedRequest,
5656
};
5757
} catch (error) {
@@ -80,7 +80,7 @@ export async function handler(event: ImageHandlerEvent): Promise<ImageHandlerExe
8080
return {
8181
statusCode: error.status ? error.status : StatusCodes.INTERNAL_SERVER_ERROR,
8282
isBase64Encoded: true,
83-
headers: headers,
83+
headers,
8484
body: defaultFallbackImage.Body.toString("base64"),
8585
};
8686
} catch (error) {

source/image-handler/test/image-handler/content-moderation.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ImageEdits, ImageHandlerError, StatusCodes } from "../../lib";
1313

1414
const s3Client = new S3();
1515
const rekognitionClient = new Rekognition();
16-
//jest spy
16+
// jest spy
1717
const blurSpy = jest.spyOn(sharp.prototype, "blur");
1818

1919
describe("contentModeration", () => {

source/image-handler/thumbor-mapper.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class ThumborMapper {
7373
* @param filterValue The specified color value
7474
* @param currentEdits The edits to be performed
7575
*/
76+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7677
private mapBGColor(filterValue: string, currentEdits: Record<string, any>): void {
7778
const color = !ColorName[filterValue] ? `#${filterValue}` : filterValue;
7879

@@ -84,6 +85,7 @@ export class ThumborMapper {
8485
* @param filterValue The blur value provided
8586
* @param currentEdits The edits to be performed
8687
*/
88+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8789
private mapBlur(filterValue: string, currentEdits: Record<string, any>): void {
8890
const [radius, sigma] = filterValue.split(",").map((x) => (x === "" ? NaN : Number(x)));
8991
currentEdits.blur = !isNaN(sigma) ? sigma : radius / 2;
@@ -94,6 +96,7 @@ export class ThumborMapper {
9496
* @param filterValue the convolution value provided
9597
* @param currentEdits the edits to be performed
9698
*/
99+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
97100
private mapConvolution(filterValue: string, currentEdits: Record<string, any>): void {
98101
const values = filterValue.split(",");
99102
const matrix = values[0].split(";").map((str) => Number(str));
@@ -112,6 +115,7 @@ export class ThumborMapper {
112115
* @param filterValue The fill value provided
113116
* @param currentEdits The edits to be performed
114117
*/
118+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
115119
private mapFill(filterValue: string, currentEdits: Record<string, any>): void {
116120
if (currentEdits.resize === undefined) {
117121
currentEdits.resize = {};
@@ -131,6 +135,7 @@ export class ThumborMapper {
131135
* @param filterValue The output format
132136
* @param currentEdits The edits to be provided
133137
*/
138+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
134139
private mapFormat(filterValue: string, currentEdits: Record<string, any>): void {
135140
const imageFormatType = filterValue.replace(/[^0-9a-z]/gi, "").replace(/jpg/i, "jpeg") as ImageFormatTypes;
136141
const acceptedValues = [
@@ -153,6 +158,7 @@ export class ThumborMapper {
153158
* Adds withoutEnlargement option to resize in currentEdits object
154159
* @param currentEdits The edits to be perforemd
155160
*/
161+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
156162
private mapNoUpscale(currentEdits: Record<string, any>): void {
157163
if (currentEdits.resize === undefined) {
158164
currentEdits.resize = {};
@@ -166,6 +172,7 @@ export class ThumborMapper {
166172
* @param filterValue The ratio value
167173
* @param currentEdits The edits to be performed
168174
*/
175+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
169176
private mapResizeRatio(filterValue: string, currentEdits: Record<string, any>): void {
170177
if (currentEdits.resize === undefined) {
171178
currentEdits.resize = {};
@@ -186,6 +193,7 @@ export class ThumborMapper {
186193
* @param currentEdits The edits to be performed
187194
* @param fileFormat The image format
188195
*/
196+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
189197
private mapQuality(filterValue: string, currentEdits: Record<string, any>, fileFormat: ImageFormatTypes): void {
190198
const toSupportedImageFormatType = (format: ImageFormatTypes): ImageFormatTypes => {
191199
if ([ImageFormatTypes.JPG, ImageFormatTypes.JPEG].includes(format)) {
@@ -201,7 +209,6 @@ export class ThumborMapper {
201209
) {
202210
return format;
203211
}
204-
return;
205212
};
206213

207214
// trying to get a target image type base on `fileFormat` passed to the current method.
@@ -218,6 +225,7 @@ export class ThumborMapper {
218225
* Maps stretch fit to the current edits
219226
* @param currentEdits The edits to be performed
220227
*/
228+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221229
private mapStretch(currentEdits: Record<string, any>): void {
222230
if (currentEdits.resize === undefined) {
223231
currentEdits.resize = {};
@@ -233,6 +241,7 @@ export class ThumborMapper {
233241
* Maps upscale fit to the current edits
234242
* @param currentEdits The edits to be performed
235243
*/
244+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
236245
private mapUpscale(currentEdits: Record<string, any>): void {
237246
if (currentEdits.resize === undefined) {
238247
currentEdits.resize = {};
@@ -241,6 +250,7 @@ export class ThumborMapper {
241250
currentEdits.resize.fit = ImageFitTypes.INSIDE;
242251
}
243252

253+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
244254
private mapWatermark(filterValue: string, currentEdits: Record<string, any>): void {
245255
const options = filterValue.replace(/\s+/g, "").split(",");
246256
const [bucket, key, xPos, yPos, alpha, wRatio, hRatio] = options;
@@ -367,7 +377,7 @@ export class ThumborMapper {
367377
* @returns image edits associated with crop.
368378
*/
369379
private mapCrop(path: string): ImageEdits {
370-
const pathCropMatchResult = path.match(/\d+x\d+:\d+x\d+/g);
380+
const pathCropMatchResult = path.match(/\d{1,6}x\d{1,6}:\d{1,6}x\d{1,6}/g);
371381

372382
if (pathCropMatchResult) {
373383
const [leftTopPoint, rightBottomPoint] = pathCropMatchResult[0].split(":");

0 commit comments

Comments
 (0)