Enable three unicorn rules — one correctness, two performance — and fix every existing violation repo-wide so the rules pass as errors. prefer-number-properties (76 sites) - parseInt/parseFloat/NaN -> Number.* : safe aliases (autofixed). - isNaN -> Number.isNaN (12 sites, hand-converted): global isNaN coerces its argument, Number.isNaN does not. Verified every call site already passes a number (Number.parseInt results, number-typed fields, Date.getTime()), so the conversion is behavior-preserving today and guards against a future non-numeric argument silently coercing. prefer-array-find (26 sites) - .filter(pred)[0] -> .find(pred); .filter(pred).at(-1) / .pop() -> .findLast(pred). Drops the intermediate array and short-circuits. prefer-array-index-of (5 sites) - .findIndex(x => x === v) -> .indexOf(v). Verified: typecheck (node/cli/web) clean, 53 affected suites pass (1679 tests), oxlint clean repo-wide. mobile/ uses findLast safely (already ships ES2023 .toReversed()); config scripts and e2e helpers run on Node 24.
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
export const DEFAULT_TERMINAL_FONT_WEIGHT = 500
|
|
export const TERMINAL_FONT_WEIGHT_MIN = 100
|
|
export const TERMINAL_FONT_WEIGHT_MAX = 900
|
|
export const TERMINAL_FONT_WEIGHT_STEP = 100
|
|
const DEFAULT_TERMINAL_FONT_WEIGHT_BOLD = 700
|
|
|
|
export function normalizeTerminalFontWeight(fontWeight: number | null | undefined): number {
|
|
const numericFontWeight = typeof fontWeight === 'number' ? fontWeight : Number.NaN
|
|
|
|
if (!Number.isFinite(numericFontWeight)) {
|
|
return DEFAULT_TERMINAL_FONT_WEIGHT
|
|
}
|
|
|
|
return Math.min(
|
|
TERMINAL_FONT_WEIGHT_MAX,
|
|
Math.max(TERMINAL_FONT_WEIGHT_MIN, Math.round(numericFontWeight))
|
|
)
|
|
}
|
|
|
|
export function resolveTerminalFontWeights(fontWeight: number | null | undefined): {
|
|
fontWeight: number
|
|
fontWeightBold: number
|
|
} {
|
|
const normalizedFontWeight = normalizeTerminalFontWeight(fontWeight)
|
|
|
|
return {
|
|
fontWeight: normalizedFontWeight,
|
|
fontWeightBold: Math.min(
|
|
TERMINAL_FONT_WEIGHT_MAX,
|
|
Math.max(DEFAULT_TERMINAL_FONT_WEIGHT_BOLD, normalizedFontWeight + 200)
|
|
)
|
|
}
|
|
}
|