Skip to content

Commit 5738eaa

Browse files
authored
Merge pull request #466 from docker/bake-annotations-missing-equals-error
Flag annotations without an equals sign as an error
2 parents 6d1ff80 + bd6ce82 commit 5738eaa

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All notable changes to the Docker Language Server will be documented in this fil
99
- Dockerfile
1010
- textDocument/codeAction
1111
- `InvalidBaseImagePlatform` warnings can now be ignored with a code action ([#464](https://github.com/docker/docker-language-server/issues/464))
12+
- Bake
13+
- textDocument/publishDiagnostics
14+
- flag `annotations` in a `target` block without an equals sign as an error ([#99](https://github.com/docker/docker-language-server/issues/99))
1215

1316
### Fixed
1417

internal/bake/hcl/diagnosticsCollector.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ func (c *BakeHCLDiagnosticsCollector) CollectDiagnostics(source, workspaceFolder
228228
}
229229
}
230230

231+
if attribute, ok := block.Body.Attributes["annotations"]; ok {
232+
if expr, ok := attribute.Expr.(*hclsyntax.TupleConsExpr); ok {
233+
for _, e := range expr.Exprs {
234+
if templateExpr, ok := e.(*hclsyntax.TemplateExpr); ok {
235+
if templateExpr.IsStringLiteral() {
236+
value, _ := templateExpr.Value(&hcl.EvalContext{})
237+
if len(strings.Split(value.AsString(), "=")) < 2 {
238+
diagnostics = append(diagnostics, protocol.Diagnostic{
239+
Message: fmt.Sprintf(`invalid annotation "%v", expected key=value`, value.AsString()),
240+
Source: types.CreateStringPointer(source),
241+
Severity: types.CreateDiagnosticSeverityPointer(protocol.DiagnosticSeverityError),
242+
Range: createProtocolRange(templateExpr.SrcRange, false),
243+
})
244+
}
245+
}
246+
}
247+
}
248+
}
249+
}
250+
231251
_, dockerfilePath, err := bakeDoc.DockerfileForTarget(block)
232252
if dockerfilePath == "" || err != nil {
233253
continue

internal/bake/hcl/diagnosticsCollector_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,24 @@ target "build" {
358358
},
359359
},
360360
},
361+
{
362+
name: "annotations attribute has no equals sign",
363+
content: `
364+
target "t1" {
365+
annotations = [ "abc" ]
366+
}`,
367+
diagnostics: []protocol.Diagnostic{
368+
{
369+
Message: `invalid annotation "abc", expected key=value`,
370+
Source: types.CreateStringPointer("docker-language-server"),
371+
Severity: types.CreateDiagnosticSeverityPointer(protocol.DiagnosticSeverityError),
372+
Range: protocol.Range{
373+
Start: protocol.Position{Line: 2, Character: 18},
374+
End: protocol.Position{Line: 2, Character: 23},
375+
},
376+
},
377+
},
378+
},
361379
}
362380

363381
wd, err := os.Getwd()

0 commit comments

Comments
 (0)