From c3e669358995c241045d52308b0c10e496f0d2d7 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Mon, 25 Mar 2024 18:15:39 -0400 Subject: [PATCH] Fix #123 Support the new --parents flag in COPY Support has been added for the new boolean --parents flag for COPY instructions. This flag will now be recognized and will no longer be identified as an error by the validator. Signed-off-by: Remy Suen --- CHANGELOG.md | 1 + src/dockerValidator.ts | 6 +++--- test/dockerValidator.test.ts | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 520aa49..49987ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Added - support parsing the new `--exclude` flag for ADD and COPY instructions ([#124](https://github.com/rcjsuen/dockerfile-utils/issues/124)) +- support parsing the new `--parents` flag for COPY instructions ([#123](https://github.com/rcjsuen/dockerfile-utils/issues/123)) ## [0.15.0] - 2023-09-10 ### Added diff --git a/src/dockerValidator.ts b/src/dockerValidator.ts index 1ac3b9f..4211857 100644 --- a/src/dockerValidator.ts +++ b/src/dockerValidator.ts @@ -723,12 +723,12 @@ export class Validator { const flagRange = flag.getRange(); if (name === "") { problems.push(Validator.createUnknownCopyFlag(copyInstructionRange.start.line, flagRange.start, flagRange.end, name)); - } else if (name === "link") { + } else if (name === "link" || name === "parents") { const problem = this.checkFlagBoolean(copyInstructionRange.start.line, flag); if (problem !== null) { problems.push(problem); } - } else if (name !== "chmod" && name !== "chown" && name !== "from" && name !== "exclude") { + } else if (name !== "chmod" && name !== "chown" && name !== "from" && name !== "exclude" && name !== "parents") { let range = flag.getNameRange(); problems.push(Validator.createUnknownCopyFlag(copyInstructionRange.start.line, flagRange.start, range.end, name)); } @@ -751,7 +751,7 @@ export class Validator { problems.push(copyDestinationDiagnostic); } this.checkFlagValue(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "exclude"], problems); - this.checkDuplicateFlags(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "link"], problems); + this.checkDuplicateFlags(copyInstructionRange.start.line, flags, ["chmod", "chown", "from", "link", "parents"], problems); this.checkJSONQuotes(instruction, problems); break; case "WORKDIR": diff --git a/test/dockerValidator.test.ts b/test/dockerValidator.test.ts index 78ede34..e7b578d 100644 --- a/test/dockerValidator.test.ts +++ b/test/dockerValidator.test.ts @@ -2877,6 +2877,46 @@ describe("Docker Validator Tests", function() { }); }); + describe("parents", () => { + it("ok", () => { + let diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=true . ."); + assert.strictEqual(diagnostics.length, 0); + + diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=false . ."); + assert.strictEqual(diagnostics.length, 0); + + diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=TrUE . ."); + assert.strictEqual(diagnostics.length, 0); + + diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=fALSe . ."); + assert.strictEqual(diagnostics.length, 0); + }); + + it("no value", () => { + const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents . ."); + assert.strictEqual(diagnostics.length, 0); + }); + + it("empty value", () => { + const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents= . ."); + assert.strictEqual(diagnostics.length, 1); + assertFlagMissingValue(diagnostics[0], 1, "parents", 1, 7, 1, 14); + }); + + it("invalid value", () => { + const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=abc . ."); + assert.strictEqual(diagnostics.length, 1); + assertFlagExpectedBooleanValue(diagnostics[0], 1, "parents", "abc", 1, 15, 1, 18); + }); + + it("duplicate flag", () => { + const diagnostics = validateDockerfile("FROM alpine\nCOPY --parents=true --parents=false . ."); + assert.strictEqual(diagnostics.length, 2); + assertFlagDuplicate(diagnostics[0], 1, "parents", 1, 7, 1, 14); + assertFlagDuplicate(diagnostics[1], 1, "parents", 1, 22, 1, 29); + }); + }); + it("all flags", function() { let diagnostics = validateDockerfile("FROM node AS bb\nFROM alpine\nCOPY --from=bb --chown=node:node . ."); assert.equal(diagnostics.length, 0);