Skip to content

Commit

Permalink
Fix #102 Allow no arguments in RUN for BuildKit
Browse files Browse the repository at this point in the history
BuildKit allows RUN instructions to have no arguments so it should not
be flagged as an error.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Sep 18, 2021
1 parent 0826f09 commit b5d2fba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
8 changes: 5 additions & 3 deletions src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
15 changes: 10 additions & 5 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ describe("Docker Validator Tests", function() {
});

it("RUN", function() {
return testMissingArgumentLoop("RUN");
return testMissingArgumentLoop("RUN", true);
});

it("SHELL", function() {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit b5d2fba

Please sign in to comment.