Skip to content

Commit

Permalink
refactor: Enable strict null checks for lookup-related functionality (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jun 2, 2022
1 parent 8229580 commit 5495ab6
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 86 deletions.
4 changes: 2 additions & 2 deletions lib/config/types.ts
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
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;
}

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
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
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;
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
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
Expand Up @@ -18,19 +18,26 @@ export function generateUpdate(
const update: LookupUpdate = {
bucket,
newVersion,
newValue: null,
newValue: null!,
};
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

0 comments on commit 5495ab6

Please sign in to comment.