Files
Sebastian Poxhofer 64e6a4c71f refactor(oxlint): enable unicorn/prefer-at (#44556)
Enable the unicorn/prefer-at rule as error in .oxlintrc.json and fix all
43 pre-existing violations (arr[arr.length - 1] -> arr.at(-1)) via oxlint
autofix. Where .at() widened the type to T | undefined, non-null
assertions were added at sites where surrounding logic guarantees the
element exists (length guards, split results), preserving the original
runtime behavior and typing.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 12:57:23 +00:00

46 lines
1.5 KiB
TypeScript

import { isEmptyObject, isString } from '@sindresorhus/is';
import type { PackageDependency } from '../../../types.ts';
import type { NpmManagerData } from '../../types.ts';
import { extractDependency } from './dependency.ts';
import { setNodeCommitTopic } from './node.ts';
/**
* Used when there is a json object as a value in overrides block.
* @param parents
* @param child
* @returns PackageDependency array
*/
export function extractOverrideDepsRec(
parents: string[],
child: NpmManagerData,
): PackageDependency[] {
const deps: PackageDependency[] = [];
if (!child || isEmptyObject(child)) {
return deps;
}
for (const [overrideName, versionValue] of Object.entries(child)) {
if (isString(versionValue)) {
// special handling for "." override dependency name
// "." means the constraint is applied to the parent dep
const currDepName = overrideName === '.' ? parents.at(-1)! : overrideName;
const dep: PackageDependency<NpmManagerData> = {
depName: currDepName,
depType: 'overrides',
managerData: { parents: parents.slice() }, // set parents for dependency
};
setNodeCommitTopic(dep);
deps.push({
...dep,
...extractDependency('overrides', currDepName, versionValue),
});
} else {
// versionValue is an object, run recursively.
parents.push(overrideName);
const depsOfObject = extractOverrideDepsRec(parents, versionValue);
deps.push(...depsOfObject);
}
}
parents.pop();
return deps;
}