Skip to content

Commit 0812e81

Browse files
committed
chore: update eslint config
1 parent 7f2b8f7 commit 0812e81

File tree

10 files changed

+37
-27
lines changed

10 files changed

+37
-27
lines changed

.eslintrc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
"eslint-config-unjs"
44
],
55
"rules": {
6-
"unicorn/no-null": 0,
7-
"unicorn/prevent-abbreviations": 0,
8-
"no-undef": 0,
9-
"no-use-before-define": 0,
10-
"unicorn/no-await-expression-member": 0,
11-
"unicorn/no-useless-undefined": 0
6+
"unicorn/no-null": 0
127
}
138
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@
4444
"changelogen": "^0.4.0",
4545
"connect": "^3.7.0",
4646
"eslint": "^8.29.0",
47-
"eslint-config-unjs": "^0.0.2",
47+
"eslint-config-unjs": "^0.0.3",
4848
"express": "^4.18.2",
4949
"get-port": "^6.1.2",
5050
"jiti": "^1.16.0",
5151
"listhen": "^1.0.1",
5252
"node-fetch-native": "^1.0.1",
53+
"prettier": "^2.8.1",
5354
"supertest": "^6.3.3",
5455
"typescript": "^4.9.4",
5556
"unbuild": "^1.0.2",

pnpm-lock.yaml

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/error.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export class H3Error extends Error {
2929
return obj;
3030
}
3131

32-
statusCode: number = 500;
33-
fatal: boolean = false;
34-
unhandled: boolean = false;
32+
statusCode = 500;
33+
fatal = false;
34+
unhandled = false;
3535
statusMessage?: string = undefined;
3636
data?: any;
3737
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" |
66
// eslint-disable-next-line unicorn/text-encoding-identifier-case
77
export type Encoding = false | "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"
88

9+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
910
export interface H3EventContext extends Record<string, any> {}
1011

1112
export type EventHandlerResponse<T = any> = T | Promise<T>

src/utils/proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function proxyRequest (event: H3Event, target: string, opts: ProxyO
3838
}
3939
}
4040
if (opts.fetchOptions?.headers) {
41-
Object.assign(headers, opts.fetchOptions!.headers);
41+
Object.assign(headers, opts.fetchOptions.headers);
4242
}
4343
if (opts.headers) {
4444
Object.assign(headers, opts.headers);

src/utils/response.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type { OutgoingMessage, ServerResponse } from "node:http";
1+
import type { OutgoingMessage } from "node:http";
2+
import type { Socket } from 'node:net'
23
import { createError } from "../error";
34
import type { H3Event } from "../event";
45
import { MIMES } from "./consts";
56

6-
const defer = typeof setImmediate !== "undefined" ? setImmediate : (fn: Function) => fn();
7+
const defer = typeof setImmediate !== "undefined" ? setImmediate : (fn: () => any) => fn();
78

89
export function send (event: H3Event, data?: any, type?: string): Promise<void> {
910
if (type) {
@@ -124,5 +125,9 @@ export function writeEarlyHints (event: H3Event, hints: string | string[] | Reco
124125
if (header === "link") { continue; }
125126
hint += `\r\n${header}: ${value}`;
126127
}
127-
(event.node.res as ServerResponse).socket!.write(`${hint}\r\n\r\n`, "utf8", cb);
128+
if (event.node.res.socket) {
129+
(event.node.res as { socket: Socket }).socket.write(`${hint}\r\n\r\n`, "utf8", cb);
130+
} else {
131+
cb()
132+
}
128133
}

test/app.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ describe("app", () => {
188188
});
189189

190190
it("wait for middleware (req, res, next)", async () => {
191-
app.use("/", fromNodeMiddleware((_req, res, _next) => {
191+
app.use("/", fromNodeMiddleware((_req, res) => {
192192
setTimeout(() => {
193193
res.setHeader("content-type", "application/json");
194194
res.end(JSON.stringify({ works: 1 }));

test/body.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ describe("", () => {
2828
});
2929

3030
it("returns undefined if body is not present", async () => {
31-
let body = "initial";
31+
let body: string | undefined = "initial";
3232
app.use("/", eventHandler(async (request) => {
33-
body = (await readRawBody(request))!;
33+
body = await readRawBody(request);
3434
return "200";
3535
}));
3636
const result = await request.post("/api/test");
@@ -40,9 +40,9 @@ describe("", () => {
4040
});
4141

4242
it("returns an empty string if body is empty", async () => {
43-
let body = "initial";
43+
let body: string | undefined = "initial";
4444
app.use("/", eventHandler(async (request) => {
45-
body = (await readRawBody(request))!;
45+
body = await readRawBody(request);
4646
return "200";
4747
}));
4848
const result = await request.post("/api/test").send("\"\"");
@@ -52,9 +52,9 @@ describe("", () => {
5252
});
5353

5454
it("returns an empty object string if body is empty object", async () => {
55-
let body = "initial";
55+
let body: string | undefined = "initial";
5656
app.use("/", eventHandler(async (request) => {
57-
body = (await readRawBody(request))!;
57+
body = await readRawBody(request);
5858
return "200";
5959
}));
6060
const result = await request.post("/api/test").send({});

test/integrations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("integrations with other frameworks", () => {
2727
it("can be used as express middleware", async () => {
2828
const expressApp = express();
2929
app.use("/api/hello", fromNodeMiddleware((_req, res, next) => {
30-
;(res as any).prop = "42";
30+
(res as any).prop = "42";
3131
next();
3232
}));
3333
app.use("/api/hello", fromNodeMiddleware((req, res) => ({ url: req.url, prop: (res as any).prop })));
@@ -53,7 +53,7 @@ describe("integrations with other frameworks", () => {
5353
it("can be used as connect middleware", async () => {
5454
const connectApp = createConnectApp();
5555
app.use("/api/hello", fromNodeMiddleware((_req, res, next) => {
56-
;(res as any).prop = "42";
56+
(res as any).prop = "42";
5757
next();
5858
}));
5959
app.use("/api/hello", fromNodeMiddleware((req, res) => ({ url: req.url, prop: (res as any).prop })));

0 commit comments

Comments
 (0)