Skip to content

Commit

Permalink
chore: update eslint & ts configs (#265)
Browse files Browse the repository at this point in the history
* chore: update eslint & ts configs

* fix(UT): update outdated snapshots
  • Loading branch information
fraxken authored Jan 3, 2025
1 parent 09a9a32 commit 39c8458
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 153 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { typescriptConfig } from "@openally/config.eslint";

export default typescriptConfig();
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint src test",
"prepublishOnly": "npm run build",
"test": "jest"
},
Expand All @@ -30,7 +31,8 @@
},
"homepage": "https://github.com/MyUnisoft/httpie#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.9.0",
"@openally/config.eslint": "^1.1.0",
"@openally/config.typescript": "^1.0.3",
"@types/content-type": "^1.1.8",
"@types/jest": "^29.5.11",
"@types/lru-cache": "^7.10.10",
Expand Down
2 changes: 1 addition & 1 deletion src/class/HttpieCommonError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IncomingHttpHeaders } from "undici/types/header";
type CommonResponseData = {
statusCode: number;
headers: IncomingHttpHeaders;
}
};

export interface HttpieErrorOptions {
response: CommonResponseData;
Expand Down
2 changes: 1 addition & 1 deletion src/class/HttpieOnHttpError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RequestResponse } from "../request";
* We attach these to the error so that they can be retrieved by the developer in a Catch block.
*/
export class HttpieOnHttpError<T extends RequestResponse<any>> extends HttpieError {
name = "HttpieOnHttpError";
override name = "HttpieOnHttpError";

statusMessage: string;
data: T["data"];
Expand Down
2 changes: 1 addition & 1 deletion src/class/Operation.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface OperationResult<T> {
attempt: number;
executionTimestamp: number;
elapsedTimeoutTime: number;
}
};
}

