From 7ee8e7fab8412673bdfc740d49d31709eea26eee Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 20 Dec 2022 17:16:44 +0100 Subject: [PATCH] chore: fix lint issues --- .eslintrc | 4 +++- scripts/bump-edge.ts | 2 +- src/compress.ts | 2 +- src/options.ts | 2 +- src/prerender.ts | 2 +- src/rollup/plugins/replace.ts | 2 +- src/rollup/plugins/server-assets.ts | 2 +- src/rollup/plugins/timing.ts | 2 ++ src/runtime/config.ts | 2 +- src/runtime/route-rules.ts | 4 +++- src/scan.ts | 2 +- src/types/fetch.ts | 7 ++++--- src/types/nitro.ts | 1 + test/fixture/types.ts | 2 +- 14 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.eslintrc b/.eslintrc index 01f1e369c8..6ecc1c66e0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,6 +14,8 @@ "unicorn/no-useless-undefined": 0, "unicorn/no-await-expression-member": 0, "unicorn/no-array-push-push": 0, - "unicorn/filename-case": 0 + "unicorn/filename-case": 0, + "@typescript-eslint/no-unused-vars": 0, + "@typescript-eslint/no-non-null-assertion": 0 } } diff --git a/scripts/bump-edge.ts b/scripts/bump-edge.ts index 3bc50968b3..2a31d25bc3 100755 --- a/scripts/bump-edge.ts +++ b/scripts/bump-edge.ts @@ -13,7 +13,7 @@ async function loadPackage(dir: string) { const save = () => fsp.writeFile(pkgPath, JSON.stringify(data, null, 2) + "\n"); - const updateDeps = (reviver: Function) => { + const updateDeps = (reviver: (dep: any) => any) => { for (const type of [ "dependencies", "devDependencies", diff --git a/src/compress.ts b/src/compress.ts index a4c906fd6e..d008c3423f 100644 --- a/src/compress.ts +++ b/src/compress.ts @@ -119,7 +119,7 @@ const COMPRESSIBLE_MIMES_RE = new Set([ "text/x-component", "text/x-java-source", "text/x-script", - "vnd.apple.mpegurl" + "vnd.apple.mpegurl", ]); function isCompressableMime(mimeType: string) { diff --git a/src/options.ts b/src/options.ts index 605614d60a..6cd1bbc139 100644 --- a/src/options.ts +++ b/src/options.ts @@ -119,7 +119,7 @@ export async function loadOptions( }, defaults: NitroDefaults, resolve(id: string) { - const presets = _PRESETS as any as Map; + const presets = _PRESETS as any as Map; let matchedPreset = presets[camelCase(id)] || presets[id]; if (!matchedPreset) { return null; diff --git a/src/prerender.ts b/src/prerender.ts index 2b45322805..9daad9555d 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -77,7 +77,7 @@ export async function prerender(nitro: Nitro) { // Start prerendering const generatedRoutes = new Set(); const displayedLengthWarns = new Set(); - const canPrerender = (route: string = "/") => { + const canPrerender = (route = "/") => { // Skip if route is already generated if (generatedRoutes.has(route)) { return false; diff --git a/src/rollup/plugins/replace.ts b/src/rollup/plugins/replace.ts index 5bb8c3768f..ea8fba74fd 100644 --- a/src/rollup/plugins/replace.ts +++ b/src/rollup/plugins/replace.ts @@ -11,7 +11,7 @@ export function replace(options: RollupReplaceOptions): Plugin { // https://github.com/rollup/plugins/blob/master/packages/replace/src/index.js#L94 renderChunk(code, chunk, options) { if (!NO_REPLACE_RE.test(code)) { - return (_plugin.renderChunk as Function).call( + return (_plugin.renderChunk as () => any).call( this, code, chunk, diff --git a/src/rollup/plugins/server-assets.ts b/src/rollup/plugins/server-assets.ts index 7cdf319896..50f8847641 100644 --- a/src/rollup/plugins/server-assets.ts +++ b/src/rollup/plugins/server-assets.ts @@ -9,7 +9,7 @@ import type { Nitro } from "../../types"; import { virtual } from "./virtual"; export interface ServerAssetOptions { - inline: Boolean; + inline: boolean; dirs: { [assetdir: string]: { dir: string; diff --git a/src/rollup/plugins/timing.ts b/src/rollup/plugins/timing.ts index 8a764cbd1c..88fab18517 100644 --- a/src/rollup/plugins/timing.ts +++ b/src/rollup/plugins/timing.ts @@ -1,6 +1,8 @@ import { extname } from "pathe"; import type { Plugin, RenderedChunk } from "rollup"; +// TODO +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface Options {} const TIMING = "globalThis.__timing__"; diff --git a/src/runtime/config.ts b/src/runtime/config.ts index 03bee111a9..30fff319b7 100644 --- a/src/runtime/config.ts +++ b/src/runtime/config.ts @@ -18,7 +18,7 @@ const getEnv = (key: string) => { function isObject(input: unknown) { return typeof input === "object" && !Array.isArray(input); } -function overrideConfig(obj: object, parentKey: string = "") { +function overrideConfig(obj: object, parentKey = "") { for (const key in obj) { const subKey = parentKey ? `${parentKey}_${key}` : key; const envValue = getEnv(subKey); diff --git a/src/runtime/route-rules.ts b/src/runtime/route-rules.ts index a34447e0f4..42613aaa30 100644 --- a/src/runtime/route-rules.ts +++ b/src/runtime/route-rules.ts @@ -33,7 +33,9 @@ export function getRouteRules(event: H3Event): NitroRouteRules { event.context._nitro = event.context._nitro || {}; if (!event.context._nitro.routeRules) { const path = new URL(event.req.url, "http://localhost").pathname; - event.context._nitro.routeRules = getRouteRulesForPath(withoutBase(path, useRuntimeConfig().app.baseURL)); + event.context._nitro.routeRules = getRouteRulesForPath( + withoutBase(path, useRuntimeConfig().app.baseURL) + ); } return event.context._nitro.routeRules; } diff --git a/src/scan.ts b/src/scan.ts index ccc4fbd5d7..7d08777ae9 100644 --- a/src/scan.ts +++ b/src/scan.ts @@ -29,7 +29,7 @@ export function scanMiddleware(nitro: Nitro) { })); } -export function scanRoutes(nitro: Nitro, dir: string, prefix: string = "/") { +export function scanRoutes(nitro: Nitro, dir: string, prefix = "/") { return scanServerDir(nitro, dir, (file) => { let route = file.path .replace(/\.[A-Za-z]+$/, "") diff --git a/src/types/fetch.ts b/src/types/fetch.ts index fa2df9f2e2..fead97c35d 100644 --- a/src/types/fetch.ts +++ b/src/types/fetch.ts @@ -3,11 +3,13 @@ import type { FetchRequest, FetchOptions, FetchResponse } from "ofetch"; import type { MatchedRoutes } from "./utils"; // An interface to extend in a local project +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface InternalApi {} export type NitroFetchRequest = | Exclude | Exclude + // eslint-disable-next-line @typescript-eslint/ban-types | (string & {}); export type MiddlewareOf< @@ -92,11 +94,10 @@ export interface $Fetch< } declare global { - // eslint-disable-next-line no-var, no-unused-vars + // eslint-disable-next-line no-var var $fetch: $Fetch; - // eslint-disable-next-line no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { - // eslint-disable-next-line no-unused-vars interface Global { $fetch: $Fetch; } diff --git a/src/types/nitro.ts b/src/types/nitro.ts index f0a43c2756..1fdfc1b80b 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -142,6 +142,7 @@ export interface NitroOptions extends PresetOptions { // General debug: boolean; + // eslint-disable-next-line @typescript-eslint/ban-types preset: KebabCase | (string & {}); logLevel: LogLevel; runtimeConfig: { diff --git a/test/fixture/types.ts b/test/fixture/types.ts index 1b2c53d184..fe3b45eebf 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -10,7 +10,7 @@ const $fetch = {} as $Fetch; describe("API routes", () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars - const dynamicString: string = ""; + const dynamicString = ""; it("generates types for middleware, unknown and manual typed routes", () => { expectTypeOf($fetch("/")).toMatchTypeOf>(); // middleware