Skip to content

Commit

Permalink
in now type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Oct 7, 2022
1 parent 7e61c7d commit 1906391
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/modules/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export class DockerDatasource extends Datasource {
// OCI image lists are not required to specify a mediaType
if (
manifest.mediaType === MediaType.ociManifestIndexV1 ||
(!manifest.mediaType && hasKey('manifests', manifest))
(!manifest.mediaType && 'manifests' in manifest)
) {
if (manifest.manifests.length) {
logger.trace(
Expand All @@ -594,7 +594,7 @@ export class DockerDatasource extends Datasource {
// OCI manifests are not required to specify a mediaType
if (
(manifest.mediaType === MediaType.ociManifestV1 ||
(!manifest.mediaType && hasKey('config', manifest))) &&
(!manifest.mediaType && 'config' in manifest)) &&
is.string(manifest.config?.digest)
) {
return manifest.config?.digest;
Expand Down Expand Up @@ -1042,7 +1042,7 @@ export class DockerDatasource extends Datasource {
manifestList.schemaVersion === 2 &&
(manifestList.mediaType === MediaType.manifestListV2 ||
manifestList.mediaType === MediaType.ociManifestIndexV1 ||
(!manifestList.mediaType && hasKey('manifests', manifestList)))
(!manifestList.mediaType && 'manifests' in manifestList))
) {
for (const manifest of manifestList.manifests) {
if (manifest.platform['architecture'] === architecture) {
Expand Down
3 changes: 1 addition & 2 deletions lib/modules/platform/github/massage-markdown-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Content } from 'mdast';
import remark from 'remark';
import type { Plugin, Transformer } from 'unified';
import { logger } from '../../../logger';
import { hasKey } from '../../../util/object';
import { regEx } from '../../../util/regex';

interface UrlMatch {
Expand Down Expand Up @@ -44,7 +43,7 @@ function collectLinkPosition(input: string, matches: UrlMatch[]): Plugin {
const newUrl = massageLink(url);
matches.push({ start, end, replaceTo: `[${url}](${newUrl})` });
}
} else if (hasKey('children', tree)) {
} else if ('children' in tree) {
tree.children.forEach((child: Content) => {
transformer(child);
});
Expand Down
5 changes: 2 additions & 3 deletions lib/util/http/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,8 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
});
const repositoryData = res?.data?.repository;
if (
repositoryData &&
is.plainObject(repositoryData) &&
repositoryData[fieldName]
is.nonEmptyObject(repositoryData) &&
!is.nullOrUndefined(repositoryData[fieldName])
) {
optimalCount = count;

Expand Down
2 changes: 1 addition & 1 deletion lib/util/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function hasKey<K extends string, T>(
k: K,
o: T
): o is T & Record<K, unknown> {
return typeof o === 'object' && k in o;
return o && typeof o === 'object' && k in o;
}

0 comments on commit 1906391

Please sign in to comment.