Skip to content

Commit cb5e4e6

Browse files
feat: add eslint-config option to run-single command
Implements the `--config` command for run-single. This has been renamed from `config` to `eslint-config` to help better differentiate the differences between the run --config command.
1 parent ce09b65 commit cb5e4e6

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

cli/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ interface RunSingleCommandOptions {
2727
*/
2828
report: ReporterFormat
2929

30+
/** Optional path to an ESLint configuration file to use for linting. */
31+
eslintConfig?: string
32+
3033
/** Maximum allowed duration in ms. */
3134
maxDuration: number
3235

3336
/** The number of iterations to run the benchmark for the rule. */
3437
iterations: number
3538

36-
/** Optional path to an ESLint configuration file to use for linting. */
37-
config?: string
38-
3939
/** Optional path to a file where the benchmark report should be saved. */
4040
output?: string
4141

@@ -150,7 +150,7 @@ export function run(): void {
150150
.command('run-single', 'Run benchmark on a single ESLint rule')
151151
.option('--rule <rule>', 'Path to the ESLint rule file')
152152
.option('--name <name>', 'Name of the rule to benchmark')
153-
.option('--config <config>', 'Path to ESLint config file')
153+
.option('--eslint-config <config>', 'Path to ESLint config file')
154154
.option('--source <source>', 'Path to directory or file with test cases')
155155
.option('--iterations <number>', 'Number of benchmark iterations', {
156156
default: DEFAULT_ITERATIONS,
@@ -227,6 +227,7 @@ export function run(): void {
227227
console.info(`Using source: ${options.source}`)
228228

229229
await runBenchmarksFromConfig({
230+
eslintConfigFile: options.eslintConfig,
230231
reporterOptions: reporterOptionsArray,
231232
userConfig: constructedUserConfig,
232233
configDirectory,

core/benchmark/run-benchmark.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export interface ProcessedBenchmarkTask {
2121

2222
/** Parameters for running a benchmark. */
2323
interface RunBenchmarkParameters {
24+
/** Optional path to custom ESLint config file. */
25+
eslintConfigFile?: string
26+
2427
/** Configuration for the benchmark. */
2528
config: BenchmarkConfig
2629

@@ -69,7 +72,7 @@ type Language = (typeof LANGUAGES)[number]
6972
export async function runBenchmark(
7073
parameters: RunBenchmarkParameters,
7174
): Promise<ProcessedBenchmarkTask[] | null> {
72-
let { configDirectory, testCases, config } = parameters
75+
let { eslintConfigFile, configDirectory, testCases, config } = parameters
7376

7477
if (testCases.length === 0) {
7578
return null
@@ -103,6 +106,7 @@ export async function runBenchmark(
103106
eslint = await createESLintInstance({
104107
languages: currentTestCaseLanguages,
105108
rule: testCase.rule,
109+
eslintConfigFile,
106110
configDirectory,
107111
})
108112
await eslint.lintText('/* eslint-disable */')

core/eslint/create-eslint-instance.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { toSeverity } from './to-severity'
1212

1313
/** Options for creating an ESLint instance. */
1414
interface CreateESLintInstanceOptions {
15+
/** Optional path to custom ESLint config file. */
16+
eslintConfigFile?: string
17+
1518
/** The path to the user configuration directory. */
1619
configDirectory: string
1720

@@ -45,7 +48,7 @@ let jiti = createJiti(import.meta.url, {
4548
export async function createESLintInstance(
4649
instanceOptions: CreateESLintInstanceOptions,
4750
): Promise<ESLint> {
48-
let { configDirectory, languages, rule } = instanceOptions
51+
let { eslintConfigFile, configDirectory, languages, rule } = instanceOptions
4952

5053
let { path: rulePath, severity, options, ruleId } = rule
5154

@@ -140,8 +143,8 @@ export async function createESLintInstance(
140143

141144
return new FlatESLint({
142145
ruleFilter: ({ ruleId: currentRuleId }) => currentRuleId === uniqueRuleId,
146+
overrideConfigFile: eslintConfigFile ?? null,
143147
overrideConfig: [flatConfig],
144-
overrideConfigFile: null,
145148
allowInlineConfig: false,
146149
fix: true,
147150
})

runners/run-benchmarks-from-config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ interface RunBenchmarksFromConfigParameters {
3333
/** The user-defined benchmark configuration. */
3434
userConfig: UserBenchmarkConfig
3535

36+
/** Optional path to custom ESLint config file. */
37+
eslintConfigFile?: string
38+
3639
/** User configuration directory path */
3740
configDirectory: string
3841
}
@@ -89,7 +92,8 @@ interface RunBenchmarksFromConfigParameters {
8992
export async function runBenchmarksFromConfig(
9093
parameters: RunBenchmarksFromConfigParameters,
9194
): Promise<void> {
92-
let { reporterOptions, configDirectory, userConfig } = parameters
95+
let { eslintConfigFile, reporterOptions, configDirectory, userConfig } =
96+
parameters
9397

9498
if (userConfig.tests.length === 0) {
9599
console.warn('User configuration contains no tests. Exiting.')
@@ -173,6 +177,7 @@ export async function runBenchmarksFromConfig(
173177
// eslint-disable-next-line no-await-in-loop
174178
await runBenchmark({
175179
config: specBenchmarkConfig,
180+
eslintConfigFile,
176181
configDirectory,
177182
testCases,
178183
})

test/core/eslint/create-eslint-instance.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,19 @@ describe('createESLintInstance', () => {
483483

484484
expect(config.rules).toBeDefined()
485485
})
486+
487+
it('sets custom config file when provided', async () => {
488+
constructorOptions = {}
489+
490+
await createESLintInstance({
491+
eslintConfigFile: '/path/to/custom/eslint.config.js',
492+
rule: { ruleId: 'test-rule', severity: 2 },
493+
configDirectory: temporaryDirectory,
494+
languages: ['javascript'],
495+
})
496+
497+
expect(constructorOptions['overrideConfigFile']).toBe(
498+
'/path/to/custom/eslint.config.js',
499+
)
500+
})
486501
})

0 commit comments

Comments
 (0)