export default class Operation<T> {
Expand Down
9 changes: 4 additions & 5 deletions src/class/undiciResponseHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-dupe-class-members */

// Import Node.js Dependencies
import { promisify } from "node:util";
Expand Down Expand Up @@ -48,7 +47,7 @@ export class HttpieResponseHandler {
try {
return Buffer.from(await this.response.body.arrayBuffer());
}
catch (error) {
catch (error: any) {
throw new HttpieFetchBodyError({
message: "ResponseFetchError",
error,
Expand All @@ -70,7 +69,7 @@ export class HttpieResponseHandler {
encodingHeader.reverse() :
encodingHeader.split(",").reverse();

let decompressedBuffer = Buffer.from(buffer);
let decompressedBuffer: Buffer = Buffer.from(buffer);
for (const rawEncoding of encodings) {
const encoding = rawEncoding.trim() as TypeOfDecompression;
const strategy = kDecompress[encoding];
Expand All @@ -90,7 +89,7 @@ export class HttpieResponseHandler {
try {
decompressedBuffer = await strategy(decompressedBuffer);
}
catch (error) {
catch (error: any) {
throw new HttpieDecompressionError({
message: "UnexpectedDecompressionError",
buffer,
Expand Down Expand Up @@ -129,7 +128,7 @@ export class HttpieResponseHandler {
return bodyAsString;
}
}
catch (error) {
catch (error: any) {
// Note: Even in case of an error we want to be able to recover the body that caused the JSON parsing error.
throw new HttpieParserError({
message: "ResponseParsingError",
Expand Down
3 changes: 1 addition & 2 deletions src/common/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable max-len */

interface GetErrorOptions<T> {
error?: Error;
message: keyof T;
Expand All @@ -26,6 +24,7 @@ const kFetchBodyErrors = {
};

const kDecompressionErrors = {
// eslint-disable-next-line @stylistic/max-len
UnexpectedDecompressionError: taggedString`An unexpected error occurred when trying to decompress the response body (reason: '${0}').`,
DecompressionNotSupported: taggedString`Unsupported encoding '${0}'.`
};
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export * from "./request";
export * from "./stream";
export * from "./retry";
export * as policies from "./policies";
export { agents, computeURI, CustomHttpAgent } from "./agents";
export { agents, computeURI, type CustomHttpAgent } from "./agents";
export { DEFAULT_HEADER, isHTTPError, isHttpieError } from "./utils";
export { HttpieOnHttpError } from "./class/HttpieOnHttpError";
export * from "./class/undiciResponseHandler";
Expand All @@ -34,14 +34,14 @@ export {
setGlobalDispatcher,
getGlobalDispatcher,
Headers,
HeadersInit,
type HeadersInit,
FormData,
File,
BodyInit,
type BodyInit,
BodyMixin,
MockAgent,
mockErrors,
MockPool,
Interceptable,
type Interceptable,
Client
};
4 changes: 2 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { HttpieOnHttpError } from "./class/HttpieOnHttpError";
import { HttpieDecompressionError, HttpieFetchBodyError, HttpieParserError } from "./class/HttpieHandlerError";

export type WebDavMethod = "MKCOL" | "COPY" | "MOVE" | "LOCK" | "UNLOCK" | "PROPFIND" | "PROPPATCH";
export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH" ;
export type HttpMethod = "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH";
export type InlineCallbackAction = <T>(fn: () => Promise<T>) => Promise<T>;

export type RequestError<T> =
export type RequestError<T> =
HttpieOnHttpError<RequestResponse<T>> |
HttpieDecompressionError |
HttpieFetchBodyError |
Expand Down
2 changes: 1 addition & 1 deletion src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function retry<T>(
const data = await callback();
op.success(data);
}
catch (error) {
catch (error: any) {
if (policy(error)) {
throw error;
}
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-redeclare */

// Import Node.js Dependencies
import { IncomingHttpHeaders } from "node:http";
Expand Down
2 changes: 1 addition & 1 deletion test/HttpieOnHttpError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("HttpieOnHttpError", () => {
try {
await request(targetUrl.method as any, path);
}
catch (error) {
catch (error: any) {
expect(error.name).toStrictEqual("HttpieOnHttpError");
expect(error).toMatchObject(expectedResponseData);
}
Expand Down
4 changes: 0 additions & 4 deletions test/__snapshots__/request.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ exports[`http.get should throw a 404 Not Found error because the path is not kno
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.58 (Ubuntu) Server at ws.dev.myunisoft.tech Port 80</address>
</body></html>
"
`;
Expand All @@ -20,8 +18,6 @@ exports[`http.safeGet should throw a 404 Not Found error because the path is not
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.58 (Ubuntu) Server at ws.dev.myunisoft.tech Port 80</address>
</body></html>
"
`;
21 changes: 10 additions & 11 deletions test/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ afterAll(async() => {

describe("http.get", () => {
it("should GET uptime from local fastify server", async() => {
const { data } = await get<{ uptime: number }>("/local/");
const { data } = await get<{ uptime: number; }>("/local/");

expect("uptime" in data).toStrictEqual(true);
expect(typeof data.uptime).toStrictEqual("number");
});

it("should GET query parameters provided to fastify", async() => {
const { data } = await get<{ name: string }>("/local/qs", {
const { data } = await get<{ name: string; }>("/local/qs", {
querystring: new URLSearchParams({
name: "foobar"
})
Expand All @@ -38,7 +38,7 @@ describe("http.get", () => {
});

it("should GET uptime by following an HTTP redirection from local fastify server", async() => {
const { data } = await get<{ uptime: number }>("/local/redirect", { maxRedirections: 1 });
const { data } = await get<{ uptime: number; }>("/local/redirect", { maxRedirections: 1 });

expect("uptime" in data).toStrictEqual(true);
expect(typeof data.uptime).toStrictEqual("number");
Expand All @@ -52,7 +52,7 @@ describe("http.get", () => {

return callback();
};
const { data } = await get<{ uptime: number }>("/local/", { limit });
const { data } = await get<{ uptime: number; }>("/local/", { limit });

expect("uptime" in data).toStrictEqual(true);
expect(typeof data.uptime).toStrictEqual("number");
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("http.get", () => {
try {
await get<string>("/windev/hlkezcjcke");
}
catch (error) {
catch (error: any) {
expect(error.name).toStrictEqual("HttpieOnHttpError");
expect(error.statusCode).toStrictEqual(404);
expect(error.statusMessage).toStrictEqual("Not Found");
Expand All @@ -102,7 +102,7 @@ describe("http.get", () => {
try {
await get<string>("/local/jsonError");
}
catch (error) {
catch (error: any) {
expect(error.name).toStrictEqual("ResponseParsingError");
expect(error.reason.name).toStrictEqual("SyntaxError");
expect(error.text).toStrictEqual(expectedPayload);
Expand All @@ -122,13 +122,12 @@ describe("http.post", () => {
userId: 1
};

const { data } = await post<typeof body & { userId: number }>("https://jsonplaceholder.typicode.com/posts", { body });
const { data } = await post<typeof body & { userId: number; }>("https://jsonplaceholder.typicode.com/posts", { body });
expect(typeof data.userId).toStrictEqual("number");
expect(data).toMatchObject(body);
});
});


describe("http.put", () => {
it("should PUT data on jsonplaceholder API", async() => {
const body = {
Expand All @@ -138,7 +137,7 @@ describe("http.put", () => {
userId: 1
};

const { data } = await put<typeof body & { userId: number }>("https://jsonplaceholder.typicode.com/posts/1", { body });
const { data } = await put<typeof body & { userId: number; }>("https://jsonplaceholder.typicode.com/posts/1", { body });
expect(data).toEqual(body);
});
});
Expand All @@ -151,7 +150,7 @@ describe("http.patch", () => {
userId: 1
};

const { data } = await patch<typeof body & { userId: number }>("https://jsonplaceholder.typicode.com/posts/1", {
const { data } = await patch<typeof body & { userId: number; }>("https://jsonplaceholder.typicode.com/posts/1", {
body: { title: "foo" }
});
expect(data).toMatchObject(body);
Expand All @@ -169,7 +168,7 @@ describe("http.del", () => {

describe("http.safeGet", () => {
it("should GET uptime from local fastify server", async() => {
const result = await safeGet<{ uptime: number }, any>("/local/");
const result = await safeGet<{ uptime: number; }, any>("/local/");

expect(result.ok).toStrictEqual(true);
const { data } = result.unwrap();
Expand Down
Loading

0 comments on commit 39c8458

Please sign in to comment.