From ae6234eca67f8aba9950c33277e3ba762a18b8e3 Mon Sep 17 00:00:00 2001 From: Remy Suen Date: Sat, 27 Mar 2021 06:34:14 -0400 Subject: [PATCH] Fix #91 Allow the question mark as a variable modifier The question mark can be used in variable substitution so we should not flag it as an error. Signed-off-by: Remy Suen --- CHANGELOG.md | 4 ++++ src/dockerValidator.ts | 2 +- test/dockerValidator.test.ts | 7 +------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac9f1a..063cab4 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] +### Fixed +- do not flag `?` as an invalid modifier in variable substitutions ([#91](https://github.com/rcjsuen/dockerfile-utils/issues/91)) + ## [0.3.0] - 2021-02-28 ### Added - a new `FormatterSettings` interface for defining `ignoreMultilineInstructions` to ignore instructions that span multiple lines ([#62](https://github.com/rcjsuen/dockerfile-utils/issues/62)) diff --git a/src/dockerValidator.ts b/src/dockerValidator.ts index 3b2da62..cbd1d40 100644 --- a/src/dockerValidator.ts +++ b/src/dockerValidator.ts @@ -154,7 +154,7 @@ export class Validator { default: if (modifier === "") { problems.push(Validator.createVariableUnsupportedModifier(variable.getRange(), variable.toString(), modifier)); - } else if (modifier !== '+' && modifier !== '-') { + } else if (modifier !== '+' && modifier !== '-' && modifier !== '?') { problems.push(Validator.createVariableUnsupportedModifier(variable.getModifierRange(), variable.toString(), modifier)); } break; diff --git a/test/dockerValidator.test.ts b/test/dockerValidator.test.ts index 6e49533..6407e95 100644 --- a/test/dockerValidator.test.ts +++ b/test/dockerValidator.test.ts @@ -1593,12 +1593,7 @@ describe("Docker Validator Tests", function() { it("question mark modifier", function() { let diagnostics = validateDockerfile("FROM scratch\nENV bbb=123\n" + prefix + "${bbb:?}" + suffix); - if (prefix === "CMD " || prefix === "ENTRYPOINT " || prefix === "RUN ") { - assert.equal(diagnostics.length, 0); - } else { - assert.equal(diagnostics.length, 1); - assertVariableModifierUnsupported(diagnostics[0], "${bbb:?}", '?', 2, length + 6, 2, length + 7); - } + assert.equal(diagnostics.length, 0); }); it("no modifier", function() {