Skip to content

Commit

Permalink
refactor: #158 remove no-explicit-any ignore eslint rule (#159)
Browse files Browse the repository at this point in the history
* removed tslint

* add eslint

* add default config

* setup default config and npm run command

* add command to node.js.yml

* set rules to support current codebase

* remove unused tslint.json

* include sample files in eslint command

* remove rule no-explicit-any

* specify type for timer

* remove any from filterKeys

* explictly declare that error can be Error, String but still accept any from the end users

* specify types in the sync worker

* improve the IndexableError type

* explain why any is allowed in CustomData

* update package lock in sample

* Update lib/raygun.sync.worker.ts

Co-authored-by: Sumitra Manga <[email protected]>

* remove empty line

---------

Co-authored-by: Sumitra Manga <[email protected]>
  • Loading branch information
miquelbeltran and sumitramanga committed May 6, 2024
1 parent b165b99 commit 6ec163e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
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

0 comments on commit 6ec163e

Please sign in to comment.