Skip to content

Commit 2118444

Browse files
committed
chore: update eslint & ts configs
1 parent 09a9a32 commit 2118444

18 files changed

+46
-96
lines changed

.eslintignore

-3
This file was deleted.

.eslintrc

-6
This file was deleted.

eslint.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { typescriptConfig } from "@openally/config.eslint";
2+
3+
export default typescriptConfig();

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"build": "tsc",
9+
"lint": "eslint src test",
910
"prepublishOnly": "npm run build",
1011
"test": "jest"
1112
},
@@ -30,7 +31,8 @@
3031
},
3132
"homepage": "https://github.com/MyUnisoft/httpie#readme",
3233
"devDependencies": {
33-
"@nodesecure/eslint-config": "^1.9.0",
34+
"@openally/config.eslint": "^1.1.0",
35+
"@openally/config.typescript": "^1.0.3",
3436
"@types/content-type": "^1.1.8",
3537
"@types/jest": "^29.5.11",
3638
"@types/lru-cache": "^7.10.10",

src/class/HttpieCommonError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IncomingHttpHeaders } from "undici/types/header";
44
type CommonResponseData = {
55
statusCode: number;
66
headers: IncomingHttpHeaders;
7-
}
7+
};
88

99
export interface HttpieErrorOptions {
1010
response: CommonResponseData;

src/class/HttpieOnHttpError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { RequestResponse } from "../request";
77
* We attach these to the error so that they can be retrieved by the developer in a Catch block.
88
*/
99
export class HttpieOnHttpError<T extends RequestResponse<any>> extends HttpieError {
10-
name = "HttpieOnHttpError";
10+
override name = "HttpieOnHttpError";
1111

1212
statusMessage: string;
1313
data: T["data"];

src/class/Operation.class.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface OperationResult<T> {
2121
attempt: number;
2222
executionTimestamp: number;
2323
elapsedTimeoutTime: number;
24-
}
24+
};
2525
}
2626

2727
export default class Operation<T> {

src/class/undiciResponseHandler.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-dupe-class-members */
21

32
// Import Node.js Dependencies
43
import { promisify } from "node:util";
@@ -48,7 +47,7 @@ export class HttpieResponseHandler {
4847
try {
4948
return Buffer.from(await this.response.body.arrayBuffer());
5049
}
51-
catch (error) {
50+
catch (error: any) {
5251
throw new HttpieFetchBodyError({
5352
message: "ResponseFetchError",
5453
error,
@@ -70,7 +69,7 @@ export class HttpieResponseHandler {
7069
encodingHeader.reverse() :
7170
encodingHeader.split(",").reverse();
7271

73-
let decompressedBuffer = Buffer.from(buffer);
72+
let decompressedBuffer: Buffer = Buffer.from(buffer);
7473
for (const rawEncoding of encodings) {
7574
const encoding = rawEncoding.trim() as TypeOfDecompression;
7675
const strategy = kDecompress[encoding];
@@ -90,7 +89,7 @@ export class HttpieResponseHandler {
9089
try {
9190
decompressedBuffer = await strategy(decompressedBuffer);
9291
}
93-
catch (error) {
92+
catch (error: any) {
9493
throw new HttpieDecompressionError({
9594
message: "UnexpectedDecompressionError",
9695
buffer,
@@ -129,7 +128,7 @@ export class HttpieResponseHandler {
129128
return bodyAsString;
130129
}
131130
}
132-
catch (error) {
131+
catch (error: any) {
133132
// Note: Even in case of an error we want to be able to recover the body that caused the JSON parsing error.
134133
throw new HttpieParserError({
135134
message: "ResponseParsingError",

src/common/errors.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable max-len */
2-
31
interface GetErrorOptions<T> {
42
error?: Error;
53
message: keyof T;
@@ -26,6 +24,7 @@ const kFetchBodyErrors = {
2624
};
2725

2826
const kDecompressionErrors = {
27+
// eslint-disable-next-line @stylistic/max-len
2928
UnexpectedDecompressionError: taggedString`An unexpected error occurred when trying to decompress the response body (reason: '${0}').`,
3029
DecompressionNotSupported: taggedString`Unsupported encoding '${0}'.`
3130
};

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export * from "./request";
2222
export * from "./stream";
2323
export * from "./retry";
2424
export * as policies from "./policies";
25-
export { agents, computeURI, CustomHttpAgent } from "./agents";
25+
export { agents, computeURI, type CustomHttpAgent } from "./agents";
2626
export { DEFAULT_HEADER, isHTTPError, isHttpieError } from "./utils";
2727
export { HttpieOnHttpError } from "./class/HttpieOnHttpError";
2828
export * from "./class/undiciResponseHandler";
@@ -34,14 +34,14 @@ export {
3434
setGlobalDispatcher,
3535
getGlobalDispatcher,
3636
Headers,
37-
HeadersInit,
37+
type HeadersInit,
3838
FormData,
3939
File,
40-
BodyInit,
40+
type BodyInit,
4141
BodyMixin,
4242
MockAgent,
4343
mockErrors,
4444
MockPool,
45-
Interceptable,
45+
type Interceptable,
4646
Client
4747
};

src/request.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { HttpieOnHttpError } from "./class/HttpieOnHttpError";
1515
import { HttpieDecompressionError, HttpieFetchBodyError, HttpieParserError } from "./class/HttpieHandlerError";
1616

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

21-
export type RequestError<T> =
21+
export type RequestError<T> =
2222
HttpieOnHttpError<RequestResponse<T>> |
2323
HttpieDecompressionError |
2424
HttpieFetchBodyError |

src/utils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-redeclare */
21

32
// Import Node.js Dependencies
43
import { IncomingHttpHeaders } from "node:http";

test/request.spec.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ afterAll(async() => {
2020

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

2525
expect("uptime" in data).toStrictEqual(true);
2626
expect(typeof data.uptime).toStrictEqual("number");
2727
});
2828

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

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

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

5353
return callback();
5454
};
55-
const { data } = await get<{ uptime: number }>("/local/", { limit });
55+
const { data } = await get<{ uptime: number; }>("/local/", { limit });
5656

5757
expect("uptime" in data).toStrictEqual(true);
5858
expect(typeof data.uptime).toStrictEqual("number");
@@ -122,13 +122,12 @@ describe("http.post", () => {
122122
userId: 1
123123
};
124124

125-
const { data } = await post<typeof body & { userId: number }>("https://jsonplaceholder.typicode.com/posts", { body });
125+
const { data } = await post<typeof body & { userId: number; }>("https://jsonplaceholder.typicode.com/posts", { body });
126126
expect(typeof data.userId).toStrictEqual("number");
127127
expect(data).toMatchObject(body);
128128
});
129129
});
130130

131-
132131
describe("http.put", () => {
133132
it("should PUT data on jsonplaceholder API", async() => {
134133
const body = {
@@ -138,7 +137,7 @@ describe("http.put", () => {
138137
userId: 1
139138
};
140139

141-
const { data } = await put<typeof body & { userId: number }>("https://jsonplaceholder.typicode.com/posts/1", { body });
140+
const { data } = await put<typeof body & { userId: number; }>("https://jsonplaceholder.typicode.com/posts/1", { body });
142141
expect(data).toEqual(body);
143142
});
144143
});
@@ -151,7 +150,7 @@ describe("http.patch", () => {
151150
userId: 1
152151
};
153152

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

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

174173
expect(result.ok).toStrictEqual(true);
175174
const { data } = result.unwrap();

0 commit comments

Comments
 (0)