Skip to content
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

refactor: #158 remove no-explicit-any ignore eslint rule #159

Merged
merged 19 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions examples/express-sample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/raygun.batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions lib/raygun.messageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object> to enforce type check and avoid using any
const _obj = { ...obj } as Record<string, object>;
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(
Expand Down Expand Up @@ -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" &&
Expand Down
6 changes: 3 additions & 3 deletions lib/raygun.sync.worker.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
9 changes: 6 additions & 3 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;

export type MessageBuilderOptions = {
reportColumnNumbers?: boolean;
Expand Down Expand Up @@ -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 }) &
Expand Down