diff --git a/eslint.config.mjs b/eslint.config.mjs index c4e282b673..8f4fc6a467 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -5,6 +5,7 @@ import noOnlyTests from 'eslint-plugin-no-only-tests' import typegen from 'eslint-typegen' // @ts-expect-error missing types import perfectionist from 'eslint-plugin-perfectionist' +import regex from 'eslint-plugin-regexp' export default createConfigForNuxt({ features: { @@ -216,6 +217,9 @@ export default createConfigForNuxt({ 'vue/multi-word-component-names': 'off', }, }, + + // @ts-ignore types misaligned + regex.configs['flat/recommended'], ) // Generate type definitions for the eslint config diff --git a/package.json b/package.json index a3e094b228..0620a07d04 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint": "9.2.0", "eslint-plugin-no-only-tests": "3.1.0", "eslint-plugin-perfectionist": "2.10.0", + "eslint-plugin-regexp": "^2.5.0", "eslint-typegen": "0.2.4", "execa": "9.1.0", "fs-extra": "11.2.0", diff --git a/packages/kit/src/compatibility.ts b/packages/kit/src/compatibility.ts index a03813dd48..b2720f05c9 100644 --- a/packages/kit/src/compatibility.ts +++ b/packages/kit/src/compatibility.ts @@ -4,7 +4,7 @@ import type { Nuxt, NuxtCompatibility, NuxtCompatibilityIssues } from '@nuxt/sch import { useNuxt } from './context' export function normalizeSemanticVersion (version: string) { - return version.replace(/-[0-9]+\.[0-9a-f]+/, '') // Remove edge prefix + return version.replace(/-\d+\.[0-9a-f]+/, '') // Remove edge prefix } const builderMap = { diff --git a/packages/kit/src/internal/template.ts b/packages/kit/src/internal/template.ts index 9349f704df..5b40a2a214 100644 --- a/packages/kit/src/internal/template.ts +++ b/packages/kit/src/internal/template.ts @@ -27,7 +27,7 @@ export async function compileTemplate (template: NuxtTemplate, ctx: any) { } /** @deprecated */ -const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, r => JSON.parse(r).replace(/^{(.*)}$/, '$1')) +const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"\{(.+)\}"(?=,?$)/gm, r => JSON.parse(r).replace(/^\{(.*)\}$/, '$1')) /** @deprecated */ const importSources = (sources: string | string[], { lazy = false } = {}) => { diff --git a/packages/kit/src/runtime-config.ts b/packages/kit/src/runtime-config.ts index a83358f11c..f6e014fd3e 100644 --- a/packages/kit/src/runtime-config.ts +++ b/packages/kit/src/runtime-config.ts @@ -94,7 +94,7 @@ function applyEnv ( return obj } -const envExpandRx = /{{(.*?)}}/g +const envExpandRx = /\{\{(.*?)\}\}/g function _expandFromEnv (value: string, env: Record = process.env) { return value.replace(envExpandRx, (match, key) => { diff --git a/packages/kit/src/template.ts b/packages/kit/src/template.ts index 9290e62fd5..4aa9ec147b 100644 --- a/packages/kit/src/template.ts +++ b/packages/kit/src/template.ts @@ -202,7 +202,7 @@ export async function _generateTypes (nuxt: Nuxt) { } else { const path = stats?.isFile() // remove extension - ? relativePath.replace(/(?<=\w)\.\w+$/g, '') + ? relativePath.replace(/\b\.\w+$/g, '') // non-existent file probably shouldn't be resolved : aliases[alias] @@ -230,7 +230,7 @@ export async function _generateTypes (nuxt: Nuxt) { tsConfig.compilerOptions!.paths[alias] = await Promise.all(paths.map(async (path: string) => { if (!isAbsolute(path)) { return path } const stats = await fsp.stat(path).catch(() => null /* file does not exist */) - return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(/(?<=\w)\.\w+$/g, '') /* remove extension */ : path) + return relativeWithDot(nuxt.options.buildDir, stats?.isFile() ? path.replace(/\b\.\w+$/g, '') /* remove extension */ : path) })) } diff --git a/packages/nuxt/src/components/client-fallback-auto-id.ts b/packages/nuxt/src/components/client-fallback-auto-id.ts index 19b5a39984..7aa42f1d0a 100644 --- a/packages/nuxt/src/components/client-fallback-auto-id.ts +++ b/packages/nuxt/src/components/client-fallback-auto-id.ts @@ -10,7 +10,7 @@ interface LoaderOptions { transform?: ComponentsOptions['transform'] rootDir: string } -const CLIENT_FALLBACK_RE = /<(NuxtClientFallback|nuxt-client-fallback)( [^>]*)?>/ +const CLIENT_FALLBACK_RE = /<(?:NuxtClientFallback|nuxt-client-fallback)(?: [^>]*)?>/ const CLIENT_FALLBACK_GLOBAL_RE = /<(NuxtClientFallback|nuxt-client-fallback)( [^>]*)?>/g export const clientFallbackAutoIdPlugin = createUnplugin((options: LoaderOptions) => { const exclude = options.transform?.exclude || [] @@ -37,7 +37,7 @@ export const clientFallbackAutoIdPlugin = createUnplugin((options: LoaderOptions s.replace(CLIENT_FALLBACK_GLOBAL_RE, (full, name, attrs) => { count++ - if (/ :?uid=/g.test(attrs)) { return full } + if (/ :?uid=/.test(attrs)) { return full } return `<${name} :uid="'${hash(relativeID)}' + JSON.stringify($props) + '${count}'" ${attrs ?? ''}>` }) diff --git a/packages/nuxt/src/components/islandsTransform.ts b/packages/nuxt/src/components/islandsTransform.ts index 6e018dc167..ac5a954932 100644 --- a/packages/nuxt/src/components/islandsTransform.ts +++ b/packages/nuxt/src/components/islandsTransform.ts @@ -25,7 +25,7 @@ interface ComponentChunkOptions { } const SCRIPT_RE = /]*>/g -const HAS_SLOT_OR_CLIENT_RE = /(]*>)|(nuxt-client)/ +const HAS_SLOT_OR_CLIENT_RE = /]*>|nuxt-client/ const TEMPLATE_RE = /