diff --git a/eslint.config.mjs b/eslint.config.mjs index a25433e..fc00f9f 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,7 +9,6 @@ export default tseslint.config( { rules: { // TODO: Remove ignored rules and fix the code - "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-this-alias": "off", "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-var-requires": "off", diff --git a/examples/express-sample/package-lock.json b/examples/express-sample/package-lock.json index fcbae9b..c70a2f9 100644 --- a/examples/express-sample/package-lock.json +++ b/examples/express-sample/package-lock.json @@ -21,6 +21,7 @@ } }, "../..": { + "name": "raygun", "version": "0.13.2", "dependencies": { "@types/express": "^4.17.21", @@ -30,9 +31,11 @@ "uuid": "^9.0.1" }, "devDependencies": { + "@eslint/js": "^9.1.1", "@types/node": "^20.12.7", "@types/stack-trace": "0.0.33", "@types/uuid": "^9.0.8", + "eslint": "^8.57.0", "express": "^4.19.2", "http-terminator": "^3.2.0", "jshint": "^2.13.6", @@ -41,10 +44,8 @@ "semver": "^7.6.0", "tap": "^18.7.2", "ts-node": "^10.9.2", - "tslint": "^6.1.1", - "tslint-config-prettier": "^1.18.0", - "tslint-react": "^5.0.0", "typescript": "^5.4.5", + "typescript-eslint": "^7.7.1", "verror": "^1.10.1" }, "engines": { diff --git a/lib/raygun.batch.ts b/lib/raygun.batch.ts index 05cb9de..cc4ccf1 100644 --- a/lib/raygun.batch.ts +++ b/lib/raygun.batch.ts @@ -32,7 +32,7 @@ export const MAX_BATCH_SIZE_BYTES = 1638400; const MAX_BATCH_INNER_SIZE_BYTES = MAX_BATCH_SIZE_BYTES - 2; // for the starting and ending byte export class RaygunBatchTransport { - private timerId: any | null = null; + private timerId: NodeJS.Timeout | null = null; private httpOptions: HTTPOptions; private interval: number; private batchId: number = 0; diff --git a/lib/raygun.messageBuilder.ts b/lib/raygun.messageBuilder.ts index 64bfb19..cc43a95 100644 --- a/lib/raygun.messageBuilder.ts +++ b/lib/raygun.messageBuilder.ts @@ -31,18 +31,21 @@ type UserMessageData = RawUserData | string | undefined; const humanString = require("object-to-human-string"); const packageDetails = require("../package.json"); -function filterKeys(obj: { [key: string]: any }, filters: string[]) { +function filterKeys(obj: object, filters: string[]): object { if (!obj || !filters || typeof obj !== "object") { return obj; } + // Make temporary copy of the object to avoid mutating the original + // Cast to Record to enforce type check and avoid using any + const _obj = { ...obj } as Record; Object.keys(obj).forEach(function (i) { if (filters.indexOf(i) > -1) { - delete obj[i]; + delete _obj[i]; } else { - obj[i] = filterKeys(obj[i], filters); + _obj[i] = filterKeys(_obj[i], filters); } }); - return obj; + return _obj; } function getStackTrace( @@ -126,7 +129,8 @@ export class RaygunMessageBuilder { return this.message as Message; } - setErrorDetails(error: any) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + setErrorDetails(error: Error | string | any) { if ( !(error instanceof Error) && typeof error !== "string" && diff --git a/lib/raygun.sync.worker.ts b/lib/raygun.sync.worker.ts index 46c4386..9f915df 100644 --- a/lib/raygun.sync.worker.ts +++ b/lib/raygun.sync.worker.ts @@ -1,17 +1,17 @@ import fs from "fs"; - import * as transport from "./raygun.transport"; import { SendOptions, SendOptionsWithoutCB } from "./types"; +import { IncomingMessage } from "http"; // Read stdin synchronously const data = fs.readFileSync(0, "utf-8"); const options: SendOptionsWithoutCB = JSON.parse(data); -const sendOptions = { ...options, callback }; +const sendOptions: SendOptions = { ...options, callback }; transport.send(sendOptions); -function callback(error: Error | null, result: any) { +function callback(error: Error | null, result: IncomingMessage | null) { if (error) { console.log("Error sending with sync transport", error); } else { diff --git a/lib/types.ts b/lib/types.ts index 410e792..9e18ffa 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,8 +1,9 @@ import type { IncomingMessage } from "http"; -export type IndexableError = Error & { - [key: string]: any; -}; +// IndexableError is a type that extends the Error type +// and allows for any additional properties to be added to it. +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export type IndexableError = Error & Record; export type MessageBuilderOptions = { reportColumnNumbers?: boolean; @@ -80,6 +81,8 @@ export type HTTPOptions = { apiKey: string; }; +// Allow any because users are free to set anything as CustomData +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type CustomData = any; export type RequestParams = ({ host: string } | { hostname: string }) &