From 359ead5df6164fa68e32239b33754dd56b399684 Mon Sep 17 00:00:00 2001 From: 9aoy <9aoyuao@gmail.com> Date: Thu, 26 Feb 2026 16:28:22 +0800 Subject: [PATCH 1/2] chore: fix some lint errors --- packages/core/src/cli/index.ts | 2 +- packages/core/src/core/cliShortcuts.ts | 12 +- packages/core/src/core/globalSetup.ts | 4 +- packages/core/src/core/listTests.ts | 10 +- packages/core/src/core/plugins/basic.ts | 272 +++++++++--------- .../core/src/core/plugins/css-filter/index.ts | 2 +- packages/core/src/core/plugins/entry.ts | 2 +- packages/core/src/core/plugins/external.ts | 52 ++-- .../src/core/plugins/ignoreResolveError.ts | 2 +- packages/core/src/core/plugins/inspect.ts | 2 +- packages/core/src/core/plugins/mockRuntime.ts | 2 +- .../src/core/plugins/moduleCacheControl.ts | 2 +- packages/core/src/core/rsbuild.ts | 4 +- packages/core/src/core/rstest.ts | 2 +- packages/core/src/core/runTests.ts | 2 +- packages/core/src/reporter/githubActions.ts | 4 +- packages/core/src/reporter/index.ts | 6 +- packages/core/src/reporter/junit.ts | 4 +- packages/core/src/reporter/md.ts | 6 +- packages/core/src/reporter/statusRenderer.ts | 6 +- packages/core/src/reporter/verbose.ts | 2 +- .../core/src/reporter/windowedRenderer.ts | 8 +- packages/core/src/runtime/api/mockObject.ts | 2 +- packages/core/src/runtime/api/utilities.ts | 34 +-- packages/core/src/runtime/runner/runtime.ts | 10 +- packages/core/src/runtime/worker/interop.ts | 2 +- .../core/src/runtime/worker/loadEsModule.ts | 2 +- packages/core/src/runtime/worker/snapshot.ts | 2 +- packages/vscode/src/project.ts | 1 - rslint.jsonc | 1 - 30 files changed, 221 insertions(+), 241 deletions(-) diff --git a/packages/core/src/cli/index.ts b/packages/core/src/cli/index.ts index fd9351c0e..adbd7a2f0 100644 --- a/packages/core/src/cli/index.ts +++ b/packages/core/src/cli/index.ts @@ -4,7 +4,7 @@ import { prepareCli } from './prepare'; export { initCli } from './init'; -export async function runCLI(): Promise { +export function runCLI(): void { // make it easier to identify the process via activity monitor or other tools process.title = 'rstest-node'; prepareCli(); diff --git a/packages/core/src/core/cliShortcuts.ts b/packages/core/src/core/cliShortcuts.ts index de5aba506..5e16c5bf1 100644 --- a/packages/core/src/core/cliShortcuts.ts +++ b/packages/core/src/core/cliShortcuts.ts @@ -55,10 +55,10 @@ export async function setupCliShortcuts({ } catch {} }; - const promptInput = async ( + const promptInput = ( promptText: string, onComplete: (value: string | undefined) => Promise, - ): Promise => { + ): void => { if (isPrompting) return; isPrompting = true; @@ -145,9 +145,9 @@ export async function setupCliShortcuts({ { key: 't', description: `${color.bold('t')} ${color.dim('filter by a test name regex pattern')}`, - action: async () => { + action: () => { clearCurrentInputLine(); - await promptInput( + promptInput( 'Enter test name pattern (empty to clear): ', async (pattern) => { await runWithTestNamePattern(pattern); @@ -158,9 +158,9 @@ export async function setupCliShortcuts({ { key: 'p', description: `${color.bold('p')} ${color.dim('filter by a filename regex pattern')}`, - action: async () => { + action: () => { clearCurrentInputLine(); - await promptInput( + promptInput( 'Enter file name pattern (empty to clear): ', async (input) => { const filters = input diff --git a/packages/core/src/core/globalSetup.ts b/packages/core/src/core/globalSetup.ts index 2d561c035..05f3644a1 100644 --- a/packages/core/src/core/globalSetup.ts +++ b/packages/core/src/core/globalSetup.ts @@ -19,7 +19,7 @@ function applyEnvChanges(changes: Record) { const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -async function createSetupPool() { +function createSetupPool() { const options: Options = { runtime: 'child_process', filename: resolve(__dirname, './globalSetupWorker.js'), @@ -61,7 +61,7 @@ export async function runGlobalSetup({ success: boolean; errors?: any[]; }> { - const pool = await createSetupPool(); + const pool = createSetupPool(); const result = await pool.run({ type: 'setup', diff --git a/packages/core/src/core/listTests.ts b/packages/core/src/core/listTests.ts index ff0eb0056..534dcc89b 100644 --- a/packages/core/src/core/listTests.ts +++ b/packages/core/src/core/listTests.ts @@ -39,8 +39,8 @@ const collectNodeTests = async ({ if (nodeProjects.length === 0) { return { list: [], - getSourceMap: async (_name: string) => null, - close: async () => {}, + getSourceMap: async () => null, + close: async () => undefined, }; } @@ -183,7 +183,7 @@ const collectBrowserTests = async ({ if (browserProjects.length === 0) { return { list: [], - close: async () => {}, + close: async () => undefined, }; } @@ -216,10 +216,10 @@ const collectTestFiles = async ({ ); } return { - close: async () => {}, + close: async () => undefined, errors: [], list, - getSourceMap: async (_name: string) => null, + getSourceMap: async () => null, }; }; diff --git a/packages/core/src/core/plugins/basic.ts b/packages/core/src/core/plugins/basic.ts index d99cb3904..2954dda68 100644 --- a/packages/core/src/core/plugins/basic.ts +++ b/packages/core/src/core/plugins/basic.ts @@ -28,160 +28,154 @@ export const pluginBasic: (context: RstestContext) => RsbuildPlugin = ( .oneOf(CHAIN_ID.ONE_OF.JS_MAIN) .delete('type'); }); - api.modifyEnvironmentConfig( - async (config, { mergeEnvironmentConfig, name }) => { - const { - normalizedConfig: { - resolve, - source, - output, - tools, - dev, - testEnvironment, - }, - outputModule, - rootPath, - } = context.projects.find((p) => p.environmentName === name)!; - return mergeEnvironmentConfig( - config, - { - tools, - resolve, - source, - output, - dev, + api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig, name }) => { + const { + normalizedConfig: { + resolve, + source, + output, + tools, + dev, + testEnvironment, + }, + outputModule, + rootPath, + } = context.projects.find((p) => p.environmentName === name)!; + return mergeEnvironmentConfig( + config, + { + tools, + resolve, + source, + output, + dev, + }, + { + source: { + define: { + 'import.meta.rstest': "global['@rstest/core']", + 'import.meta.env': 'process.env', + }, }, - { - source: { - define: { - 'import.meta.rstest': "global['@rstest/core']", - 'import.meta.env': 'process.env', - }, + output: { + // Pass resources to the worker on demand according to entry + manifest: `${name}-manifest.json`, + sourceMap: { + js: 'source-map', }, - output: { - // Pass resources to the worker on demand according to entry - manifest: `${name}-manifest.json`, - sourceMap: { - js: 'source-map', - }, - module: outputModule, - filename: outputModule - ? { - js: '[name].mjs', - } - : undefined, - distPath: { - root: - context.projects.length > 1 - ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` - : TEMP_RSTEST_OUTPUT_DIR, - }, + module: outputModule, + filename: outputModule + ? { + js: '[name].mjs', + } + : undefined, + distPath: { + root: + context.projects.length > 1 + ? `${TEMP_RSTEST_OUTPUT_DIR}/${name}` + : TEMP_RSTEST_OUTPUT_DIR, }, - tools: { - rspack: (config, { isProd, rspack }) => { - // keep windows path as native path - config.context = path.resolve(rootPath); - // treat `test` as development mode - config.mode = isProd ? 'production' : 'development'; - config.output ??= {}; - config.output.iife = false; - // polyfill interop - config.output.importFunctionName = outputModule - ? 'import.meta.__rstest_dynamic_import__' - : '__rstest_dynamic_import__'; - config.output.devtoolModuleFilenameTemplate = - '[absolute-resource-path]'; + }, + tools: { + rspack: (config, { isProd, rspack }) => { + // keep windows path as native path + config.context = path.resolve(rootPath); + // treat `test` as development mode + config.mode = isProd ? 'production' : 'development'; + config.output ??= {}; + config.output.iife = false; + // polyfill interop + config.output.importFunctionName = outputModule + ? 'import.meta.__rstest_dynamic_import__' + : '__rstest_dynamic_import__'; + config.output.devtoolModuleFilenameTemplate = + '[absolute-resource-path]'; - if (!config.devtool || !config.devtool.includes('inline')) { - config.devtool = 'nosources-source-map'; - } + if (!config.devtool || !config.devtool.includes('inline')) { + config.devtool = 'nosources-source-map'; + } + + config.plugins.push( + new rspack.experiments.RstestPlugin({ + injectModulePathName: true, + importMetaPathName: true, + hoistMockModule: true, + manualMockRoot: pathe.resolve(rootPath, '__mocks__'), + }), + ); + config.module.rules ??= []; + config.module.rules.push({ + test: /\.mts$/, + // Treated mts as strict ES modules. + type: 'javascript/esm', + }); + + if (outputModule) { config.plugins.push( - new rspack.experiments.RstestPlugin({ - injectModulePathName: true, - importMetaPathName: true, - hoistMockModule: true, - manualMockRoot: pathe.resolve(rootPath, '__mocks__'), + new rspack.BannerPlugin({ + banner: requireShim, + // Just before minify stage, to perform tree shaking. + stage: rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1, + raw: true, + include: /\.(js|mjs)$/, }), ); + } - config.module.rules ??= []; - config.module.rules.push({ - test: /\.mts$/, - // Treated mts as strict ES modules. - type: 'javascript/esm', - }); - - if (outputModule) { - config.plugins.push( - new rspack.BannerPlugin({ - banner: requireShim, - // Just before minify stage, to perform tree shaking. - stage: - rspack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE - 1, - raw: true, - include: /\.(js|mjs)$/, - }), - ); - } - - config.module.parser ??= {}; - config.module.parser.javascript = { - // Keep dynamic import expressions. - // eg. (modulePath) => import(modulePath) - importDynamic: false, - // Keep dynamic require expressions. - // eg. (modulePath) => require(modulePath) - requireDynamic: false, - requireAsExpression: false, - // Keep require.resolve expressions. - requireResolve: false, - ...(config.module.parser.javascript || {}), - // suppress ESModulesLinkingError for exports that might be implemented in mock - exportsPresence: 'warn', - }; + config.module.parser ??= {}; + config.module.parser.javascript = { + // Keep dynamic import expressions. + // eg. (modulePath) => import(modulePath) + importDynamic: false, + // Keep dynamic require expressions. + // eg. (modulePath) => require(modulePath) + requireDynamic: false, + requireAsExpression: false, + // Keep require.resolve expressions. + requireResolve: false, + ...(config.module.parser.javascript || {}), + // suppress ESModulesLinkingError for exports that might be implemented in mock + exportsPresence: 'warn', + }; - config.resolve ??= {}; - config.resolve.extensions ??= []; - config.resolve.extensions.push('.cjs'); + config.resolve ??= {}; + config.resolve.extensions ??= []; + config.resolve.extensions.push('.cjs'); - // TypeScript allows importing TS files with `.js` extension - config.resolve.extensionAlias ??= {}; - config.resolve.extensionAlias['.js'] = ['.js', '.ts', '.tsx']; - config.resolve.extensionAlias['.jsx'] = ['.jsx', '.tsx']; + // TypeScript allows importing TS files with `.js` extension + config.resolve.extensionAlias ??= {}; + config.resolve.extensionAlias['.js'] = ['.js', '.ts', '.tsx']; + config.resolve.extensionAlias['.jsx'] = ['.jsx', '.tsx']; - if (testEnvironment.name === 'node') { - // skip `module` field in Node.js environment. - // ESM module resolved by module field is not always a native ESM module - config.resolve.mainFields = config.resolve.mainFields?.filter( - (filed) => filed !== 'module', - ) || ['main']; - } + if (testEnvironment.name === 'node') { + // skip `module` field in Node.js environment. + // ESM module resolved by module field is not always a native ESM module + config.resolve.mainFields = config.resolve.mainFields?.filter( + (filed) => filed !== 'module', + ) || ['main']; + } - config.resolve.byDependency ??= {}; - config.resolve.byDependency.commonjs ??= {}; - // skip `module` field when commonjs require - // By default, rspack resolves the "module" field for commonjs first, but this is not always returned synchronously in esm - config.resolve.byDependency.commonjs.mainFields = [ - 'main', - '...', - ]; + config.resolve.byDependency ??= {}; + config.resolve.byDependency.commonjs ??= {}; + // skip `module` field when commonjs require + // By default, rspack resolves the "module" field for commonjs first, but this is not always returned synchronously in esm + config.resolve.byDependency.commonjs.mainFields = ['main', '...']; - config.optimization = { - moduleIds: 'named', - chunkIds: 'named', - nodeEnv: false, - ...(config.optimization || {}), - // make sure setup file and test file share the runtime - runtimeChunk: { - name: `${name}-${RUNTIME_CHUNK_NAME}`, - }, - }; - }, + config.optimization = { + moduleIds: 'named', + chunkIds: 'named', + nodeEnv: false, + ...(config.optimization || {}), + // make sure setup file and test file share the runtime + runtimeChunk: { + name: `${name}-${RUNTIME_CHUNK_NAME}`, + }, + }; }, }, - ); - }, - ); + }, + ); + }); }, }); diff --git a/packages/core/src/core/plugins/css-filter/index.ts b/packages/core/src/core/plugins/css-filter/index.ts index 11c81141a..57bf1865c 100644 --- a/packages/core/src/core/plugins/css-filter/index.ts +++ b/packages/core/src/core/plugins/css-filter/index.ts @@ -19,7 +19,7 @@ export const pluginCSSFilter = (): RsbuildPlugin => ({ setup(api) { api.modifyBundlerChain({ order: 'post', - handler: async (chain, { target, CHAIN_ID, environment }) => { + handler: (chain, { target, CHAIN_ID, environment }) => { const emitCss = environment.config.output.emitCss ?? target === 'web'; if (!emitCss) { const ruleIds = [ diff --git a/packages/core/src/core/plugins/entry.ts b/packages/core/src/core/plugins/entry.ts index 1f926b7c2..96f721116 100644 --- a/packages/core/src/core/plugins/entry.ts +++ b/packages/core/src/core/plugins/entry.ts @@ -3,7 +3,7 @@ import type { RstestContext } from '../../types'; import { castArray, TEMP_RSTEST_OUTPUT_DIR_GLOB } from '../../utils'; class TestFileWatchPlugin { - private contextToWatch: string | null = null; + private readonly contextToWatch: string | null = null; constructor(contextToWatch: string) { this.contextToWatch = contextToWatch; diff --git a/packages/core/src/core/plugins/external.ts b/packages/core/src/core/plugins/external.ts index f43bc9fba..7058d7168 100644 --- a/packages/core/src/core/plugins/external.ts +++ b/packages/core/src/core/plugins/external.ts @@ -100,35 +100,33 @@ export const pluginExternal: (context: RstestContext) => RsbuildPlugin = ( ) => ({ name: 'rstest:external', setup: (api) => { - api.modifyEnvironmentConfig( - async (config, { mergeEnvironmentConfig, name }) => { - const { - normalizedConfig: { testEnvironment }, - outputModule, - } = context.projects.find((p) => p.environmentName === name)!; - return mergeEnvironmentConfig(config, { - output: { - externals: - testEnvironment.name === 'node' - ? [autoExternalNodeModules(outputModule)] - : undefined, - }, - tools: { - rspack: (config) => { - // Make sure that externals configuration is not modified by users - config.externals = castArray(config.externals) || []; + api.modifyEnvironmentConfig((config, { mergeEnvironmentConfig, name }) => { + const { + normalizedConfig: { testEnvironment }, + outputModule, + } = context.projects.find((p) => p.environmentName === name)!; + return mergeEnvironmentConfig(config, { + output: { + externals: + testEnvironment.name === 'node' + ? [autoExternalNodeModules(outputModule)] + : undefined, + }, + tools: { + rspack: (config) => { + // Make sure that externals configuration is not modified by users + config.externals = castArray(config.externals) || []; - config.externals.unshift({ - '@rstest/core': 'global @rstest/core', - }); + config.externals.unshift({ + '@rstest/core': 'global @rstest/core', + }); - config.externalsPresets ??= {}; - config.externalsPresets.node = false; - config.externals.unshift(autoExternalNodeBuiltin); - }, + config.externalsPresets ??= {}; + config.externalsPresets.node = false; + config.externals.unshift(autoExternalNodeBuiltin); }, - }); - }, - ); + }, + }); + }); }, }); diff --git a/packages/core/src/core/plugins/ignoreResolveError.ts b/packages/core/src/core/plugins/ignoreResolveError.ts index dc93bdcc3..772f69387 100644 --- a/packages/core/src/core/plugins/ignoreResolveError.ts +++ b/packages/core/src/core/plugins/ignoreResolveError.ts @@ -19,7 +19,7 @@ class IgnoreModuleNotFoundErrorPlugin { export const pluginIgnoreResolveError: RsbuildPlugin = { name: 'rstest:ignore-resolve-error', setup: (api) => { - api.modifyRspackConfig(async (config) => { + api.modifyRspackConfig((config) => { config.plugins.push(new IgnoreModuleNotFoundErrorPlugin()); config.optimization ??= {}; config.optimization.emitOnErrors = true; diff --git a/packages/core/src/core/plugins/inspect.ts b/packages/core/src/core/plugins/inspect.ts index 2a1757d4d..2a1c01028 100644 --- a/packages/core/src/core/plugins/inspect.ts +++ b/packages/core/src/core/plugins/inspect.ts @@ -19,7 +19,7 @@ export const pluginInspect: (options?: { ? { name: 'rstest:inspect', setup: (api) => { - api.modifyRspackConfig(async (config) => { + api.modifyRspackConfig((config) => { // use inline source map or write to disk config.devtool = 'inline-nosources-source-map'; config.optimization ??= {}; diff --git a/packages/core/src/core/plugins/mockRuntime.ts b/packages/core/src/core/plugins/mockRuntime.ts index 1642811eb..e250f1297 100644 --- a/packages/core/src/core/plugins/mockRuntime.ts +++ b/packages/core/src/core/plugins/mockRuntime.ts @@ -89,7 +89,7 @@ class MockRuntimeRspackPlugin { export const pluginMockRuntime: RsbuildPlugin = { name: 'rstest:mock-runtime', setup: (api) => { - api.modifyRspackConfig(async (config) => { + api.modifyRspackConfig((config) => { config.plugins.push( new MockRuntimeRspackPlugin(Boolean(config.output.module)), ); diff --git a/packages/core/src/core/plugins/moduleCacheControl.ts b/packages/core/src/core/plugins/moduleCacheControl.ts index 920fec4ea..60eac0a36 100644 --- a/packages/core/src/core/plugins/moduleCacheControl.ts +++ b/packages/core/src/core/plugins/moduleCacheControl.ts @@ -67,7 +67,7 @@ export const pluginCacheControl: (setupFiles: string[]) => RsbuildPlugin = ( }); } - api.modifyRspackConfig(async (config) => { + api.modifyRspackConfig((config) => { config.plugins.push(new RstestCacheControlPlugin()); }); }, diff --git a/packages/core/src/core/rsbuild.ts b/packages/core/src/core/rsbuild.ts index 6a4275c39..2970f9cce 100644 --- a/packages/core/src/core/rsbuild.ts +++ b/packages/core/src/core/rsbuild.ts @@ -432,7 +432,7 @@ export const createRsbuildServer = async ({ } > = {}; - const getEntryFiles = async (manifest: ManifestData, outputPath: string) => { + const getEntryFiles = (manifest: ManifestData, outputPath: string) => { const entryFiles: Record = {}; const entries = Object.keys(manifest.entries); @@ -473,7 +473,7 @@ export const createRsbuildServer = async ({ timings: true, }); - const entryFiles = await getEntryFiles(manifest, outputPath!); + const entryFiles = getEntryFiles(manifest, outputPath!); const entries: EntryInfo[] = []; const setupEntries: EntryInfo[] = []; const globalSetupEntries: EntryInfo[] = []; diff --git a/packages/core/src/core/rstest.ts b/packages/core/src/core/rstest.ts index 162324e88..ce95d73e4 100644 --- a/packages/core/src/core/rstest.ts +++ b/packages/core/src/core/rstest.ts @@ -276,7 +276,7 @@ export function createReporters( // TODO: load third-party reporters throw new Error( - `Reporter ${reporter} not found. Please install it or use a built-in reporter.`, + `Reporter ${name} not found. Please install it or use a built-in reporter.`, ); } diff --git a/packages/core/src/core/runTests.ts b/packages/core/src/core/runTests.ts index 7ca4ceb8e..4fb983243 100644 --- a/packages/core/src/core/runTests.ts +++ b/packages/core/src/core/runTests.ts @@ -172,7 +172,7 @@ export async function runTests(context: Rstest): Promise { // Prevent an unhandled rejection window in mixed node+browser runs. // We still await the original promise later to surface the error. - browserResultPromise.catch(() => {}); + browserResultPromise.catch(() => undefined); } // If there are no node tests to run, we can potentially exit early. diff --git a/packages/core/src/reporter/githubActions.ts b/packages/core/src/reporter/githubActions.ts index a5a6d0fe6..e97568454 100644 --- a/packages/core/src/reporter/githubActions.ts +++ b/packages/core/src/reporter/githubActions.ts @@ -9,8 +9,8 @@ import type { import { getTaskNameWithPrefix, logger, TEST_DELIMITER } from '../utils'; export class GithubActionsReporter { - private onWritePath: (path: string) => string; - private rootPath: string; + private readonly onWritePath: (path: string) => string; + private readonly rootPath: string; constructor({ options, diff --git a/packages/core/src/reporter/index.ts b/packages/core/src/reporter/index.ts index 1922d760b..442250d2c 100644 --- a/packages/core/src/reporter/index.ts +++ b/packages/core/src/reporter/index.ts @@ -22,9 +22,9 @@ export class DefaultReporter implements Reporter { protected rootPath: string; protected config: NormalizedConfig; protected projectConfigs: Map; - private options: DefaultReporterOptions = {}; + private readonly options: DefaultReporterOptions = {}; protected statusRenderer: StatusRenderer | undefined; - private testState: RstestTestState; + private readonly testState: RstestTestState; constructor({ rootPath, @@ -129,7 +129,7 @@ export class DefaultReporter implements Reporter { logOutput(''); } - async onExit(): Promise { + onExit(): void { this.statusRenderer?.clear(); } diff --git a/packages/core/src/reporter/junit.ts b/packages/core/src/reporter/junit.ts index b635b4ff0..8a0f138b3 100644 --- a/packages/core/src/reporter/junit.ts +++ b/packages/core/src/reporter/junit.ts @@ -49,8 +49,8 @@ interface JUnitReport { } export class JUnitReporter implements Reporter { - private rootPath: string; - private outputPath?: string; + private readonly rootPath: string; + private readonly outputPath?: string; constructor({ rootPath, diff --git a/packages/core/src/reporter/md.ts b/packages/core/src/reporter/md.ts index f6ef30746..20c6e3063 100644 --- a/packages/core/src/reporter/md.ts +++ b/packages/core/src/reporter/md.ts @@ -840,9 +840,9 @@ const createCodeFrame = ( export class MdReporter implements Reporter { protected rootPath: string; protected config: NormalizedConfig; - private fileFilters: string[]; - private options: ResolvedOptions; - private logsByTestPath = new Map(); + private readonly fileFilters: string[]; + private readonly options: ResolvedOptions; + private readonly logsByTestPath = new Map(); constructor({ rootPath, diff --git a/packages/core/src/reporter/statusRenderer.ts b/packages/core/src/reporter/statusRenderer.ts index c4830a950..922d139d8 100644 --- a/packages/core/src/reporter/statusRenderer.ts +++ b/packages/core/src/reporter/statusRenderer.ts @@ -20,10 +20,10 @@ import { } from './windowedRenderer'; export class StatusRenderer { - private rootPath: string; - private renderer: WindowRenderer; + private readonly rootPath: string; + private readonly renderer: WindowRenderer; private startTime: number | undefined = undefined; - private testState: RstestTestState; + private readonly testState: RstestTestState; constructor( rootPath: string, diff --git a/packages/core/src/reporter/verbose.ts b/packages/core/src/reporter/verbose.ts index 1f5732f80..9d0da67a2 100644 --- a/packages/core/src/reporter/verbose.ts +++ b/packages/core/src/reporter/verbose.ts @@ -10,7 +10,7 @@ import { DefaultReporter } from './index'; import { logCase, logFileTitle } from './utils'; export class VerboseReporter extends DefaultReporter { - private verboseOptions: VerboseReporterOptions = {}; + private readonly verboseOptions: VerboseReporterOptions = {}; constructor({ rootPath, diff --git a/packages/core/src/reporter/windowedRenderer.ts b/packages/core/src/reporter/windowedRenderer.ts index 2be2d7e2d..196dbd745 100644 --- a/packages/core/src/reporter/windowedRenderer.ts +++ b/packages/core/src/reporter/windowedRenderer.ts @@ -44,15 +44,15 @@ type StreamType = 'output' | 'error'; * forwards all other intercepted `stdout` and `stderr` logs above it. */ export class WindowRenderer { - private options: Required; - private streams!: Record; - private buffer: { type: StreamType; message: string }[] = []; + private readonly options: Required; + private readonly streams!: Record; + private readonly buffer: { type: StreamType; message: string }[] = []; private renderInterval: NodeJS.Timeout | undefined = undefined; private renderScheduled = false; private windowHeight = 0; private finished = false; - private cleanups: (() => void)[] = []; + private readonly cleanups: (() => void)[] = []; constructor(options: Options) { this.options = { diff --git a/packages/core/src/runtime/api/mockObject.ts b/packages/core/src/runtime/api/mockObject.ts index d094b3614..83a69822e 100644 --- a/packages/core/src/runtime/api/mockObject.ts +++ b/packages/core/src/runtime/api/mockObject.ts @@ -272,7 +272,7 @@ export function mockObject>( configurable: descriptor.configurable, enumerable: descriptor.enumerable, get: () => undefined, - set: descriptor.set ? () => {} : undefined, + set: descriptor.set ? () => undefined : undefined, }); } } catch { diff --git a/packages/core/src/runtime/api/utilities.ts b/packages/core/src/runtime/api/utilities.ts index 0d97ff01d..bd6dfd9db 100644 --- a/packages/core/src/runtime/api/utilities.ts +++ b/packages/core/src/runtime/api/utilities.ts @@ -134,35 +134,25 @@ export const createRstestUtilities: ( } return rstest; }, - mock: () => { + // The below methods are not implemented in the core package. + // The actual implementation is managed by the built-in Rstest plugin. + mock: () => undefined, + mockRequire: () => undefined, + doMock: () => undefined, + doMockRequire: () => undefined, + unmock: () => undefined, + doUnmock: () => undefined, + importMock: () => { // The actual implementation is managed by the built-in Rstest plugin. - }, - mockRequire: () => { - // The actual implementation is managed by the built-in Rstest plugin. - }, - doMock: () => { - // The actual implementation is managed by the built-in Rstest plugin. - }, - doMockRequire: () => { - // The actual implementation is managed by the built-in Rstest plugin. - }, - unmock: () => { - // The actual implementation is managed by the built-in Rstest plugin. - }, - doUnmock: () => { - // The actual implementation is managed by the built-in Rstest plugin. - }, - importMock: async () => { - // The actual implementation is managed by the built-in Rstest plugin. - return {} as any; + return Promise.resolve({} as any); }, requireMock: () => { // The actual implementation is managed by the built-in Rstest plugin. return {} as any; }, - importActual: async () => { + importActual: () => { // The actual implementation is managed by the built-in Rstest plugin. - return {} as any; + return Promise.resolve({} as any); }, requireActual: () => { // The actual implementation is managed by the built-in Rstest plugin. diff --git a/packages/core/src/runtime/runner/runtime.ts b/packages/core/src/runtime/runner/runtime.ts index 4be1be547..5c5b80b5b 100644 --- a/packages/core/src/runtime/runner/runtime.ts +++ b/packages/core/src/runtime/runner/runtime.ts @@ -35,10 +35,10 @@ type CollectStatus = 'lazy' | 'running'; export class RunnerRuntime { /** all test cases */ - private tests: Test[] = []; + private readonly tests: Test[] = []; /** a calling stack of the current test suites and case */ - private _currentTest: Test[] = []; - private testPath: string; + private readonly _currentTest: Test[] = []; + private readonly testPath: string; private status: 'running' | 'collect' = 'collect'; /** @@ -48,8 +48,8 @@ export class RunnerRuntime { */ private collectStatus: CollectStatus = 'lazy'; private currentCollectList: (() => MaybePromise)[] = []; - private runtimeConfig; - private project: string; + private readonly runtimeConfig; + private readonly project: string; private testId = 1; constructor({ diff --git a/packages/core/src/runtime/worker/interop.ts b/packages/core/src/runtime/worker/interop.ts index 0f2ad6ba8..ce5efec5f 100644 --- a/packages/core/src/runtime/worker/interop.ts +++ b/packages/core/src/runtime/worker/interop.ts @@ -68,7 +68,7 @@ export const asModule = async ( if (unlinked) return m; - await m.link((() => {}) as unknown as vm.ModuleLinker); + await m.link((() => undefined) as unknown as vm.ModuleLinker); // @ts-expect-error copy from webpack if (m.instantiate) m.instantiate(); diff --git a/packages/core/src/runtime/worker/loadEsModule.ts b/packages/core/src/runtime/worker/loadEsModule.ts index db94b10f9..fe498ca2a 100644 --- a/packages/core/src/runtime/worker/loadEsModule.ts +++ b/packages/core/src/runtime/worker/loadEsModule.ts @@ -164,7 +164,7 @@ export const asModule = async ( if (unlinked) return syntheticModule; - await syntheticModule.link((() => {}) as unknown as ModuleLinker); + await syntheticModule.link((() => undefined) as unknown as ModuleLinker); await syntheticModule.evaluate(); return syntheticModule; }; diff --git a/packages/core/src/runtime/worker/snapshot.ts b/packages/core/src/runtime/worker/snapshot.ts index 73fbe008f..5cc3695cd 100644 --- a/packages/core/src/runtime/worker/snapshot.ts +++ b/packages/core/src/runtime/worker/snapshot.ts @@ -1,7 +1,7 @@ import { NodeSnapshotEnvironment } from '@vitest/snapshot/environment'; export class RstestSnapshotEnvironment extends NodeSnapshotEnvironment { - private resolveSnapshotPath: (filepath: string) => Promise; + private readonly resolveSnapshotPath: (filepath: string) => Promise; constructor(options: { resolveSnapshotPath: (filepath: string) => Promise; diff --git a/packages/vscode/src/project.ts b/packages/vscode/src/project.ts index e6568f9a4..14bf1c1ee 100644 --- a/packages/vscode/src/project.ts +++ b/packages/vscode/src/project.ts @@ -335,7 +335,6 @@ export class Project implements vscode.Disposable { path .relative(this.root.fsPath, vscode.Uri.parse(uriString).fsPath) .split(path.sep) - // biome-ignore lint/suspicious/noAssignInExpressions: just simple shorthand .reduce((tree, segment) => (tree[segment] ||= {}), tree); } diff --git a/rslint.jsonc b/rslint.jsonc index c98b809a4..7acb8383d 100644 --- a/rslint.jsonc +++ b/rslint.jsonc @@ -9,7 +9,6 @@ "plugins": ["@typescript-eslint"], // We should fix the corresponding code according to the following rules and gradually enable more rules. "rules": { - "@typescript-eslint/prefer-readonly": "off", "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-invalid-void-type": "off", From ea30212197d273287103f8a3b2f1e2032dd47d6d Mon Sep 17 00:00:00 2001 From: 9aoy <9aoyuao@gmail.com> Date: Thu, 26 Feb 2026 16:29:19 +0800 Subject: [PATCH 2/2] fix: update --- rslint.jsonc | 1 - 1 file changed, 1 deletion(-) diff --git a/rslint.jsonc b/rslint.jsonc index 7acb8383d..4e6f01d85 100644 --- a/rslint.jsonc +++ b/rslint.jsonc @@ -34,7 +34,6 @@ "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-redundant-type-constituents": "off", "@typescript-eslint/switch-exhaustiveness-check": "off", - "@typescript-eslint/no-empty-function": "off", }, }, ]