Skip to content

Commit

Permalink
chore: update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 13, 2022
1 parent 7f2b8f7 commit 0812e81
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 27 deletions.
7 changes: 1 addition & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
"eslint-config-unjs"
],
"rules": {
"unicorn/no-null": 0,
"unicorn/prevent-abbreviations": 0,
"no-undef": 0,
"no-use-before-define": 0,
"unicorn/no-await-expression-member": 0,
"unicorn/no-useless-undefined": 0
"unicorn/no-null": 0
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
"changelogen": "^0.4.0",
"connect": "^3.7.0",
"eslint": "^8.29.0",
"eslint-config-unjs": "^0.0.2",
"eslint-config-unjs": "^0.0.3",
"express": "^4.18.2",
"get-port": "^6.1.2",
"jiti": "^1.16.0",
"listhen": "^1.0.1",
"node-fetch-native": "^1.0.1",
"prettier": "^2.8.1",
"supertest": "^6.3.3",
"typescript": "^4.9.4",
"unbuild": "^1.0.2",
Expand Down
16 changes: 12 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export class H3Error extends Error {
return obj;
}

statusCode: number = 500;
fatal: boolean = false;
unhandled: boolean = false;
statusCode = 500;
fatal = false;
unhandled = false;
statusMessage?: string = undefined;
data?: any;
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" |
// eslint-disable-next-line unicorn/text-encoding-identifier-case
export type Encoding = false | "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"

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

export type EventHandlerResponse<T = any> = T | Promise<T>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function proxyRequest (event: H3Event, target: string, opts: ProxyO
}
}
if (opts.fetchOptions?.headers) {
Object.assign(headers, opts.fetchOptions!.headers);
Object.assign(headers, opts.fetchOptions.headers);
}
if (opts.headers) {
Object.assign(headers, opts.headers);
Expand Down
11 changes: 8 additions & 3 deletions src/utils/response.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { OutgoingMessage, ServerResponse } from "node:http";
import type { OutgoingMessage } from "node:http";
import type { Socket } from 'node:net'
import { createError } from "../error";
import type { H3Event } from "../event";
import { MIMES } from "./consts";

const defer = typeof setImmediate !== "undefined" ? setImmediate : (fn: Function) => fn();
const defer = typeof setImmediate !== "undefined" ? setImmediate : (fn: () => any) => fn();

export function send (event: H3Event, data?: any, type?: string): Promise<void> {
if (type) {
Expand Down Expand Up @@ -124,5 +125,9 @@ export function writeEarlyHints (event: H3Event, hints: string | string[] | Reco
if (header === "link") { continue; }
hint += `\r\n${header}: ${value}`;
}
(event.node.res as ServerResponse).socket!.write(`${hint}\r\n\r\n`, "utf8", cb);
if (event.node.res.socket) {
(event.node.res as { socket: Socket }).socket.write(`${hint}\r\n\r\n`, "utf8", cb);
} else {
cb()
}
}
2 changes: 1 addition & 1 deletion test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe("app", () => {
});

it("wait for middleware (req, res, next)", async () => {
app.use("/", fromNodeMiddleware((_req, res, _next) => {
app.use("/", fromNodeMiddleware((_req, res) => {
setTimeout(() => {
res.setHeader("content-type", "application/json");
res.end(JSON.stringify({ works: 1 }));
Expand Down
12 changes: 6 additions & 6 deletions test/body.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ describe("", () => {
});

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

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

it("returns an empty object string if body is empty object", async () => {
let body = "initial";
let body: string | undefined = "initial";
app.use("/", eventHandler(async (request) => {
body = (await readRawBody(request))!;
body = await readRawBody(request);
return "200";
}));
const result = await request.post("/api/test").send({});
Expand Down
4 changes: 2 additions & 2 deletions test/integrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("integrations with other frameworks", () => {
it("can be used as express middleware", async () => {
const expressApp = express();
app.use("/api/hello", fromNodeMiddleware((_req, res, next) => {
;(res as any).prop = "42";
(res as any).prop = "42";
next();
}));
app.use("/api/hello", fromNodeMiddleware((req, res) => ({ url: req.url, prop: (res as any).prop })));
Expand All @@ -53,7 +53,7 @@ describe("integrations with other frameworks", () => {
it("can be used as connect middleware", async () => {
const connectApp = createConnectApp();
app.use("/api/hello", fromNodeMiddleware((_req, res, next) => {
;(res as any).prop = "42";
(res as any).prop = "42";
next();
}));
app.use("/api/hello", fromNodeMiddleware((req, res) => ({ url: req.url, prop: (res as any).prop })));
Expand Down

0 comments on commit 0812e81

Please sign in to comment.