-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(lint): Upgrade ESLint #704
Changes from all commits
40f6140
6782341
a8c53ed
2565987
cfa692c
58fff15
1ee31b7
7b353ca
8b3f2bc
9575802
0ed26da
728aec0
22e2dbc
06ea15a
db2569a
fe8de8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// @ts-check | ||
import react from "eslint-plugin-react"; | ||
import eslintReactHooks from "eslint-plugin-react-hooks"; | ||
import eslint from "@eslint/js"; | ||
import tseslint from "typescript-eslint"; | ||
import { fixupPluginRules, includeIgnoreFile } from "@eslint/compat"; | ||
import { fileURLToPath } from "url"; | ||
import path from "path"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const gitignorePath = path.resolve(__dirname, ".gitignore"); | ||
|
||
export default tseslint.config( | ||
eslint.configs.recommended, | ||
...tseslint.configs.recommended, | ||
// @ts-expect-error https://github.com/typescript-eslint/typescript-eslint/issues/8522 | ||
includeIgnoreFile(gitignorePath), | ||
{ | ||
plugins: { | ||
react, | ||
// @ts-expect-error https://github.com/facebook/react/pull/28773#issuecomment-2147149016 | ||
"react-hooks": fixupPluginRules(eslintReactHooks), | ||
}, | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
|
||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
}, | ||
|
||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
|
||
rules: { | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"react/react-in-jsx-scope": "off", | ||
"react-hooks/rules-of-hooks": "error", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/ban-ts-comment": [ | ||
"off", | ||
{ | ||
"ts-ignore": false, | ||
"ts-nocheck": false, | ||
"ts-check": true, | ||
"ts-expect-error": true, | ||
}, | ||
], | ||
}, | ||
}, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
import { describe, it, expect, vi, beforeEach, Mock } from "vitest"; | ||
import { APIGatewayEvent } from "aws-lambda"; | ||
import { handler } from "./getUploadUrl"; | ||
import { response } from "libs/handler-lib"; | ||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3"; | ||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import * as path from "node:path"; | ||
|
||
vi.mock("libs/handler-lib", () => ({ | ||
response: vi.fn(), | ||
|
@@ -29,7 +27,7 @@ describe("Handler for generating signed URL", () => { | |
vi.clearAllMocks(); | ||
process.env.attachmentsBucketName = "test-bucket"; | ||
process.env.attachmentsBucketRegion = "test-region"; | ||
(uuidv4 as vi.Mock).mockReturnValue("123e4567-e89b-12d3-a456-426614174000"); | ||
(uuidv4 as Mock).mockReturnValue("123e4567-e89b-12d3-a456-426614174000"); | ||
}); | ||
|
||
it("should return 400 if event body is missing", async () => { | ||
|
@@ -45,7 +43,7 @@ describe("Handler for generating signed URL", () => { | |
|
||
it("should return 200 with signed URL, bucket, and key", async () => { | ||
const mockUrl = "https://example.com/signed-url"; | ||
(getSignedUrl as vi.Mock).mockResolvedValueOnce(mockUrl); | ||
(getSignedUrl as Mock).mockResolvedValueOnce(mockUrl); | ||
|
||
const event = { | ||
body: JSON.stringify({ fileName: "test-file.pdf" }), | ||
|
@@ -61,11 +59,11 @@ describe("Handler for generating signed URL", () => { | |
key: "123e4567-e89b-12d3-a456-426614174000.pdf", | ||
}, | ||
}); | ||
expect(getSignedUrl).toHaveBeenCalled; | ||
expect(getSignedUrl).toHaveBeenCalled(); | ||
}); | ||
|
||
it("should return 500 if an error occurs during processing", async () => { | ||
(getSignedUrl as vi.Mock).mockRejectedValueOnce(new Error("Test error")); | ||
(getSignedUrl as Mock).mockRejectedValueOnce(new Error("Test error")); | ||
|
||
const event = { | ||
body: JSON.stringify({ fileName: "test-file.pdf" }), | ||
|
@@ -79,9 +77,14 @@ describe("Handler for generating signed URL", () => { | |
}); | ||
}); | ||
|
||
it("should throw an error if required environment variables are missing", () => { | ||
it("should throw an error if required environment variables are missing", async () => { | ||
delete process.env.attachmentsBucketName; | ||
|
||
expect(() => handler({} as APIGatewayEvent)).toThrowError; | ||
await handler({} as APIGatewayEvent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test never ran as it was never called – eslint caught the error and I fixed it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
expect(response).toHaveBeenCalledWith({ | ||
statusCode: 500, | ||
body: { message: "Internal server error" }, | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,10 @@ const s3 = new S3Client({ | |
}); | ||
|
||
export const handler = async (event: APIGatewayEvent) => { | ||
validateEnvVariable("attachmentsBucketName"); | ||
validateEnvVariable("attachmentsBucketRegion"); | ||
try { | ||
validateEnvVariable("attachmentsBucketName"); | ||
validateEnvVariable("attachmentsBucketRegion"); | ||
|
||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved these into the |
||
if (!event.body) { | ||
return response({ | ||
statusCode: 400, | ||
|
@@ -48,15 +49,3 @@ export const handler = async (event: APIGatewayEvent) => { | |
}); | ||
} | ||
}; | ||
|
||
function checkEnvVariables(requiredEnvVariables: string[]) { | ||
const missingVariables = requiredEnvVariables.filter( | ||
(envVar) => !process.env[envVar], | ||
); | ||
|
||
if (missingVariables.length > 0) { | ||
throw new Error( | ||
`Missing required environment variables: ${missingVariables.join(", ")}`, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs