Skip to content

Commit c30b0db

Browse files
fix all the remaining eslint warnings (#545)
1 parent 0dd718f commit c30b0db

File tree

10 files changed

+105
-84
lines changed

10 files changed

+105
-84
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
],
1616
"sonarjs/elseif-without-else": "warn",
1717
"sonarjs/no-duplicate-string": "warn",
18-
"sonarjs/cognitive-complexity": "warn",
18+
"sonarjs/cognitive-complexity": ["warn", 35],
1919

2020
// We add some typescript rules - The recommended rules breaks too much stuff
2121
// TODO: We should add more rules, especially around typescript types
@@ -29,8 +29,6 @@ module.exports = {
2929
],
3030

3131
"@typescript-eslint/unbound-method": "error",
32-
33-
"@typescript-eslint/no-non-null-assertion": "warn",
3432
},
3533
overrides: [
3634
{

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

Lines changed: 87 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -284,80 +284,95 @@ export default class S3Cache {
284284
.getStore()
285285
?.pendingPromiseRunner.withResolvers<void>();
286286
try {
287-
if (data?.kind === "ROUTE" || data?.kind === "APP_ROUTE") {
288-
const { body, status, headers } = data;
289-
await globalThis.incrementalCache.set(
290-
key,
291-
{
292-
type: "route",
293-
body: body.toString(
294-
isBinaryContentType(String(headers["content-type"]))
295-
? "base64"
296-
: "utf8",
297-
),
298-
meta: {
299-
status,
300-
headers,
301-
},
302-
},
303-
false,
304-
);
305-
} else if (data?.kind === "PAGE" || data?.kind === "PAGES") {
306-
const { html, pageData, status, headers } = data;
307-
const isAppPath = typeof pageData === "string";
308-
if (isAppPath) {
309-
await globalThis.incrementalCache.set(
310-
key,
311-
{
312-
type: "app",
313-
html,
314-
rsc: pageData,
315-
meta: {
316-
status,
317-
headers,
287+
if (data === null || data === undefined) {
288+
await globalThis.incrementalCache.delete(key);
289+
} else {
290+
switch (data.kind) {
291+
case "ROUTE":
292+
case "APP_ROUTE":
293+
const { body, status, headers } = data;
294+
await globalThis.incrementalCache.set(
295+
key,
296+
{
297+
type: "route",
298+
body: body.toString(
299+
isBinaryContentType(String(headers["content-type"]))
300+
? "base64"
301+
: "utf8",
302+
),
303+
meta: {
304+
status,
305+
headers,
306+
},
318307
},
319-
},
320-
false,
321-
);
322-
} else {
323-
await globalThis.incrementalCache.set(
324-
key,
325-
{
326-
type: "page",
327-
html,
328-
json: pageData,
329-
},
330-
false,
331-
);
308+
false,
309+
);
310+
break;
311+
case "PAGE":
312+
case "PAGES": {
313+
const { html, pageData, status, headers } = data;
314+
const isAppPath = typeof pageData === "string";
315+
if (isAppPath) {
316+
await globalThis.incrementalCache.set(
317+
key,
318+
{
319+
type: "app",
320+
html,
321+
rsc: pageData,
322+
meta: {
323+
status,
324+
headers,
325+
},
326+
},
327+
false,
328+
);
329+
} else {
330+
await globalThis.incrementalCache.set(
331+
key,
332+
{
333+
type: "page",
334+
html,
335+
json: pageData,
336+
},
337+
false,
338+
);
339+
}
340+
break;
341+
}
342+
case "APP_PAGE": {
343+
const { html, rscData, headers, status } = data;
344+
await globalThis.incrementalCache.set(
345+
key,
346+
{
347+
type: "app",
348+
html,
349+
rsc: rscData.toString("utf8"),
350+
meta: {
351+
status,
352+
headers,
353+
},
354+
},
355+
false,
356+
);
357+
break;
358+
}
359+
case "FETCH":
360+
await globalThis.incrementalCache.set<true>(key, data, true);
361+
break;
362+
case "REDIRECT":
363+
await globalThis.incrementalCache.set(
364+
key,
365+
{
366+
type: "redirect",
367+
props: data.props,
368+
},
369+
false,
370+
);
371+
break;
372+
case "IMAGE":
373+
// Not implemented
374+
break;
332375
}
333-
} else if (data?.kind === "APP_PAGE") {
334-
const { html, rscData, headers, status } = data;
335-
await globalThis.incrementalCache.set(
336-
key,
337-
{
338-
type: "app",
339-
html,
340-
rsc: rscData.toString("utf8"),
341-
meta: {
342-
status,
343-
headers,
344-
},
345-
},
346-
false,
347-
);
348-
} else if (data?.kind === "FETCH") {
349-
await globalThis.incrementalCache.set<true>(key, data, true);
350-
} else if (data?.kind === "REDIRECT") {
351-
await globalThis.incrementalCache.set(
352-
key,
353-
{
354-
type: "redirect",
355-
props: data.props,
356-
},
357-
false,
358-
);
359-
} else if (data === null || data === undefined) {
360-
await globalThis.incrementalCache.delete(key);
361376
}
362377
// Write derivedTags to dynamodb
363378
// If we use an in house version of getDerivedTags in build we should use it here instead of next's one

packages/open-next/src/adapters/plugins/without-routing/requestHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable unused-imports/no-unused-vars */
12
import { InternalEvent } from "types/open-next";
23

34
import { MiddlewareOutputEvent } from "../../../core/routingHandler";

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function copyPatchFile(outputDir: string) {
2424
copyFileSync(patchFile, outputPatchFile);
2525
}
2626

27+
// eslint-disable-next-line sonarjs/cognitive-complexity
2728
export async function copyTracedFiles(
2829
buildOutputPath: string,
2930
packagePath: string,

packages/open-next/src/build/generateOutput.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ interface OpenNextOutput {
9292
};
9393
}
9494

95+
const indexHandler = "index.hander";
96+
9597
async function canStream(opts: FunctionOptions) {
9698
if (!opts.override?.wrapper) {
9799
return false;
@@ -161,6 +163,7 @@ function prefixPattern(basePath: string) {
161163
};
162164
}
163165

166+
// eslint-disable-next-line sonarjs/cognitive-complexity
164167
export async function generateOutput(
165168
outputPath: string,
166169
config: OpenNextConfig,
@@ -183,7 +186,7 @@ export async function generateOutput(
183186
if (value.placement === "global") {
184187
edgeFunctions[key] = {
185188
bundle: `.open-next/functions/${key}`,
186-
handler: "index.handler",
189+
handler: indexHandler,
187190
...(await extractOverrideFn(value.override)),
188191
};
189192
}
@@ -228,7 +231,7 @@ export async function generateOutput(
228231
},
229232
imageOptimizer: {
230233
type: "function",
231-
handler: "index.handler",
234+
handler: indexHandler,
232235
bundle: ".open-next/image-optimization-function",
233236
streaming: false,
234237
imageLoader: await extractOverrideName(
@@ -247,7 +250,7 @@ export async function generateOutput(
247250
}
248251
: {
249252
type: "function",
250-
handler: "index.handler",
253+
handler: indexHandler,
251254
bundle: ".open-next/server-functions/default",
252255
streaming: defaultOriginCanstream,
253256
...(await extractOverrideFn(config.default.override)),
@@ -274,7 +277,7 @@ export async function generateOutput(
274277
const streaming = await canStream(value);
275278
origins[key] = {
276279
type: "function",
277-
handler: "index.handler",
280+
handler: indexHandler,
278281
bundle: `.open-next/server-functions/${key}`,
279282
streaming,
280283
...(await extractOverrideFn(value.override)),
@@ -348,19 +351,19 @@ export async function generateOutput(
348351
disableIncrementalCache: config.dangerous?.disableIncrementalCache,
349352
disableTagCache: config.dangerous?.disableTagCache,
350353
warmer: {
351-
handler: "index.handler",
354+
handler: indexHandler,
352355
bundle: ".open-next/warmer-function",
353356
},
354357
initializationFunction: isTagCacheDisabled
355358
? undefined
356359
: {
357-
handler: "index.handler",
360+
handler: indexHandler,
358361
bundle: ".open-next/dynamodb-provider",
359362
},
360363
revalidationFunction: config.dangerous?.disableIncrementalCache
361364
? undefined
362365
: {
363-
handler: "index.handler",
366+
handler: indexHandler,
364367
bundle: ".open-next/revalidation-function",
365368
},
366369
},

packages/open-next/src/core/routing/i18n/accept-header.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Options {
1313
type: "accept-language";
1414
}
1515

16+
// eslint-disable-next-line sonarjs/cognitive-complexity
1617
function parse(
1718
raw: string,
1819
preferences: string[] | undefined,

packages/open-next/src/core/routingHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface MiddlewareOutputEvent {
2626

2727
// Add the locale prefix to the regex so we correctly match the rawPath
2828
const optionalLocalePrefixRegex = !!RoutesManifest.locales.length
29-
? `^/(?:${RoutesManifest.locales.map((locale) => `${locale}/?`).join("|")})?`
29+
? `^/(?:${RoutesManifest.locales.map((locale) => locale + "/?").join("|")})?`
3030
: "^/";
3131

3232
// Add the basepath prefix to the regex so we correctly match the rawPath

packages/open-next/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function parseArgs() {
1818
acc[key] = undefined;
1919
} else if (self[ind + 1]) {
2020
acc[key] = self[ind + 1];
21+
// eslint-disable-next-line sonarjs/elseif-without-else
2122
} else if (!self[ind + 1]) {
2223
acc[key] = undefined;
2324
}

packages/open-next/src/minimize-js.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
// Copied and modified from node-minify-all-js by Adones Pitogo
23
// https://github.com/adonespitogo/node-minify-all-js/blob/master/index.js
34

packages/open-next/src/plugins/edge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function openNextEdgePlugins({
5757
});
5858
}
5959

60-
build.onResolve({ filter: /\.(mjs|wasm)$/g }, (args) => {
60+
build.onResolve({ filter: /\.(mjs|wasm)$/g }, () => {
6161
return {
6262
external: true,
6363
};

0 commit comments

Comments
 (0)