Skip to content

Commit 009332b

Browse files
authored
Refactor/biome code style (#628)
* chore(lint): restore useArrowFunction fixes for bound functions and ignore rule * chore(lint): remove linter rules from config * chore(lint): fix noVar rule and remove from config - Fixed linting issues related to the rule - Restored the rule to default settings * chore(lint): fix noImplicitAnyLet rule and remove from config - Fixed linting issues related to the rule - Restored the rule to default settings * chore(lint): fix noGlobalIsNan rule and remove from config - Fixed linting issues related to the rule - Restored the rule to default settings * chore(lint): fix noUselessElse rule and remove from config * chore(lint): fix useNodejsImportProtocol rule and remove from config * chore(lint): fix useTemplate rule and remove from config * chore(lint): fix useDefaultParameterLast rule and remove from config * chore(lint): fix useSingleVarDeclarator rule and remove from config * chore(lint): fix noSwitchDeclarations rule and remove from config * chore(lint): fix useLiteralKeys rule and remove from config * chore(lint): fix noUselessSwitchCase rule and remove from config * chore(lint): fix noUselessConstructor rule and remove from config * chore(lint): fix noUselessTernary rule and remove from config * chore(lint): fix noExtraBooleanCast rule and remove from config * chore(lint): fix useOptionalChain rule and remove from config * chore(lint): fix noUnusedTemplateLiteral rule and remove from config * chore(lint): fix noAccumulatingSpread rule and remove from config * chore(lint): ignore linter warnings * chore(lint): update linter rules config * chore(lint): remove <explanation> placeholder in biome-ignore comments * Revert "chore(lint): restore useArrowFunction fixes for bound functions and ignore rule" This reverts commit b2a8203. Resolved here: #627 (comment) * fixup! chore(lint): ignore linter warnings
1 parent 5f0cbc8 commit 009332b

File tree

74 files changed

+376
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+376
-413
lines changed

.changeset/aggregate.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ console.log(`::set-output name=notes::${notes.join("%0A")}`);
4747
console.log(`::set-output name=version::v${version}`);
4848

4949
execSync(`git tag v${version}`);
50-
execSync(`git push origin --tags`);
50+
execSync("git push origin --tags");

biome.jsonc

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,21 @@
1414
"all": false
1515
},
1616
"suspicious": {
17-
"noExplicitAny": "info",
18-
"noGlobalIsNan": "warn",
19-
"noImplicitAnyLet": "warn",
20-
"noAssignInExpressions": "warn",
21-
"noConfusingVoidType": "warn",
22-
"useNamespaceKeyword": "warn" // safe fix
17+
"noExplicitAny": "off",
18+
"noAssignInExpressions": "off",
19+
"noConfusingVoidType": "off"
2320
},
2421
"style": {
25-
"noUnusedTemplateLiteral": "warn",
26-
"noInferrableTypes": "warn", // safe fix
27-
"noUselessElse": "warn",
28-
"useNodejsImportProtocol": "warn",
29-
"useTemplate": "warn",
30-
"useNumberNamespace": "warn", // safe fix
31-
"noNonNullAssertion": "warn",
32-
"useImportType": "warn",
33-
"noParameterAssign": "warn",
34-
"useDefaultParameterLast": "warn",
35-
"noCommaOperator": "warn",
36-
"useConst": "warn",
37-
"useSingleVarDeclarator": "warn",
38-
"noVar": "warn",
39-
"useShorthandFunctionType": "warn" // safe fix
40-
},
41-
"correctness": {
42-
"noSwitchDeclarations": "warn",
43-
"noUnnecessaryContinue": "warn",
44-
"noInnerDeclarations": "warn"
22+
"noNonNullAssertion": "off",
23+
"noParameterAssign": "info",
24+
"noCommaOperator": "info"
4525
},
4626
"complexity": {
47-
"useLiteralKeys": "warn",
4827
"noForEach": "off",
49-
"noUselessSwitchCase": "warn",
50-
"noUselessConstructor": "warn",
51-
"noBannedTypes": "warn",
52-
"noUselessTernary": "warn",
53-
"useArrowFunction": "warn", // safe fix
54-
"noExtraBooleanCast": "warn",
55-
"useOptionalChain": "warn"
28+
"noBannedTypes": "off"
5629
},
5730
"performance": {
58-
"noDelete": "warn",
59-
"noAccumulatingSpread": "warn"
31+
"noDelete": "off"
6032
}
6133
}
6234
},
@@ -66,7 +38,7 @@
6638
"linter": {
6739
"rules": {
6840
"suspicious": {
69-
"noRedeclare": "warn"
41+
"noRedeclare": "off"
7042
}
7143
}
7244
}
@@ -76,15 +48,15 @@
7648
"linter": {
7749
"rules": {
7850
"style": {
79-
"useSelfClosingElements": "warn"
51+
"useSelfClosingElements": "off"
8052
},
8153
"correctness": {
82-
"useJsxKeyInIterable": "warn",
83-
"useExhaustiveDependencies": "warn"
54+
"useJsxKeyInIterable": "off",
55+
"useExhaustiveDependencies": "off"
8456
},
8557
"suspicious": {
86-
"noArrayIndexKey": "warn",
87-
"noRedeclare": "warn"
58+
"noArrayIndexKey": "off",
59+
"noRedeclare": "off"
8860
}
8961
}
9062
}

