Skip to content

Commit 9ec8fc4

Browse files
committed
chore: run formatter
1 parent 0886129 commit 9ec8fc4

File tree

7 files changed

+44
-42
lines changed

7 files changed

+44
-42
lines changed

lib/extractor/image.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class ImageName {
1212
digests: { manifest?: string; index?: string } = {},
1313
) {
1414
const parsed = parseImageReference(targetImage);
15-
this.name = parsed.registry ? parsed.registry + "/" + parsed.repository : parsed.repository;
15+
this.name = parsed.registry
16+
? parsed.registry + "/" + parsed.repository
17+
: parsed.repository;
1618

1719
// If the image name has a tag, use it. If the image name has
1820
// nether a tag nor a digest, use "latest".
@@ -27,8 +29,12 @@ class ImageName {
2729
}
2830

2931
// If the image name has a digest, and it's not the same as the manifest or index digest, add it as the unknown digest.
30-
if (parsed.digest && !this.digests.manifest?.equals(parsed.digest) && !this.digests.index?.equals(parsed.digest)) {
31-
this.digests.unknown = new ImageDigest(parsed.digest);
32+
if (
33+
parsed.digest &&
34+
!this.digests.manifest?.equals(parsed.digest) &&
35+
!this.digests.index?.equals(parsed.digest)
36+
) {
37+
this.digests.unknown = new ImageDigest(parsed.digest);
3238
}
3339
}
3440

lib/extractor/oci-distribution-metadata.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export function constructOCIDisributionMetadata({
3333
| undefined {
3434
try {
3535
const parsed = parseImageReference(imageName);
36-
// Normalize the hostname. Note this function uses slightly different logic from the one in the image-reference.ts file.
36+
// Extract the registry hostname, using "docker.io" as the default for Docker Hub images.
37+
// Note this is different from registryForPull, which defaults to "registry-1.docker.io" for Docker Hub images.
3738
const hostname = parsed.registry ? parsed.registry : "docker.io";
3839
const metadata: OCIDistributionMetadata = {
3940
registryHost: hostname,

lib/image-reference.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ const imageRegistryRegex = new RegExp(imageRegistryPattern);
1515

1616
export class ParsedImageReference {
1717
/** Repository path (e.g. nginx, library/nginx) */
18-
readonly repository: string;
18+
public readonly repository: string;
1919
/** Registry hostname (e.g. gcr.io, registry-1.docker.io); undefined if none */
20-
readonly registry?: string;
20+
public readonly registry?: string;
2121
/** Tag (e.g. latest, 1.23.0); undefined if only digest or neither */
22-
readonly tag?: string;
22+
public readonly tag?: string;
2323
/** Inline digest (e.g. sha256:abc...); undefined if not present */
24-
readonly digest?: string;
24+
public readonly digest?: string;
2525

2626
constructor(params: {
2727
repository: string;
@@ -39,7 +39,7 @@ export class ParsedImageReference {
3939
* Rebuilds the image reference string from repository, registry, tag, and digest.
4040
* Format: [registry/]repository[:tag][@digest]
4141
*/
42-
toString(): string {
42+
public toString(): string {
4343
let ref = "";
4444
if (this.registry) {
4545
ref += this.registry + "/";

lib/scan.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ import { DockerFileAnalysis } from "./dockerfile/types";
77
import { extractImageContent } from "./extractor";
88
import { ImageName } from "./extractor/image";
99
import { ExtractAction, ExtractionResult } from "./extractor/types";
10+
import {
11+
isValidImageReference,
12+
ParsedImageReference,
13+
parseImageReference,
14+
} from "./image-reference";
1015
import { fullImageSavePath } from "./image-save-path";
1116
import { getArchivePath, getImageType } from "./image-type";
1217
import { isNumber, isTrue } from "./option-utils";
1318
import * as staticModule from "./static";
1419
import { ImageType, PluginOptions, PluginResponse } from "./types";
15-
import { isValidImageReference, ParsedImageReference, parseImageReference } from "./image-reference";
1620

1721
// Registry credentials may also be provided by env vars. When both are set, flags take precedence.
1822
export function mergeEnvVarsIntoCredentials(
@@ -222,8 +226,10 @@ export function appendLatestTagIfMissing(targetImage: string): string {
222226
if (parsed.tag !== undefined || parsed.digest !== undefined) {
223227
return parsed.toString();
224228
}
225-
return parsed.toString() + ':latest';
226-
} catch { return targetImage; }
229+
return parsed.toString() + ":latest";
230+
} catch {
231+
return targetImage;
232+
}
227233
}
228234

229235
export async function extractContent(

test/lib/image-reference.spec.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
parseImageReference,
32
isValidImageReference,
43
ParsedImageReference,
4+
parseImageReference,
55
} from "../../lib/image-reference";
66

77
const validSha256 =
@@ -80,14 +80,14 @@ describe("image-reference", () => {
8080
});
8181

8282
it("parses localhost registry with port", () => {
83-
expect(
84-
parseImageReference("localhost:5000/foo/bar:tag"),
85-
).toMatchObject({
86-
repository: "foo/bar",
87-
registry: "localhost:5000",
88-
tag: "tag",
89-
digest: undefined,
90-
});
83+
expect(parseImageReference("localhost:5000/foo/bar:tag")).toMatchObject(
84+
{
85+
repository: "foo/bar",
86+
registry: "localhost:5000",
87+
tag: "tag",
88+
digest: undefined,
89+
},
90+
);
9191
});
9292

9393
it("parses docker.io style registry", () => {
@@ -122,9 +122,7 @@ describe("image-reference", () => {
122122
});
123123

124124
it("parses repository with dots and dashes", () => {
125-
expect(
126-
parseImageReference("my.repo/image-name:tag"),
127-
).toMatchObject({
125+
expect(parseImageReference("my.repo/image-name:tag")).toMatchObject({
128126
repository: "image-name",
129127
registry: "my.repo",
130128
tag: "tag",
@@ -133,9 +131,7 @@ describe("image-reference", () => {
133131
});
134132

135133
it("parses IPv6 registry", () => {
136-
expect(
137-
parseImageReference("[::1]:5000/foo/bar:latest"),
138-
).toMatchObject({
134+
expect(parseImageReference("[::1]:5000/foo/bar:latest")).toMatchObject({
139135
repository: "foo/bar",
140136
registry: "[::1]:5000",
141137
tag: "latest",
@@ -144,9 +140,7 @@ describe("image-reference", () => {
144140
});
145141

146142
it("parses tag with dots and dashes", () => {
147-
expect(
148-
parseImageReference("nginx:1.23.0-alpha"),
149-
).toMatchObject({
143+
expect(parseImageReference("nginx:1.23.0-alpha")).toMatchObject({
150144
repository: "nginx",
151145
registry: undefined,
152146
tag: "1.23.0-alpha",
@@ -191,9 +185,9 @@ describe("image-reference", () => {
191185
});
192186

193187
it("throws for invalid digest (too short)", () => {
194-
expect(() =>
195-
parseImageReference("nginx@sha256:abc"),
196-
).toThrow("invalid image reference format");
188+
expect(() => parseImageReference("nginx@sha256:abc")).toThrow(
189+
"invalid image reference format",
190+
);
197191
});
198192

199193
it("throws for malformed reference", () => {
@@ -339,4 +333,4 @@ describe("isValidImageReference", () => {
339333
},
340334
);
341335
});
342-
});
336+
});

test/lib/scan.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ describe("appendLatestTagIfMissing", () => {
107107
it("does not append latest if digest exists (digest-only reference)", () => {
108108
const imageWithDigest =
109109
"nginx@sha256:56ea7092e72db3e9f84d58d583370d59b842de02ea9e1f836c3f3afc7ce408c1";
110-
expect(appendLatestTagIfMissing(imageWithDigest)).toEqual(
111-
imageWithDigest,
112-
);
110+
expect(appendLatestTagIfMissing(imageWithDigest)).toEqual(imageWithDigest);
113111
});
114112

115113
it("does not append latest if both tag and digest exist", () => {
@@ -146,4 +144,4 @@ describe("appendLatestTagIfMissing", () => {
146144
const invalid = "/test:unknown";
147145
expect(appendLatestTagIfMissing(invalid)).toEqual(invalid);
148146
});
149-
});
147+
});

test/lib/utils.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
RESPONSE_SIZE_LIMITS,
3-
truncateAdditionalFacts,
4-
} from "../../lib/utils";
1+
import { RESPONSE_SIZE_LIMITS, truncateAdditionalFacts } from "../../lib/utils";
52

63
describe("truncateAdditionalFacts", () => {
74
describe("should handle edge cases", () => {

0 commit comments

Comments
 (0)