From b5d2fbaf6797652ea81d55e528dadc3fa9a4fb82 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Sat, 18 Sep 2021 10:10:00 -0400 Subject: [PATCH] Fix #102 Allow no arguments in RUN for BuildKit BuildKit allows RUN instructions to have no arguments so it should not be flagged as an error. Signed-off-by: Remy Suen --- CHANGELOG.md | 4 ++++ src/dockerValidator.ts | 8 +++++--- test/dockerValidator.test.ts | 15 ++++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82a1564..9a583c2 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 BuildKit by ignoring RUN instructions with no arguments ([#102](https://github.com/rcjsuen/dockerfile-utils/issues/102)) + ## [0.8.0] - 2021-09-08 ### Changed - duplicated escape parser directive errors will now only flag the duplicates ([#100](https://github.com/rcjsuen/dockerfile-utils/issues/100)) diff --git a/src/dockerValidator.ts b/src/dockerValidator.ts index 7a6be2c..0e9c7c6 100644 --- a/src/dockerValidator.ts +++ b/src/dockerValidator.ts @@ -104,9 +104,11 @@ export class Validator { validate: Function, createIncompleteDiagnostic?: Function): void { let args = instruction instanceof PropertyInstruction ? instruction.getPropertyArguments() : instruction.getArguments(); if (args.length === 0) { - // all instructions are expected to have at least one argument - let range = instruction.getInstructionRange(); - problems.push(Validator.createMissingArgument(range.start, range.end)); + if (instruction.getKeyword() !== Keyword.RUN) { + // all instructions are expected to have at least one argument + const range = instruction.getInstructionRange(); + problems.push(Validator.createMissingArgument(range.start, range.end)); + } } else if (expectedArgCount[0] === -1) { for (let i = 0; i < args.length; i++) { let createInvalidDiagnostic = validate(i, args[i].getValue(), args[i].getRange()); diff --git a/test/dockerValidator.test.ts b/test/dockerValidator.test.ts index c41eb09..c5aacd6 100644 --- a/test/dockerValidator.test.ts +++ b/test/dockerValidator.test.ts @@ -1128,7 +1128,7 @@ describe("Docker Validator Tests", function() { }); it("RUN", function() { - return testMissingArgumentLoop("RUN"); + return testMissingArgumentLoop("RUN", true); }); it("SHELL", function() { @@ -3957,12 +3957,17 @@ describe("Docker Validator Tests", function() { it("flags only with no argument", function () { let diagnostics = validateDockerfile("FROM alpine\nRUN --x=y"); - assert.equal(diagnostics.length, 1); - assertInstructionMissingArgument(diagnostics[0], 1, 0, 1, 3); + assert.strictEqual(diagnostics.length, 0); diagnostics = validateDockerfile("FROM alpine\nRUN --x=y --abc=def"); - assert.equal(diagnostics.length, 1); - assertInstructionMissingArgument(diagnostics[0], 1, 0, 1, 3); + assert.strictEqual(diagnostics.length, 0); + + diagnostics = validateDockerfile("FROM alpine\nrun --x=y --abc=def"); + assertDiagnostics(diagnostics, + [ ValidationCode.CASING_INSTRUCTION ], + [ assertInstructionCasing ], + [ [ DiagnosticSeverity.Warning, 1, 0, 1, 3 ] ] + ); }); createSingleQuotedJSONTests("RUN");