Skip to content

Commit

Permalink
Fix #21 Use non-zero ranges for diagnostics
Browse files Browse the repository at this point in the history
If a FROM's base image's digest string is the empty string, the
generated diagnostic's range has a length of zero. This causes the
CLI to not highlight anything in its output. Use the entire
argument's range for the diagnostic instead so that the CLI can at
least highlight something meaningful.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
  • Loading branch information
rcjsuen committed Feb 11, 2018
1 parent ab83d4f commit 88d1abe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [Unreleased]
### Fixed
- use a non-zero range for the diagnostic if FROM's base image's digest is the empty string ([#21](https://github.com/rcjsuen/dockerfile-utils/issues/21))

## [0.0.6] - 2018-02-11
### Added
- create a Docker image for running the CLI ([#10](https://github.com/rcjsuen/dockerfile-utils/issues/10))
Expand Down Expand Up @@ -41,6 +45,7 @@ All notable changes to this project will be documented in this file.
- create formatter for Dockerfiles
- create linter for Dockerfiles

[Unreleased]: https://github.com/rcjsuen/dockerfile-utils/compare/v0.0.6...HEAD
[0.0.6]: https://github.com/rcjsuen/dockerfile-utils/compare/v0.0.5...v0.0.6
[0.0.5]: https://github.com/rcjsuen/dockerfile-utils/compare/v0.0.4...v0.0.5
[0.0.4]: https://github.com/rcjsuen/dockerfile-utils/compare/v0.0.3...v0.0.4
Expand Down
5 changes: 5 additions & 0 deletions src/dockerValidator.ts
Expand Up @@ -348,6 +348,11 @@ export class Validator {
}
let endIndex = argument.indexOf(':');
if (endIndex === -1) {
let digest = argument.substring(index + 1);
if (digest === "") {
// no digest specified, just highlight the whole argument
return Validator.createInvalidReferenceFormat(range);
}
return Validator.createInvalidReferenceFormat(from.getImageDigestRange());
}
let algorithmRegexp = new RegExp(/[A-Fa-f0-9_+.-]+/);
Expand Down
6 changes: 5 additions & 1 deletion test/dockerValidator.test.ts
Expand Up @@ -2224,7 +2224,11 @@ describe("Docker Validator Tests", function() {
});

it("invalid reference format (digest)", function() {
let diagnostics = validateDockerfile("FROM alpine@sha25");
let diagnostics = validateDockerfile("FROM alpine@");
assert.equal(diagnostics.length, 1);
assertInvalidReferenceFormat(diagnostics[0], 0, 5, 0, 12);

diagnostics = validateDockerfile("FROM alpine@sha25");
assert.equal(diagnostics.length, 1);
assertInvalidReferenceFormat(diagnostics[0], 0, 12, 0, 17);

Expand Down

0 comments on commit 88d1abe

Please sign in to comment.