Unverified Commit 007058ef authored by Will Binns-Smith's avatar Will Binns-Smith Committed by GitHub

Lint devlow-bench with the root eslint config (#96871)

Follow-up to #96860, addressing @lukesandberg's review.

That PR moved `devlow-bench` into `packages/`, where the root eslint
config applies for the first time, and exempted the package from the
three rules it didn't satisfy rather than fixing the violations.

This drops the exemption block:

- **`import/no-extraneous-dependencies`** — had no violations. The
exemption was unnecessary.
- **`@typescript-eslint/consistent-type-imports`** — 13 violations, all
autofixable.
- **`@typescript-eslint/no-shadow`** — 17 violations, renamed by hand.

The shadow fixes are mostly loop variables and callback parameters that
restated their outer binding. Two worth a look:

- `table.ts` — `getValue(data, ...)` took a single entry but shadowed
the `data` array it indexes into. Renamed the parameter to `entry`, and
the `row`/`column` grouping keys to `rowKey`/`columnKey` so the loop
variables can keep the shorter names.
- `shell.ts` — `command(command, args)` shadowed the exported function
with its own first parameter. Renamed to `executable`, which also fixes
the `[SHELL]` debug log that was interpolating the function rather than
the argument.

## Verification

- `eslint` clean under both the root config and the package's own `lint`
script
- `tsc` compiles, `pnpm run --filter=devlow-bench test` 3/3
- prettier clean

<!-- NEXT_JS_LLM -->

---------
Co-authored-by: 's avatarLuke Sandberg <lukesandberg@users.noreply.github.com>
parent 286169a9
...@@ -601,15 +601,4 @@ export default defineConfig([ ...@@ -601,15 +601,4 @@ export default defineConfig([
'no-console': 'off', 'no-console': 'off',
}, },
}, },
{
// Moved from turbopack/, where the root config never applied. Exempted from
// the rules it doesn't currently satisfy rather than reformatting it as
// part of the move.
files: ['packages/devlow-bench/**'],
rules: {
'@typescript-eslint/no-shadow': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'import/no-extraneous-dependencies': 'off',
},
},
]) ])
import minimist from 'minimist' import minimist from 'minimist'
import { setCurrentScenarios } from './describe.js' import { setCurrentScenarios } from './describe.js'
import { join } from 'path' import { join } from 'path'
import { Scenario, ScenarioVariant, runScenarios } from './index.js' import { type Scenario, type ScenarioVariant, runScenarios } from './index.js'
import compose from './interfaces/compose.js' import compose from './interfaces/compose.js'
import { groupRows, printComparison } from './compare.js' import { groupRows, printComparison } from './compare.js'
import { readSnapshot, resolveCompareTarget } from './snapshot.js' import { readSnapshot, resolveCompareTarget } from './snapshot.js'
...@@ -131,14 +131,14 @@ async function runRunSubcommand(argv: string[]): Promise<void> { ...@@ -131,14 +131,14 @@ async function runRunSubcommand(argv: string[]): Promise<void> {
setCurrentScenarios(null) setCurrentScenarios(null)
const cliIface = { const cliIface = {
filterScenarios: async (scenarios: Scenario[]) => { filterScenarios: async (allScenarios: Scenario[]) => {
if (args.scenario) { if (args.scenario) {
const filter = [].concat(args.scenario) const filters = [].concat(args.scenario)
return scenarios.filter((s) => return allScenarios.filter((s) =>
filter.some((filter) => s.name.includes(filter)) filters.some((filter) => s.name.includes(filter))
) )
} }
return scenarios return allScenarios
}, },
filterScenarioVariants: async (variants: ScenarioVariant[]) => { filterScenarioVariants: async (variants: ScenarioVariant[]) => {
const propEntries = Object.entries(args).filter( const propEntries = Object.entries(args).filter(
......
import picocolors from 'picocolors' import picocolors from 'picocolors'
import { SnapshotRow } from './snapshot.js' import type { SnapshotRow } from './snapshot.js'
import { mannWhitneyU, quantile } from './statistics.js' import { mannWhitneyU, quantile } from './statistics.js'
import { formatUnit } from './units.js' import { formatUnit } from './units.js'
......
...@@ -27,17 +27,17 @@ export async function waitForFile( ...@@ -27,17 +27,17 @@ export async function waitForFile(
} }
elements.reverse() elements.reverse()
try { try {
for (const path of elements) { for (const element of elements) {
const checkAccess = () => const checkAccess = () =>
access(path, constants.F_OK) access(element, constants.F_OK)
.then(() => true) .then(() => true)
.catch(() => false) .catch(() => false)
if (!(await checkAccess())) { if (!(await checkAccess())) {
let resolveCheckAgain = () => {} let resolveCheckAgain = () => {}
const watcher = watch(dirname(path), () => { const watcher = watch(dirname(element), () => {
resolveCheckAgain() resolveCheckAgain()
}) })
currentAction = `waiting for ${path}` currentAction = `waiting for ${element}`
let checkAgainPromise = new Promise<void>((resolve) => { let checkAgainPromise = new Promise<void>((resolve) => {
resolveCheckAgain = resolve resolveCheckAgain = resolve
}) })
......
import { Interface } from '../index.js' import type { Interface } from '../index.js'
import { SampleGroup, groupRows, makeKey, printComparison } from '../compare.js' import {
type SampleGroup,
groupRows,
makeKey,
printComparison,
} from '../compare.js'
import { readSnapshot } from '../snapshot.js' import { readSnapshot } from '../snapshot.js'
import { formatVariantProps } from '../utils.js' import { formatVariantProps } from '../utils.js'
......
import { Interface } from '../index.js' import type { Interface } from '../index.js'
export default function compose(...ifaces: Interface[]): Interface { export default function compose(...ifaces: Interface[]): Interface {
const allKeys = new Set<keyof Interface>() const allKeys = new Set<keyof Interface>()
......
import picocolors from 'picocolors' import picocolors from 'picocolors'
import { Interface } from '../index.js' import type { Interface } from '../index.js'
import { formatUnit } from '../units.js' import { formatUnit } from '../units.js'
import { formatVariant } from '../utils.js' import { formatVariant } from '../utils.js'
......
...@@ -71,10 +71,10 @@ export default function createInterface({ ...@@ -71,10 +71,10 @@ export default function createInterface({
type: 'distribution', type: 'distribution',
host, host,
tags: Object.entries(props) tags: Object.entries(props)
.filter(([, value]) => value !== null) .filter(([, propValue]) => propValue !== null)
.map( .map(
([key, value]) => ([key, propValue]) =>
`${toIdentifier(key)}:${toIdentifier(value!.toString())}` `${toIdentifier(key)}:${toIdentifier(propValue!.toString())}`
) )
.concat(commonTags), .concat(commonTags),
points: [[ts, [value]]], points: [[ts, [value]]],
......
import { Interface } from '../index.js' import type { Interface } from '../index.js'
import inquirer from 'inquirer' import inquirer from 'inquirer'
import { formatVariant } from '../utils.js' import { formatVariant } from '../utils.js'
......
import { Interface } from '../index.js' import type { Interface } from '../index.js'
import { quantile, mean as statsMean } from '../statistics.js' import { quantile, mean as statsMean } from '../statistics.js'
import { formatUnit } from '../units.js' import { formatUnit } from '../units.js'
import { writeFile } from 'fs/promises' import { writeFile } from 'fs/promises'
...@@ -17,11 +17,11 @@ function filterProp( ...@@ -17,11 +17,11 @@ function filterProp(
export default function createInterface( export default function createInterface(
file: string = (() => { file: string = (() => {
const file = process.env.JSON_OUTPUT_FILE const fromEnv = process.env.JSON_OUTPUT_FILE
if (!file) { if (!fromEnv) {
throw new Error('env var JSON_OUTPUT_FILE is not set') throw new Error('env var JSON_OUTPUT_FILE is not set')
} }
return file return fromEnv
})(), })(),
options: { n?: number } = {} options: { n?: number } = {}
): Interface { ): Interface {
......
import { execFile } from 'node:child_process' import { execFile } from 'node:child_process'
import { promisify } from 'node:util' import { promisify } from 'node:util'
import picocolors from 'picocolors' import picocolors from 'picocolors'
import { Interface } from '../index.js' import type { Interface } from '../index.js'
import { SnapshotRow, defaultSnapshotPath, writeSnapshot } from '../snapshot.js' import {
type SnapshotRow,
defaultSnapshotPath,
writeSnapshot,
} from '../snapshot.js'
import { formatVariantProps } from '../utils.js' import { formatVariantProps } from '../utils.js'
const execFileAsync = promisify(execFile) const execFileAsync = promisify(execFile)
......
import { withCurrent } from './describe.js' import { withCurrent } from './describe.js'
import { import type {
FullInterface, FullInterface,
Interface, Interface,
Scenario, Scenario,
VariantStatistic, VariantStatistic,
intoFullInterface,
} from './index.js' } from './index.js'
import { intoFullInterface } from './index.js'
import { summary } from './statistics.js' import { summary } from './statistics.js'
import { formatVariant } from './utils.js' import { formatVariant } from './utils.js'
...@@ -44,12 +44,12 @@ export async function runScenarios( ...@@ -44,12 +44,12 @@ export async function runScenarios(
let variants = [] let variants = []
for (const scenario of scenarios) { for (const scenario of scenarios) {
let props = [{}] let props = [{}]
for (const [key, options] of Object.entries(scenario.config)) { for (const [key, values] of Object.entries(scenario.config)) {
const newProps = [] const newProps = []
for (const prop of props) { for (const prop of props) {
if (prop === 'scenario' || prop === 'name') if (prop === 'scenario' || prop === 'name')
throw new Error("Cannot use 'scenario' or 'name' as a property name") throw new Error("Cannot use 'scenario' or 'name' as a property name")
for (const value of options) { for (const value of values) {
newProps.push({ newProps.push({
...prop, ...prop,
[key]: value, [key]: value,
...@@ -59,9 +59,9 @@ export async function runScenarios( ...@@ -59,9 +59,9 @@ export async function runScenarios(
props = newProps props = newProps
} }
variants.push( variants.push(
...props.map((props) => ({ ...props.map((variantProps) => ({
scenario, scenario,
props, props: variantProps,
})) }))
) )
} }
......
import { ChildProcess, spawn } from 'child_process' import type { ChildProcess } from 'child_process'
import { spawn } from 'child_process'
import split2 from 'split2' import split2 from 'split2'
import treeKill from 'tree-kill' import treeKill from 'tree-kill'
import pidusage from 'pidusage-tree' import pidusage from 'pidusage-tree'
import { PREVIOUS, reportMeasurement } from './describe.js' import type { PREVIOUS } from './describe.js'
import { reportMeasurement } from './describe.js'
export interface Command { export interface Command {
ok(): Promise<void> ok(): Promise<void>
...@@ -183,21 +185,21 @@ class CommandImpl { ...@@ -183,21 +185,21 @@ class CommandImpl {
} }
export function command( export function command(
command: string, executable: string,
args: string[], args: string[],
options: { options: {
env?: Record<string, string> env?: Record<string, string>
cwd?: string cwd?: string
} = {} } = {}
): Command { ): Command {
const process = spawn(command, args, { const process = spawn(executable, args, {
shell: true, shell: true,
...options, ...options,
stdio: ['ignore', 'pipe', 'pipe'], stdio: ['ignore', 'pipe', 'pipe'],
}) })
if (shellOutput) { if (shellOutput) {
console.log( console.log(
`[SHELL] ${command} ${args.join(' ')} ${JSON.stringify(options)}` `[SHELL] ${executable} ${args.join(' ')} ${JSON.stringify(options)}`
) )
} }
return new CommandImpl(process) return new CommandImpl(process)
......
...@@ -22,20 +22,20 @@ import minimist from 'minimist' ...@@ -22,20 +22,20 @@ import minimist from 'minimist'
let data = JSON.parse(await readFile(args._[0], 'utf-8')) as any[] let data = JSON.parse(await readFile(args._[0], 'utf-8')) as any[]
const getValue = ( const getValue = (
data: any, entry: any,
name: string | string[], name: string | string[],
includeKey: boolean includeKey: boolean
): string => { ): string => {
if (name === 'value') { if (name === 'value') {
return data.text as string return entry.text as string
} }
if (Array.isArray(name)) { if (Array.isArray(name)) {
return name return name
.map((n) => getValue(data, n, true)) .map((n) => getValue(entry, n, true))
.filter((x) => x) .filter((x) => x)
.join(' ') .join(' ')
} }
const value = data.key[name] const value = entry.key[name]
if (value === undefined) return '' if (value === undefined) return ''
if (value === true) return includeKey ? name : 'true' if (value === true) return includeKey ? name : 'true'
if (value === false) return includeKey ? '' : 'false' if (value === false) return includeKey ? '' : 'false'
...@@ -61,10 +61,10 @@ import minimist from 'minimist' ...@@ -61,10 +61,10 @@ import minimist from 'minimist'
return return
} }
const row = args.row || 'name' const rowKey = args.row || 'name'
const column = args.column || 'scenario' const columnKey = args.column || 'scenario'
const getRow = (data: any) => getValue(data, row, false) const getRow = (entry: any) => getValue(entry, rowKey, false)
const getColumn = (data: any) => getValue(data, column, false) const getColumn = (entry: any) => getValue(entry, columnKey, false)
const allRows = new Set(data.map(getRow)) const allRows = new Set(data.map(getRow))
const allColumns = new Set(data.map(getColumn)) const allColumns = new Set(data.map(getColumn))
...@@ -77,7 +77,7 @@ import minimist from 'minimist' ...@@ -77,7 +77,7 @@ import minimist from 'minimist'
for (const column of allColumns) { for (const column of allColumns) {
let items = data let items = data
.filter((d: any) => getRow(d) === row && getColumn(d) === column) .filter((d: any) => getRow(d) === row && getColumn(d) === column)
.map((i) => i.text) .map((item) => item.text)
rowData.push(items.join(', ')) rowData.push(items.join(', '))
columnSizes[i] = Math.max(columnSizes[i], rowData[i].length) columnSizes[i] = Math.max(columnSizes[i], rowData[i].length)
i++ i++
...@@ -93,34 +93,34 @@ import minimist from 'minimist' ...@@ -93,34 +93,34 @@ import minimist from 'minimist'
// Header // Header
{ {
let row = '| ' let line = '| '
let sepRow = '|:' let sepLine = '|:'
row += ' '.repeat(firstColumnSize) line += ' '.repeat(firstColumnSize)
sepRow += '-'.repeat(firstColumnSize) sepLine += '-'.repeat(firstColumnSize)
const allColumnsArray = [...allColumns] const allColumnsArray = [...allColumns]
for (let i = 0; i < columnSizes.length; i++) { for (let i = 0; i < columnSizes.length; i++) {
row += ' | ' line += ' | '
row += pad(allColumnsArray[i], columnSizes[i]) line += pad(allColumnsArray[i], columnSizes[i])
sepRow += ':|-' sepLine += ':|-'
sepRow += '-'.repeat(columnSizes[i]) sepLine += '-'.repeat(columnSizes[i])
} }
row += ' |' line += ' |'
sepRow += ':|' sepLine += ':|'
console.log(row) console.log(line)
console.log(sepRow) console.log(sepLine)
} }
// Separator // Separator
let r = 0 let r = 0
for (const rowName of allRows) { for (const rowName of allRows) {
let row = '| ' let line = '| '
row += pad(rowName, firstColumnSize) line += pad(rowName, firstColumnSize)
for (let i = 0; i < columnSizes.length; i++) { for (let i = 0; i < columnSizes.length; i++) {
row += ' | ' line += ' | '
row += pad(table[r][i], columnSizes[i]) line += pad(table[r][i], columnSizes[i])
} }
row += ' |' line += ' |'
console.log(row) console.log(line)
r++ r++
} }
})().catch((e) => { })().catch((e) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment