Skip to content

Commit

Permalink
refactor: #158 remove no-this-alias ignore eslint rule (#160)
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

* remove no-this-alias from eslint config

* convert to arrow function to preserve this reference

* use arrow functions to remove the need of a this alias

* define httpoptions object instead of using this alias

* update package lock in sample
  • Loading branch information
miquelbeltran authored May 1, 2024
1 parent de0eed9 commit aea993f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 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-this-alias": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-var-requires": "off",
"no-undef": "off",
Expand Down
24 changes: 9 additions & 15 deletions lib/raygun.offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ export class OfflineStorage implements IOfflineStorage {
}

private _sendAndDelete(item: string) {
const storage = this;

fs.readFile(path.join(this.cachePath, item), "utf8", function (
fs.readFile(path.join(this.cachePath, item), "utf8", (
err,
cacheContents
) {
storage.transport.send(cacheContents);
fs.unlink(path.join(storage.cachePath, item), () => {});
) => {
this.transport.send(cacheContents);
fs.unlink(path.join(this.cachePath, item), () => {});
});
}

Expand All @@ -60,18 +58,16 @@ export class OfflineStorage implements IOfflineStorage {
}

save(transportItem: string, callback: (err: Error | null) => void) {
const storage = this;

const filename = path.join(storage.cachePath, Date.now() + ".json");
const filename = path.join(this.cachePath, Date.now() + ".json");

fs.readdir(storage.cachePath, function (err, files) {
fs.readdir(this.cachePath, (err, files) => {
if (err) {
console.log("[Raygun] Error reading cache folder");
console.log(err);
return callback(err);
}

if (files.length > storage.cacheLimit) {
if (files.length > this.cacheLimit) {
console.log("[Raygun] Error cache reached limit");
return callback(null);
}
Expand All @@ -97,9 +93,7 @@ export class OfflineStorage implements IOfflineStorage {
}

send(callback: (error: Error | null, items?: string[]) => void) {
const storage = this;

storage.retrieve(function (err, items) {
this.retrieve((err, items) => {
if (err) {
console.log("[Raygun] Error reading cache folder");
console.log(err);
Expand All @@ -113,7 +107,7 @@ export class OfflineStorage implements IOfflineStorage {
}

for (let i = 0; i < items.length; i++) {
storage._sendAndDelete(items[i]);
this._sendAndDelete(items[i]);
}

callback(err, items);
Expand Down
20 changes: 9 additions & 11 deletions lib/raygun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,8 @@ class Raygun {
return;
}

const client = this;

process.on("uncaughtExceptionMonitor", function (e) {
client.sendSync(e);
process.on("uncaughtExceptionMonitor", (e) => {
this.sendSync(e);
});
}

Expand Down Expand Up @@ -397,19 +395,19 @@ class Raygun {

private offlineTransport(): MessageTransport {
const transport = this.transport();
const client = this;
const httpOptions = {
host: this._host,
port: this._port,
useSSL: this._useSSL || false,
apiKey: this._apiKey || "",
}

return {
send(message: string) {
transport.send({
message,
callback: () => {},
http: {
host: client._host,
port: client._port,
useSSL: !!client._useSSL,
apiKey: client._apiKey || "",
},
http: httpOptions,
});
},
};
Expand Down

0 comments on commit aea993f

Please sign in to comment.