Skip to content

Commit

Permalink
chore: re-enable linting rule to disallow the use of "any"
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Apr 29, 2024
1 parent 27d9420 commit 92be585
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 63 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"rules": {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": ["warn"],
"@typescript-eslint/ban-ts-comment": ["error", { "ts-ignore": "allow-with-description" } ],
"prettier/prettier": ["error", { "endOfLine": "auto" }]
}
Expand Down
9 changes: 5 additions & 4 deletions packages/node/dist/deno/jsonparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export default class JSONParserTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.jsonParser.write(chunk);
done();
Expand All @@ -51,12 +52,12 @@ export default class JSONParserTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.jsonParser.isEnded) this.jsonParser.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
9 changes: 5 additions & 4 deletions packages/node/dist/deno/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export default class TokenizerTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.tokenizer.write(chunk);
done();
Expand All @@ -53,12 +54,12 @@ export default class TokenizerTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.tokenizer.isEnded) this.tokenizer.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
9 changes: 5 additions & 4 deletions packages/node/dist/deno/tokenparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export default class TokenParserTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.tokenParser.write(chunk);
done();
Expand All @@ -51,12 +52,12 @@ export default class TokenParserTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.tokenParser.isEnded) this.tokenParser.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
9 changes: 5 additions & 4 deletions packages/node/src/jsonparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export default class JSONParserTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.jsonParser.write(chunk);
done();
Expand All @@ -51,12 +52,12 @@ export default class JSONParserTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.jsonParser.isEnded) this.jsonParser.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
9 changes: 5 additions & 4 deletions packages/node/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export default class TokenizerTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.tokenizer.write(chunk);
done();
Expand All @@ -53,12 +54,12 @@ export default class TokenizerTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.tokenizer.isEnded) this.tokenizer.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
9 changes: 5 additions & 4 deletions packages/node/src/tokenparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ export default class TokenParserTransform extends Transform {
* @param {Function} done Called when the proceesing of the supplied chunk is done
*/
override _transform(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
chunk: any,
encoding: BufferEncoding,
done: TransformCallback,
) {
): void {
try {
this.tokenParser.write(chunk);
done();
Expand All @@ -51,12 +52,12 @@ export default class TokenParserTransform extends Transform {
}
}

override _final(done: any) {
override _final(callback: (error?: Error | null) => void): void {
try {
if (!this.tokenParser.isEnded) this.tokenParser.end();
done();
callback();
} catch (err: unknown) {
done(err);
callback(err as Error);
}
}
}
5 changes: 3 additions & 2 deletions packages/node/test/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ describe("selectors", () => {
try {
new JSONParser({ paths });
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(expectedError);
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(expectedError);
}
});
});
Expand Down
17 changes: 11 additions & 6 deletions packages/node/test/separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ describe("separator", () => {
test(`separator: fail on invalid value`, async () => {
try {
await runJSONParserTest(new JSONParser({ separator: "abc" }), ["abe"]);
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected "e" at position "2" in state SEPARATOR',
);
}
Expand All @@ -73,8 +74,11 @@ describe("separator", () => {
{ token: TokenType.TRUE, value: true },
]);
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual("Unexpected TRUE (true) in state SEPARATOR");
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
"Unexpected TRUE (true) in state SEPARATOR",
);
}
});

Expand All @@ -85,8 +89,9 @@ describe("separator", () => {
{ token: TokenType.SEPARATOR, value: "\r\n" },
]);
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected SEPARATOR ("\\r\\n") in state SEPARATOR',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/utils/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ParsedElementInfo } from "@streamparser/json/utils/types/parsedEle
export type TestData = {
value: string | string[] | Iterable<number>;
paths?: string[];
expected: any[];
expected: unknown[];
};

type ParseableData = string | Iterable<number>;
Expand Down
4 changes: 2 additions & 2 deletions packages/plainjs/dist/deno/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ export default class Tokenizer {
}
}
}
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/plainjs/dist/deno/tokenparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@ export default class TokenParser {
value,
)}) in state ${TokenParserStateToString(this.state)}`,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plainjs/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ export default class Tokenizer {
}
}
}
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/plainjs/src/tokenparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,8 @@ export default class TokenParser {
value,
)}) in state ${TokenParserStateToString(this.state)}`,
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/plainjs/test/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ describe("callback", () => {

p.write('"test"');
expect(onValueCb.mock.calls).toHaveLength(1);
expect((onValueCb.mock.calls[0] as any)[0].value).toBe("test");
expect(
(onValueCb.mock.calls[0] as unknown as [{ value: string }])[0].value,
).toBe("test");
});

test("should handle invalid input using the onError callback if set", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/plainjs/test/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ describe("selectors", () => {
try {
new JSONParser({ paths });
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(expectedError);
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(expectedError);
}
});
});
Expand Down
17 changes: 11 additions & 6 deletions packages/plainjs/test/separator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ describe("separator", () => {
test(`separator: fail on invalid value`, async () => {
try {
await runJSONParserTest(new JSONParser({ separator: "abc" }), ["abe"]);
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected "e" at position "2" in state SEPARATOR',
);
}
Expand All @@ -73,8 +74,11 @@ describe("separator", () => {
{ token: TokenType.TRUE, value: true },
]);
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual("Unexpected TRUE (true) in state SEPARATOR");
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
"Unexpected TRUE (true) in state SEPARATOR",
);
}
});

Expand All @@ -85,8 +89,9 @@ describe("separator", () => {
{ token: TokenType.SEPARATOR, value: "\r\n" },
]);
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected SEPARATOR ("\\r\\n") in state SEPARATOR',
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plainjs/test/utils/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ParsedElementInfo } from "../../src/utils/types/parsedElementInfo.js";
export type TestData = {
value: string | string[] | Iterable<number>;
paths?: string[];
expected: any[];
expected: unknown[];
};

type ParseableData = string | Iterable<number>;
Expand Down
5 changes: 3 additions & 2 deletions packages/whatwg/test/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ describe("selectors", () => {
try {
new JSONParser({ paths });
fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(expectedError);
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(expectedError);
}
});
});
Expand Down
Loading

0 comments on commit 92be585

Please sign in to comment.