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([
'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 { setCurrentScenarios } from './describe.js'
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 { groupRows, printComparison } from './compare.js'
import { readSnapshot, resolveCompareTarget } from './snapshot.js'
......@@ -131,14 +131,14 @@ async function runRunSubcommand(argv: string[]): Promise<void> {
setCurrentScenarios(null)
const cliIface = {
filterScenarios: async (scenarios: Scenario[]) => {
filterScenarios: async (allScenarios: Scenario[]) => {
if (args.scenario) {
const filter = [].concat(args.scenario)
return scenarios.filter((s) =>
filter.some((filter) => s.name.includes(filter))
const filters = [].concat(args.scenario)
return allScenarios.filter((s) =>
filters.some((filter) => s.name.includes(filter))
)
}
return scenarios
return allScenarios
},
filterScenarioVariants: async (variants: ScenarioVariant[]) => {
const propEntries = Object.entries(args).filter(
......
import picocolors from 'picocolors'
import { SnapshotRow } from './snapshot.js'
import type { SnapshotRow } from './snapshot.js'
import { mannWhitneyU, quantile } from './statistics.js'
import { formatUnit } from './units.js'
......
......@@ -27,17 +27,17 @@ export async function waitForFile(
}
elements.reverse()
try {
for (const path of elements) {
for (const element of elements) {
const checkAccess = () =>
access(path, constants.F_OK)
access(element, constants.F_OK)
.then(() => true)
.catch(() => false)
if (!(await checkAccess())) {
let resolveCheckAgain = () => {}
const watcher = watch(dirname(path), () => {
const watcher = watch(dirname(element), () => {
resolveCheckAgain()
})
currentAction = `waiting for ${path}`
currentAction = `waiting for ${element}`
let checkAgainPromise = new Promise<void>((resolve) => {
resolveCheckAgain = resolve
})
......
import { Interface } from '../index.js'
import { SampleGroup, groupRows, makeKey, printComparison } from '../compare.js'
import type { Interface } from '../index.js'
import {
type SampleGroup,
groupRows,
makeKey,
printComparison,
} from '../compare.js'
import { readSnapshot } from '../snapshot.js'
import { formatVariantProps } from '../utils.js'
......
import { Interface } from '../index.js'
import type { Interface } from '../index.js'
export default function compose(...ifaces: Interface[]): Interface {
const allKeys = new Set<keyof Interface>()
......
import picocolors from 'picocolors'
import { Interface } from '../index.js'
import type { Interface } from '../index.js'
import { formatUnit } from '../units.js'
import { formatVariant } from '../utils.js'
......
......@@ -71,10 +71,10 @@ export default function createInterface({
type: 'distribution',
host,
tags: Object.entries(props)
.filter(([, value]) => value !== null)
.filter(([, propValue]) => propValue !== null)
.map(
([key, value]) =>
`${toIdentifier(key)}:${toIdentifier(value!.toString())}`
([key, propValue]) =>
`${toIdentifier(key)}:${toIdentifier(propValue!.toString())}`
)
.concat(commonTags),
points: [[ts, [value]]],
......
import { Interface } from '../index.js'
import type { Interface } from '../index.js'
import inquirer from 'inquirer'
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 { formatUnit } from '../units.js'
import { writeFile } from 'fs/promises'
......@@ -17,11 +17,11 @@ function filterProp(
export default function createInterface(
file: string = (() => {
const file = process.env.JSON_OUTPUT_FILE
if (!file) {
const fromEnv = process.env.JSON_OUTPUT_FILE
if (!fromEnv) {
throw new Error('env var JSON_OUTPUT_FILE is not set')
}
return file
return fromEnv
})(),
options: { n?: number } = {}
): Interface {
......
import { execFile } from 'node:child_process'
import { promisify } from 'node:util'
import picocolors from 'picocolors'
import { Interface } from '../index.js'
import { SnapshotRow, defaultSnapshotPath, writeSnapshot } from '../snapshot.js'
import type { Interface } from '../index.js'
import {
type SnapshotRow,
defaultSnapshotPath,
writeSnapshot,
} from '../snapshot.js'
import { formatVariantProps } from '../utils.js'
const execFileAsync = promisify(execFile)
......
import { withCurrent } from './describe.js'
import {
import type {
FullInterface,
Interface,
Scenario,
VariantStatistic,
intoFullInterface,
} from './index.js'
import { intoFullInterface } from './index.js'
import { summary } from './statistics.js'
import { formatVariant } from './utils.js'
......@@ -44,12 +44,12 @@ export async function runScenarios(
let variants = []
for (const scenario of scenarios) {
let props = [{}]
for (const [key, options] of Object.entries(scenario.config)) {
for (const [key, values] of Object.entries(scenario.config)) {
const newProps = []
for (const prop of props) {
if (prop === 'scenario' || prop === '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({
...prop,
[key]: value,
......@@ -59,9 +59,9 @@ export async function runScenarios(
props = newProps
}
variants.push(
...props.map((props) => ({
...props.map((variantProps) => ({
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 treeKill from 'tree-kill'
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 {
ok(): Promise<void>
......@@ -183,21 +185,21 @@ class CommandImpl {
}
export function command(
command: string,
executable: string,
args: string[],
options: {
env?: Record<string, string>
cwd?: string
} = {}
): Command {
const process = spawn(command, args, {
const process = spawn(executable, args, {
shell: true,
...options,
stdio: ['ignore', 'pipe', 'pipe'],
})
if (shellOutput) {
console.log(
`[SHELL] ${command} ${args.join(' ')} ${JSON.stringify(options)}`
`[SHELL] ${executable} ${args.join(' ')} ${JSON.stringify(options)}`
)
}
return new CommandImpl(process)
......
......@@ -22,20 +22,20 @@ import minimist from 'minimist'
let data = JSON.parse(await readFile(args._[0], 'utf-8')) as any[]
const getValue = (
data: any,
entry: any,
name: string | string[],
includeKey: boolean
): string => {
if (name === 'value') {
return data.text as string
return entry.text as string
}
if (Array.isArray(name)) {
return name
.map((n) => getValue(data, n, true))
.map((n) => getValue(entry, n, true))
.filter((x) => x)
.join(' ')
}
const value = data.key[name]
const value = entry.key[name]
if (value === undefined) return ''
if (value === true) return includeKey ? name : 'true'
if (value === false) return includeKey ? '' : 'false'
......@@ -61,10 +61,10 @@ import minimist from 'minimist'
return
}
const row = args.row || 'name'
const column = args.column || 'scenario'
const getRow = (data: any) => getValue(data, row, false)
const getColumn = (data: any) => getValue(data, column, false)
const rowKey = args.row || 'name'
const columnKey = args.column || 'scenario'
const getRow = (entry: any) => getValue(entry, rowKey, false)
const getColumn = (entry: any) => getValue(entry, columnKey, false)
const allRows = new Set(data.map(getRow))
const allColumns = new Set(data.map(getColumn))
......@@ -77,7 +77,7 @@ import minimist from 'minimist'
for (const column of allColumns) {
let items = data
.filter((d: any) => getRow(d) === row && getColumn(d) === column)
.map((i) => i.text)
.map((item) => item.text)
rowData.push(items.join(', '))
columnSizes[i] = Math.max(columnSizes[i], rowData[i].length)
i++
......@@ -93,34 +93,34 @@ import minimist from 'minimist'
// Header
{
let row = '| '
let sepRow = '|:'
row += ' '.repeat(firstColumnSize)
sepRow += '-'.repeat(firstColumnSize)
let line = '| '
let sepLine = '|:'
line += ' '.repeat(firstColumnSize)
sepLine += '-'.repeat(firstColumnSize)
const allColumnsArray = [...allColumns]
for (let i = 0; i < columnSizes.length; i++) {
row += ' | '
row += pad(allColumnsArray[i], columnSizes[i])
sepRow += ':|-'
sepRow += '-'.repeat(columnSizes[i])
line += ' | '
line += pad(allColumnsArray[i], columnSizes[i])
sepLine += ':|-'
sepLine += '-'.repeat(columnSizes[i])
}
row += ' |'
sepRow += ':|'
console.log(row)
console.log(sepRow)
line += ' |'
sepLine += ':|'
console.log(line)
console.log(sepLine)
}
// Separator
let r = 0
for (const rowName of allRows) {
let row = '| '
row += pad(rowName, firstColumnSize)
let line = '| '
line += pad(rowName, firstColumnSize)
for (let i = 0; i < columnSizes.length; i++) {
row += ' | '
row += pad(table[r][i], columnSizes[i])
line += ' | '
line += pad(table[r][i], columnSizes[i])
}
row += ' |'
console.log(row)
line += ' |'
console.log(line)
r++
}
})().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