examples/app-pages-router/middleware.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,27 @@ export function middleware(request: NextRequest) {
1111
return NextResponse.redirect(u, {
1212
headers: { "set-cookie": "test=success" },
1313
});
14-
} else if (path === "/rewrite") {
14+
}
15+
if (path === "/rewrite") {
1516
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
1617
u.searchParams.set("a", "b");
1718
return NextResponse.rewrite(u);
18-
} else if (path === "/api/middleware") {
19+
}
20+
if (path === "/api/middleware") {
1921
return new NextResponse(JSON.stringify({ hello: "middleware" }), {
2022
status: 200,
2123
headers: {
2224
"content-type": "application/json",
2325
},
2426
});
25-
} else {
26-
const rHeaders = new Headers(request.headers);
27-
const r = NextResponse.next({
28-
request: {
29-
headers: rHeaders,
30-
},
31-
});
32-
return r;
3327
}
28+
const rHeaders = new Headers(request.headers);
29+
const r = NextResponse.next({
30+
request: {
31+
headers: rHeaders,
32+
},
33+
});
34+
return r;
3435
}
3536

3637
export const config = {

examples/app-router/app/api/isr/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from "path";
2-
import fs from "fs/promises";
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
33
import type { NextRequest } from "next/server";
44
import { NextResponse } from "next/server";
55

examples/app-router/app/api/sse/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
3131
await wait(2000);
3232
await writer.write(
3333
`data: ${JSON.stringify({
34-
message: "hello:" + i,
34+
message: `hello:${i}`,
3535
time: new Date().toISOString(),
3636
})}\n\n`,
3737
);

examples/app-router/app/search-query/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default async function SearchQuery(props: {
55
}) {
66
const propsSearchParams = await props.searchParams;
77
const mwSearchParams = (await headers()).get("search-params");
8-
const multiValueParams = propsSearchParams["multi"];
8+
const multiValueParams = propsSearchParams.multi;
99
const multiValueArray = Array.isArray(multiValueParams)
1010
? multiValueParams
1111
: [multiValueParams];

examples/app-router/middleware.ts

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,67 @@ export function middleware(request: NextRequest) {
1111
return NextResponse.redirect(u, {
1212
headers: { "set-cookie": "test=success" },
1313
});
14-
} else if (path === "/rewrite") {
14+
}
15+
if (path === "/rewrite") {
1516
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
1617
return NextResponse.rewrite(u);
17-
} else if (path === "/api/middleware") {
18+
}
19+
if (path === "/api/middleware") {
1820
return new NextResponse(JSON.stringify({ hello: "middleware" }), {
1921
status: 200,
2022
headers: {
2123
"content-type": "application/json",
2224
},
2325
});
24-
} else {
25-
const requestHeaders = new Headers();
26-
// Setting the Request Headers, this should be available in RSC
27-
requestHeaders.set("request-header", "request-header");
28-
requestHeaders.set(
29-
"search-params",
30-
`mw/${request.nextUrl.searchParams.get("searchParams") || ""}`,
31-
);
32-
const responseHeaders = new Headers();
33-
// Response headers should show up in the client's response headers
34-
responseHeaders.set("response-header", "response-header");
26+
}
27+
const requestHeaders = new Headers();
28+
// Setting the Request Headers, this should be available in RSC
29+
requestHeaders.set("request-header", "request-header");
30+
requestHeaders.set(
31+
"search-params",
32+
`mw/${request.nextUrl.searchParams.get("searchParams") || ""}`,
33+
);
34+
const responseHeaders = new Headers();
35+
// Response headers should show up in the client's response headers
36+
responseHeaders.set("response-header", "response-header");
3537

36-
// Set the cache control header with custom swr
37-
// For: isr.test.ts
38-
if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
39-
responseHeaders.set(
40-
"cache-control",
41-
"max-age=10, stale-while-revalidate=999",
42-
);
43-
}
38+
// Set the cache control header with custom swr
39+
// For: isr.test.ts
40+
if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
41+
responseHeaders.set(
42+
"cache-control",
43+
"max-age=10, stale-while-revalidate=999",
44+
);
45+
}
4446

45-
// It is so that cloudfront doesn't cache the response
46-
if (
47-
path.startsWith("/revalidate-tag") ||
48-
path.startsWith("/revalidate-path")
49-
) {
50-
responseHeaders.set(
51-
"cache-control",
52-
"private, no-cache, no-store, max-age=0, must-revalidate",
53-
);
54-
}
47+
// It is so that cloudfront doesn't cache the response
48+
if (
49+
path.startsWith("/revalidate-tag") ||
50+
path.startsWith("/revalidate-path")
51+
) {
52+
responseHeaders.set(
53+
"cache-control",
54+
"private, no-cache, no-store, max-age=0, must-revalidate",
55+
);
56+
}
5557

