Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Enable strict null checks for lookup-related functionality #15848

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ export interface PackageRuleInputConfig extends Record<string, unknown> {
lockedVersion?: string;
updateType?: UpdateType;
isBump?: boolean;
sourceUrl?: string;
sourceUrl?: string | null;
language?: string;
baseBranch?: string;
manager?: string;
manager?: string | null;
datasource?: string;
packageRules?: (PackageRule & PackageRuleInputConfig)[];
}
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface RangeConfig<T = Record<string, any>> extends ManagerData<T> {
currentValue?: string;
depName?: string;
depType?: string;
manager?: string;
manager?: string | null;
packageJsonType?: 'app' | 'library';
rangeStrategy: RangeStrategy;
}
Expand Down Expand Up @@ -145,6 +145,9 @@ export interface LookupUpdate {
newVersion?: string;
updateType?: UpdateType;
userStrings?: Record<string, string>;
checksumUrl?: string;
downloadUrl?: string;
releaseTimestamp?: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any? really ? 😕

}

export interface PackageDependency<T = Record<string, any>> extends Package<T> {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/lookup/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function getBucket(
currentVersion: string,
newVersion: string,
versioning: VersioningApi
): string {
): string | null {
const { separateMajorMinor, separateMultipleMajor, separateMinorPatch } =
config;
if (!separateMajorMinor) {
Expand Down
28 changes: 18 additions & 10 deletions lib/workers/repository/process/lookup/filter-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function filterInternalChecks(
sortedReleases: Release[]
): Promise<InternalChecksResult> {
const { currentVersion, datasource, depName, internalChecksFilter } = config;
let release: Release;
let release: Release | undefined = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let release: Release | undefined = undefined;
let release: Release | undefined;

undefined is default value

let pendingChecks = false;
let pendingReleases: Release[] = [];
if (internalChecksFilter === 'none') {
Expand All @@ -41,12 +41,13 @@ export async function filterInternalChecks(
releaseConfig.updateType = getUpdateType(
releaseConfig,
versioning,
currentVersion,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
currentVersion!,
candidateRelease.version
);
releaseConfig = mergeChildConfig(
releaseConfig,
releaseConfig[releaseConfig.updateType]
releaseConfig[releaseConfig.updateType]!
);
// Apply packageRules in case any apply to updateType
releaseConfig = applyPackageRules(releaseConfig);
Expand All @@ -69,15 +70,21 @@ export async function filterInternalChecks(
continue;
}
}
if (isActiveConfidenceLevel(minimumConfidence)) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
if (isActiveConfidenceLevel(minimumConfidence!)) {
const confidenceLevel = await getMergeConfidenceLevel(
datasource,
depName,
currentVersion,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
datasource!,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
depName!,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
currentVersion!,
newVersion,
updateType
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
updateType!
);
if (!satisfiesConfidenceLevel(confidenceLevel, minimumConfidence)) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
if (!satisfiesConfidenceLevel(confidenceLevel, minimumConfidence!)) {
logger.debug(
{ depName, check: 'minimumConfidence' },
`Release ${candidateRelease.version} is pending status checks`
Expand Down Expand Up @@ -106,5 +113,6 @@ export async function filterInternalChecks(
}
}
}
return { release, pendingChecks, pendingReleases };
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return { release: release!, pendingChecks, pendingReleases };
}
5 changes: 3 additions & 2 deletions lib/workers/repository/process/lookup/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export function filterVersions(
const versionRelease = releases.find(
(release) => release.version === v.version
);
if (versionRelease.isDeprecated) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
if (versionRelease!.isDeprecated) {
logger.trace(
`Skipping ${config.depName}@${v.version} because it is deprecated`
);
Expand Down Expand Up @@ -79,7 +80,7 @@ export function filterVersions(
'Falling back to npm semver syntax for allowedVersions'
);
filteredVersions = filteredVersions.filter((v) =>
semver.satisfies(semver.coerce(v.version), allowedVersions)
semver.satisfies(semver.coerce(v.version)!, allowedVersions)
);
} else if (
config.versioning === poetryVersioning.id &&
Expand Down
42 changes: 25 additions & 17 deletions lib/workers/repository/process/lookup/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ export function generateUpdate(
const update: LookupUpdate = {
bucket,
newVersion,
newValue: null,
newValue: null!,
viceice marked this conversation as resolved.
Show resolved Hide resolved
};
const releaseFields = [
'checksumUrl',
'downloadUrl',
'newDigest',
'releaseTimestamp',
];
for (const field of releaseFields) {
if (release[field] !== undefined) {
update[field] = release[field];
}

// istanbul ignore if
if (release.checksumUrl !== undefined) {
update.checksumUrl = release.checksumUrl;
}
// istanbul ignore if
if (release.downloadUrl !== undefined) {
update.downloadUrl = release.downloadUrl;
}
// istanbul ignore if
if (release.newDigest !== undefined) {
update.newDigest = release.newDigest;
}
// istanbul ignore if
if (release.releaseTimestamp !== undefined) {
update.releaseTimestamp = release.releaseTimestamp;
}

const { currentValue } = config;
if (currentValue) {
try {
Expand All @@ -39,7 +46,7 @@ export function generateUpdate(
rangeStrategy,
currentVersion,
newVersion,
});
})!;
} catch (err) /* istanbul ignore next */ {
logger.warn(
{ err, currentValue, rangeStrategy, currentVersion, newVersion },
Expand All @@ -48,14 +55,14 @@ export function generateUpdate(
update.newValue = currentValue;
}
} else {
update.newValue = currentValue;
update.newValue = currentValue!;
}
update.newMajor = versioning.getMajor(newVersion);
update.newMinor = versioning.getMinor(newVersion);
update.newMajor = versioning.getMajor(newVersion)!;
update.newMinor = versioning.getMinor(newVersion)!;
// istanbul ignore if
if (!update.updateType && !currentVersion) {
logger.debug({ update }, 'Update has no currentVersion');
update.newValue = currentValue;
update.newValue = currentValue!;
return update;
}
update.updateType =
Expand All @@ -69,7 +76,8 @@ export function generateUpdate(
}
if (
rangeStrategy === 'bump' &&
versioning.matches(newVersion, currentValue)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
versioning.matches(newVersion, currentValue!)
) {
update.isBump = true;
}
Expand Down