Improve error reporting for comma-separated args
This commit is contained in:
parent
7b147fbae4
commit
d663dc6118
@ -236,10 +236,18 @@ func (p *parser) finishParsingBodyAttribute(ident Token, singleLine bool) (Node,
|
||||
end := p.Peek()
|
||||
if end.Type != TokenNewline && end.Type != TokenEOF {
|
||||
if !p.recovery {
|
||||
summary := "Missing newline after argument"
|
||||
detail := "An argument definition must end with a newline."
|
||||
|
||||
if end.Type == TokenComma {
|
||||
summary = "Unexpected comma after argument"
|
||||
detail = "Argument definitions must be separated by newlines, not commas. " + detail
|
||||
}
|
||||
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Missing newline after argument",
|
||||
Detail: "An argument definition must end with a newline.",
|
||||
Summary: summary,
|
||||
Detail: detail,
|
||||
Subject: &end.Range,
|
||||
Context: hcl.RangeBetween(ident.Range, end.Range).Ptr(),
|
||||
})
|
||||
|
@ -2030,6 +2030,47 @@ block "valid" {}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a = 1,",
|
||||
1,
|
||||
&Body{
|
||||
Attributes: Attributes{
|
||||
"a": {
|
||||
Name: "a",
|
||||
Expr: &LiteralValueExpr{
|
||||
Val: cty.NumberIntVal(1),
|
||||
|
||||
SrcRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 5, Byte: 4},
|
||||
End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
|
||||
},
|
||||
},
|
||||
|
||||
SrcRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
|
||||
End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
|
||||
},
|
||||
NameRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
|
||||
End: hcl.Pos{Line: 1, Column: 2, Byte: 1},
|
||||
},
|
||||
EqualsRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 3, Byte: 2},
|
||||
End: hcl.Pos{Line: 1, Column: 4, Byte: 3},
|
||||
},
|
||||
},
|
||||
},
|
||||
Blocks: Blocks{},
|
||||
SrcRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
|
||||
End: hcl.Pos{Line: 1, Column: 7, Byte: 6},
|
||||
},
|
||||
EndRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
|
||||
End: hcl.Pos{Line: 1, Column: 7, Byte: 6},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a = sort(data.first.ref.attr)[count.index]\n",
|
||||
0,
|
||||
|
Loading…
Reference in New Issue
Block a user