eslint-rule-benchmark
Version:
Benchmark ESLint rules with detailed performance metrics for CI and plugin development
67 lines (66 loc) • 3.27 kB
TypeScript
import { ReporterOptions } from '../types/benchmark-config'
import { UserBenchmarkConfig } from '../types/user-benchmark-config'
/** Parameters for running benchmarks based on a user configuration. */
interface RunBenchmarksFromConfigParameters {
/** Options for the reporters. */
reporterOptions: ReporterOptions[]
/** The user-defined benchmark configuration. */
userConfig: UserBenchmarkConfig
/** Optional path to custom ESLint config file. */
eslintConfigFile?: string
/** User configuration directory path. */
configDirectory: string
}
/**
* Orchestrates the entire benchmark process based on a user-provided
* configuration.
*
* This function takes a `UserBenchmarkConfig` object and reporter options. It
* performs the following main stages:
*
* 1. **Parallel Preparation**: a. For each test specification (`testSpec`) in
* `userConfig.tests`: i. Determines the specific benchmark settings
* (`specBenchmarkConfig`) by merging global `userConfig` settings with any
* overrides from the current `testSpec`. Ii. For each `caseItem` within the
* `testSpec.cases` array: - Loads code samples using `loadCodeSamples` based
* on `caseItem.testPath`. - Creates a `RuleConfig` using the `testSpec`'s
* rule information (`ruleId`, `rulePath`) and the `caseItem`'s specific
* `options` and `severity`. - Generates a `TestCase` object which includes
* the loaded samples and the `RuleConfig`. B. All these preparation tasks
* (for all `testSpec`s and their `caseItem`s) are executed in parallel using
* `Promise.all`. Errors during individual case processing are caught, and
* problematic cases are skipped.
* 2. **Sequential Benchmarking**: a. After all test cases are prepared, the
* function iterates through the data मौसम for each `testSpec`. B. For each
* `testSpec` that has valid `TestCase`s, it calls `runBenchmark`
* _sequentially_. This ensures that benchmark runs for different test
* specifications do not interfere with each other. The call to
* `runBenchmark` uses the `testCases` prepared for that specific `testSpec`
* and its determined `specBenchmarkConfig`.
* 3. **Reporting**: a. All `Task` results from all `runBenchmark` calls are
* aggregated. B. For each `Task` result, the corresponding `TestCase` (which
* contains the rule context) is identified. C. `runReporters` is called for
* each task to output or save the benchmark results.
*
* If no valid `TestCase` objects can be generated from the entire
* configuration, an error is logged, and the process may exit with an error
* code.
*
* @example
* // Assuming userConfig and reporterOpts are defined:
* await runBenchmarksFromConfig({
* userConfig,
* reporterOptions: reporterOpts,
* })
*
* @param parameters - An object containing the `userConfig` (the
* UserBenchmarkConfig object) and `reporterOptions` (an array of reporter
* configurations).
* @returns A promise that resolves when all benchmarks have been run and
* reported, or when the process exits due to critical errors (e.g., no valid
* test cases).
*/
export declare function runBenchmarksFromConfig(
parameters: RunBenchmarksFromConfigParameters,
): Promise<void>
export {}