56-
const r = NextResponse.next({
57-
headers: responseHeaders,
58-
request: {
59-
headers: requestHeaders,
60-
},
61-
});
58+
const r = NextResponse.next({
59+
headers: responseHeaders,
60+
request: {
61+
headers: requestHeaders,
62+
},
63+
});
6264

63-
// Set cookies in middleware
64-
// For: middleware.cookies.test.ts
65-
r.cookies.set("from", "middleware", {
66-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
67-
});
68-
r.cookies.set("with", "love", {
69-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
70-
});
65+
// Set cookies in middleware
66+
// For: middleware.cookies.test.ts
67+
r.cookies.set("from", "middleware", {
68+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
69+
});
70+
r.cookies.set("with", "love", {
71+
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
72+
});
7173

72-
return r;
73-
}
74+
return r;
7475
}
7576

7677
export const config = {

examples/sst/stacks/OpenNextReferenceImplementation.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execSync } from "node:child_process";
22

3-
import { readFileSync } from "fs";
4-
import path from "path";
3+
import { readFileSync } from "node:fs";
4+
import path from "node:path";
55
import type { BehaviorOptions, ICachePolicy } from "aws-cdk-lib/aws-cloudfront";
66
import {
77
AllowedMethods,
@@ -391,26 +391,24 @@ export class OpenNextCdkReferenceImplementation extends Construct {
391391
.filter((b) => b.pattern !== "*")
392392
.reduce(
393393
(acc, behavior) => {
394-
return {
395-
...acc,
396-
[behavior.pattern]: {
397-
origin: behavior.origin
398-
? origins[behavior.origin]
399-
: origins.default,
400-
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
401-
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
402-
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
403-
cachePolicy:
404-
behavior.origin === "s3"
405-
? this.staticCachePolicy
406-
: this.serverCachePolicy,
407-
originRequestPolicy:
408-
behavior.origin === "s3"
409-
? undefined
410-
: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
411-
functionAssociations: fnAssociations,
412-
},
394+
acc[behavior.pattern] = {
395+
origin: behavior.origin
396+
? origins[behavior.origin]
397+
: origins.default,
398+
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
399+
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
400+
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
401+
cachePolicy:
402+
behavior.origin === "s3"
403+
? this.staticCachePolicy
404+
: this.serverCachePolicy,
405+
originRequestPolicy:
406+
behavior.origin === "s3"
407+
? undefined
408+
: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
409+
functionAssociations: fnAssociations,
413410
};
411+
return acc;
414412
},
415413
{} as Record<string, BehaviorOptions>,
416414
),

packages/open-next/src/adapters/cache.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ function isFetchCache(
121121
}
122122
// We need to use globalThis client here as this class can be defined at load time in next 12 but client is not available at load time
123123
export default class S3Cache {
124-
constructor(_ctx: CacheHandlerContext) {}
125-
126124
public async get(
127125
key: string,
128126
// fetchCache is for next 13.5 and above, kindHint is for next 14 and above and boolean is for earlier versions
@@ -233,7 +231,8 @@ export default class S3Cache {
233231
headers: meta?.headers,
234232
},
235233
} as CacheHandlerValue;
236-
} else if (cacheData?.type === "page" || cacheData?.type === "app") {
234+
}
235+
if (cacheData?.type === "page" || cacheData?.type === "app") {
237236
if (globalThis.isNextAfter15 && cacheData?.type === "app") {
238237
return {
239238
lastModified: _lastModified,
@@ -258,18 +257,18 @@ export default class S3Cache {
258257
headers: meta?.headers,
259258
},
260259
} as CacheHandlerValue;
261-
} else if (cacheData?.type === "redirect") {
260+
}
261+
if (cacheData?.type === "redirect") {
262262
return {
263263
lastModified: _lastModified,
264264
value: {
265265
kind: "REDIRECT",
266266
props: cacheData.props,
267267
},
268268
} as CacheHandlerValue;
269-
} else {
270-
warn("Unknown cache type", cacheData);
271-
return null;
272269
}
270+
warn("Unknown cache type", cacheData);
271+
return null;
273272
} catch (e) {
274273
// We can usually ignore errors here as they are usually due to cache not being found
275274
debug("Failed to get body cache", e);
@@ -296,7 +295,7 @@ export default class S3Cache {
296295
} else {
297296
switch (data.kind) {
298297
case "ROUTE":
299-
case "APP_ROUTE":
298+
case "APP_ROUTE": {
300299
const { body, status, headers } = data;
301300
await globalThis.incrementalCache.set(
302301
key,
@@ -315,6 +314,7 @@ export default class S3Cache {
315314
false,
316315
);
317316
break;
317+
}
318318
case "PAGE":
319319
case "PAGES": {
320320
const { html, pageData, status, headers } = data;

packages/open-next/src/adapters/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from "path";
1+
import path from "node:path";
22

33
import { debug } from "../logger";
44
import {

0 commit comments

Comments
 (0)