Skip to content

Commit

Permalink
Fix Tab Before Inline Comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cwarden committed Jan 28, 2025
1 parent 68ec2e3 commit 3fa0e15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions formatter/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func (e *testErrorListener) SyntaxError(_ antlr.Recognizer, _ interface{}, line,
func TestStatement(t *testing.T) {
if testing.Verbose() {
log.SetLevel(log.TraceLevel)
log.SetFormatter(&log.TextFormatter{
DisableQuote: true,
})
}
tests :=
[]struct {
Expand Down Expand Up @@ -378,6 +381,18 @@ b);`,
WhatId IN :this.oldAccountProfileIds
]);`,
},
{
`Account a = new Account(
Name = 'Acme',
Type = 'Something', // a comment
BillingPostalCode = '90210'
);`,
`Account a = new Account(
Name = 'Acme',
Type = 'Something', // a comment
BillingPostalCode = '90210'
);`,
},
}
dmp := diffmatchpatch.New()
for i, tt := range tests {
Expand Down
5 changes: 5 additions & 0 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func removeExtraCommentIndentation(input string) string {

newlinePrefixedInlineComment := regexp.MustCompile("\n\t*\uFFF9\n")
input = newlinePrefixedInlineComment.ReplaceAllString(input, "\uFFF9\n")
log.Trace(fmt.Sprintf("ADJUSTED(6): %q", input))

tabPrefixedInlineComment := regexp.MustCompile(`([\w,]+)` + "\t+\uFFF9")
input = tabPrefixedInlineComment.ReplaceAllString(input, "$1 \uFFF9")
log.Trace(fmt.Sprintf("ADJUSTED(7): %q", input))

// Remove inline comment delimeters
inlineCommentPattern := regexp.MustCompile(`(?s)` + "\uFFF9" + `(.*?)` + "\uFFFB")
Expand Down

0 comments on commit 3fa0e15

Please sign in to comment.