Skip to content

Commit

Permalink
Fix #91 Allow the question mark as a variable modifier
Browse files Browse the repository at this point in the history
The question mark can be used in variable substitution so we should not
flag it as an error.

Signed-off-by: Remy Suen <[email protected]>
  • Loading branch information
rcjsuen committed Mar 27, 2021
1 parent 57f8a3b commit ae6234e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 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]
### 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))
Expand Down
2 changes: 1 addition & 1 deletion src/dockerValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions test/dockerValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ae6234e

Please sign in to comment.