Files
renovate/lib/config/migrations/custom/node-migration.ts
Sebastian Poxhofer c32e2391a0 refactor(linters): add prefer-coerce-object rule (#45493)
Refs #45216

The object counterpart to `prefer-coerce-array`: `x ?? {}` becomes
`coerceObject(x)`. The rule flags a `??` whose default is a bare `{}`
literal, so a populated default or an asserted `({} as Foo)` still
passes; a `x ?? y ?? {}` chain maps onto `coerceObject(x, y)`.

Every hit across `lib/` converted cleanly, so no disable comments were
needed.
2026-08-28 09:27:59 +00:00

25 lines
762 B
TypeScript

import { coerceObject } from '../../../util/object.ts';
import type { RenovateConfig } from '../../types.ts';
import { AbstractMigration } from '../base/abstract-migration.ts';
export class NodeMigration extends AbstractMigration {
override readonly propertyName = 'node';
override run(value: unknown): void {
const node = this.get('node')!;
// v8 ignore else -- TODO: add test #40625
if ((value as RenovateConfig).enabled === true) {
// validated non-null
delete node.enabled;
const travis = coerceObject(this.get('travis'));
travis.enabled = true;
if (Object.keys(node).length) {
this.rewrite(node);
} else {
this.delete('node');
}
this.setSafely('travis', travis);
}
}
}