hcl/hclsyntax: Produce better error message for invalid apostrophe
This commit is contained in:
parent
d43e8fd7d9
commit
6d20f625a6
@ -2109,6 +2109,44 @@ block "valid" {}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
`a = 'str'`,
|
||||
2, // Invalid character and expression
|
||||
&Body{
|
||||
Attributes: Attributes{
|
||||
"a": {
|
||||
Name: "a",
|
||||
Expr: &LiteralValueExpr{
|
||||
SrcRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 5, Byte: 4},
|
||||
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},
|
||||
},
|
||||
SrcRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
|
||||
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: 10, Byte: 9},
|
||||
},
|
||||
EndRange: hcl.Range{
|
||||
Start: hcl.Pos{Line: 1, Column: 10, Byte: 9},
|
||||
End: hcl.Pos{Line: 1, Column: 10, Byte: 9},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"a = sort(data.first.ref.attr)[count.index]\n",
|
||||
0,
|
||||
|
@ -184,6 +184,7 @@ func checkInvalidTokens(tokens Tokens) hcl.Diagnostics {
|
||||
toldBitwise := 0
|
||||
toldExponent := 0
|
||||
toldBacktick := 0
|
||||
toldApostrophe := 0
|
||||
toldSemicolon := 0
|
||||
toldTabs := 0
|
||||
toldBadUTF8 := 0
|
||||
@ -238,6 +239,19 @@ func checkInvalidTokens(tokens Tokens) hcl.Diagnostics {
|
||||
if toldBacktick <= 2 {
|
||||
toldBacktick++
|
||||
}
|
||||
case TokenApostrophe:
|
||||
if (toldApostrophe % 2) == 0 {
|
||||
newDiag := &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid character",
|
||||
Detail: "The ' character is not valid. Use double quotes (\") to enclose strings.",
|
||||
Subject: &tok.Range,
|
||||
}
|
||||
diags = append(diags, newDiag)
|
||||
}
|
||||
if toldApostrophe <= 2 {
|
||||
toldApostrophe++
|
||||
}
|
||||
case TokenSemicolon:
|
||||
if toldSemicolon < 1 {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
|
Loading…
Reference in New Issue
Block a user