From d757826d7f969e9b7376d03bc9644920eacd79b3 Mon Sep 17 00:00:00 2001 From: Liam White Date: Wed, 26 Jun 2019 17:14:42 +0100 Subject: [PATCH] bugfix: initial line now preserved on certain file types Signed-off-by: Liam White --- pkg/file/mutator.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/file/mutator.go b/pkg/file/mutator.go index d2e8ca9..ed67904 100644 --- a/pkg/file/mutator.go +++ b/pkg/file/mutator.go @@ -103,21 +103,24 @@ func (m *Mutator) styledLicense(path string) []byte { func merge(license, file []byte) []byte { result := bytes.NewBuffer([]byte{}) fileScanner := bufio.NewScanner(bytes.NewReader(file)) - licensePlaced := false for fileScanner.Scan() { - // If we've placed the license just continue to dump out the rest of the file - if licensePlaced { - result.Write(fileScanner.Bytes()) - result.WriteString("\n") - continue - } // If there's a #! preserve it if strings.Contains(fileScanner.Text(), "#!") { result.Write(fileScanner.Bytes()) result.WriteString("\n\n") + result.Write(license) + } else { + result.Write(license) + result.WriteString("\n") + result.Write(fileScanner.Bytes()) + result.WriteString("\n") + } + + // Now that we've written the license just dump the rest + for fileScanner.Scan() { + result.Write(fileScanner.Bytes()) + result.WriteString("\n") } - result.Write(license) - licensePlaced = true } return result.Bytes() }