Skip to content

Commit

Permalink
bugfix: initial line now preserved on certain file types
Browse files Browse the repository at this point in the history
Signed-off-by: Liam White <[email protected]>
  • Loading branch information
liamawhite committed Jun 26, 2019
1 parent f360f32 commit d757826
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/file/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit d757826

Please sign in to comment.