diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ecf3e..ceae34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## [Unreleased] +### Added +- support parsing the new `--checksum` flag for ADD instructions ([#116](https://github.com/rcjsuen/dockerfile-utils/issues/116)) + ## [0.12.0] - 2023-09-09 ### Added - support parsing the new `--start-interval` flag for HEALTHCHECK instructions ([#115](https://github.com/rcjsuen/dockerfile-utils/issues/115)) diff --git a/src/dockerValidator.ts b/src/dockerValidator.ts index 9201891..8124058 100644 --- a/src/dockerValidator.ts +++ b/src/dockerValidator.ts @@ -675,7 +675,7 @@ export class Validator { if (problem !== null) { problems.push(problem); } - } else if (name !== "chmod" && name !== "chown") { + } else if (name !== "chmod" && name !== "chown" && name !== "checksum") { let range = flag.getNameRange(); problems.push(Validator.createUnknownAddFlag(addInstructionRange.start.line, flagRange.start, range.end, name)); } @@ -684,8 +684,8 @@ export class Validator { if (addDestinationDiagnostic !== null) { problems.push(addDestinationDiagnostic); } - this.checkFlagValue(addInstructionRange.start.line, addFlags, ["chmod", "chown"], problems); - this.checkDuplicateFlags(addInstructionRange.start.line, addFlags, ["chmod", "chown", "link"], problems); + this.checkFlagValue(addInstructionRange.start.line, addFlags, ["chmod", "chown", "checksum"], problems); + this.checkDuplicateFlags(addInstructionRange.start.line, addFlags, ["chmod", "chown", "checksum", "link"], problems); this.checkJSONQuotes(instruction, problems); break; case "COPY": diff --git a/test/dockerValidator.test.ts b/test/dockerValidator.test.ts index 6c795f6..b7481dd 100644 --- a/test/dockerValidator.test.ts +++ b/test/dockerValidator.test.ts @@ -2241,6 +2241,26 @@ describe("Docker Validator Tests", function() { }); }); + describe("checksum", () => { + it("ok", () => { + const diagnostics = validateDockerfile("FROM alpine\nADD --checksum=sha256:24454f830cdb571e2c4ad15481119c43b3cafd48dd869a9b2945d1036d1dc68d https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /"); + assert.strictEqual(diagnostics.length, 0); + }); + + it("flag no value", () => { + const diagnostics = validateDockerfile("FROM alpine\nADD --checksum https://mirrors.edge.kernel.org/pub/linux/kernel/Historic/linux-0.01.tar.gz /"); + assert.strictEqual(diagnostics.length, 1); + assertFlagMissingValue(diagnostics[0], 1, "checksum", 1, 6, 1, 14); + }); + + it("duplicate flag", () => { + const diagnostics = validateDockerfile("FROM alpine\nADD --checksum=abc --checksum=123 a /b"); + assert.strictEqual(diagnostics.length, 2); + assertFlagDuplicate(diagnostics[0], 1, "checksum", 1, 6, 1, 14); + assertFlagDuplicate(diagnostics[1], 1, "checksum", 1, 21, 1, 29); + }); + }); + it("unknown flag", function() { let diagnostics = validateDockerfile("FROM alpine\nADD --x=bb . ."); assert.equal(diagnostics.length, 1);