-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: hotfix shim for CRLF behaviour (#36)
* fix: hotfix shim for CRLF behaviour Added a configuration option for line endings, which is a feature that needs to exist anyway. Also included temporary hotfix behaviour for CRLF normalization while waiting for upstream fixes to get merged. * LineBreakStyle was useless, LineEndings rename was renamed to LineEnding to match the config key value. * remove accidental fmt println
- Loading branch information
Showing
8 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package hotfix | ||
|
||
func StripCRBytes(crlfContent []byte) []byte { | ||
onlyLf := []byte{} | ||
for _, b := range crlfContent { | ||
if b != '\r' { | ||
onlyLf = append(onlyLf, b) | ||
} | ||
} | ||
return onlyLf | ||
} | ||
|
||
func WriteCRLFBytes(lfContent []byte) []byte { | ||
crlfContent := []byte{} | ||
for _, b := range lfContent { | ||
if b == '\n' { | ||
crlfContent = append(crlfContent, '\r') | ||
} | ||
crlfContent = append(crlfContent, b) | ||
} | ||
return crlfContent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hotfix_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/yamlfmt/internal/hotfix" | ||
) | ||
|
||
func TestStripCRBytes(t *testing.T) { | ||
crlfContent := []byte("two\r\nlines\r\n") | ||
lfContent := hotfix.StripCRBytes(crlfContent) | ||
count := countByte(lfContent, '\r') | ||
if count != 0 { | ||
t.Fatalf("Found %d CR (decimal 13) bytes in %v", count, lfContent) | ||
} | ||
} | ||
|
||
func TestWriteCRLF(t *testing.T) { | ||
lfContent := []byte("two\nlines\n") | ||
crlfContent := hotfix.WriteCRLFBytes(lfContent) | ||
countCR := countByte(crlfContent, '\r') | ||
countLF := countByte(crlfContent, '\n') | ||
if countCR != countLF { | ||
t.Fatalf("Found %d CR (decimal 13) and %d LF (decimal 10) bytes in %v", countCR, countLF, crlfContent) | ||
} | ||
} | ||
|
||
func countByte(content []byte, searchByte byte) int { | ||
count := 0 | ||
for _, b := range content { | ||
if b == searchByte { | ||
count++ | ||
} | ||
} | ||
return count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters