Skip to content

Commit

Permalink
Fix granular formatting disable to allow for preceding blank lines.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 664785820
  • Loading branch information
txtpbfmt-copybara-robot committed Aug 19, 2024
1 parent a619d35 commit 0a5c94e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,12 @@ func (p *parser) readContinuousBlocksOfComments() []string {
// within this block, and as parsing errors will be ignored, please exercise caution.
func (p *parser) readFormatterDisabledBlock() (string, error) {
start := p.index
for p.consume('\n') {
// Consume blank lines.
}
if !p.consumeString("# txtpbfmt: off") {
// Directive not found. Rollback to start.
p.index = start
return "", nil
}
if !p.consume('\n') {
Expand Down
2 changes: 2 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,7 @@ bar {
should_format {
foo: "bar"
}
# txtpbfmt: off
no_format { foo: "bar" } # txtpbfmt: on
should_format {
Expand All @@ -1499,6 +1500,7 @@ bar {
should_format {
foo: "bar"
}
# txtpbfmt: off
no_format { foo: "bar" } # txtpbfmt: on
should_format {
Expand Down

0 comments on commit 0a5c94e

Please sign in to comment.