From 26e1e07536b9d2c0e7370f3d0fdd3ff89b04e126 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 7 Jul 2024 09:38:08 +0800 Subject: [PATCH] chore: lint --- src/node/build.ts | 3 ++- src/node/cli.ts | 2 +- src/node/critical.ts | 2 +- src/node/jsdomGlobal.mjs | 3 ++- src/utils/state.ts | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/node/build.ts b/src/node/build.ts index 752b32a..9641d40 100644 --- a/src/node/build.ts +++ b/src/node/build.ts @@ -241,7 +241,8 @@ export async function build(ssgOptions: Partial = {}, viteConfig async function detectEntry(root: string) { // pick the first script tag of type module as the entry - const scriptSrcReg = /(?:[\n\r\s]*?)(?:<\/script>)/img + // eslint-disable-next-line regexp/no-super-linear-backtracking + const scriptSrcReg = /\s*<\/script>/gi const html = await fs.readFile(join(root, 'index.html'), 'utf-8') const scripts = [...html.matchAll(scriptSrcReg)] || [] const [, entry] = scripts.find((matchResult) => { diff --git a/src/node/cli.ts b/src/node/cli.ts index 3c7d16f..a8339da 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -1,10 +1,10 @@ -/* eslint-disable no-unused-expressions */ import process from 'node:process' import { bold, gray, red, reset, underline } from 'kolorist' import yargs from 'yargs' import { hideBin } from 'yargs/helpers' import { build } from './build' +// eslint-disable-next-line ts/no-unused-expressions yargs(hideBin(process.argv)) .scriptName('vite-ssg') .usage('$0 [args]') diff --git a/src/node/critical.ts b/src/node/critical.ts index d405afc..98a8c11 100644 --- a/src/node/critical.ts +++ b/src/node/critical.ts @@ -14,7 +14,7 @@ export async function getCritters(outDir: string, options: Options = {}): Promis ...options, }) } - catch (e) { + catch { return undefined } } diff --git a/src/node/jsdomGlobal.mjs b/src/node/jsdomGlobal.mjs index f1c5a71..f131472 100644 --- a/src/node/jsdomGlobal.mjs +++ b/src/node/jsdomGlobal.mjs @@ -42,8 +42,9 @@ export function jsdomGlobal(html = defaultHtml, options = {}) { && global.navigator.userAgent && global.navigator.userAgent.includes('Node.js') && global.document - && typeof global.document.destroy === 'function') + && typeof global.document.destroy === 'function') { return global.document.destroy + } // set a default url if we don't get one - otherwise things explode when we copy localstorage keys if (!('url' in options)) diff --git a/src/utils/state.ts b/src/utils/state.ts index 24f0313..fdb5356 100644 --- a/src/utils/state.ts +++ b/src/utils/state.ts @@ -1,5 +1,5 @@ // https://github.com/yahoo/serialize-javascript -const UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g +const UNSAFE_CHARS_REGEXP = /[<>/\u2028\u2029]/g const ESCAPED_CHARS = { '<': '\\u003C', '>': '\\u003E',