diff --git a/hclsyntax/token.go b/hclsyntax/token.go index 5964475..59f4c43 100644 --- a/hclsyntax/token.go +++ b/hclsyntax/token.go @@ -294,12 +294,23 @@ func checkInvalidTokens(tokens Tokens) hcl.Diagnostics { Subject: &tok.Range, }) case TokenInvalid: - diags = append(diags, &hcl.Diagnostic{ - Severity: hcl.DiagError, - Summary: "Invalid character", - Detail: "This character is not used within the language.", - Subject: &tok.Range, - }) + chars := string(tok.Bytes) + switch chars { + case "“", "”": + diags = append(diags, &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid character", + Detail: "\"Curly quotes\" are not valid here. These can sometimes be inadvertently introduced when sharing code via documents or discussion forums. It might help to replace the character with a \"straight quote\".", + Subject: &tok.Range, + }) + default: + diags = append(diags, &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid character", + Detail: "This character is not used within the language.", + Subject: &tok.Range, + }) + } } } return diags diff --git a/hclsyntax/token_test.go b/hclsyntax/token_test.go new file mode 100644 index 0000000..a954d60 --- /dev/null +++ b/hclsyntax/token_test.go @@ -0,0 +1,60 @@ +package hclsyntax + +import ( + "testing" + + "github.com/hashicorp/hcl/v2" +) + +func TestCheckInvalidTokensTest(t *testing.T) { + tests := []struct { + Input string + WantSummary string + WantDetail string + }{ + { + `block “invalid” {}`, + `Invalid character`, + `"Curly quotes" are not valid here. These can sometimes be inadvertently introduced when sharing code via documents or discussion forums. It might help to replace the character with a "straight quote".`, + }, + { + `block 'invalid' {}`, + `Invalid character`, + `Single quotes are not valid. Use double quotes (") to enclose strings.`, + }, + { + "block `invalid` {}", + `Invalid character`, + "The \"`\" character is not valid. To create a multi-line string, use the \"heredoc\" syntax, like \"<