mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-12-05 00:00:34 +00:00
Merge pull request #23 from erizocosmico/fix/get-first-line
data: fix getting the first line for empty content
This commit is contained in:
commit
2880ccae4a
@ -188,7 +188,11 @@ func isSourceMap(path, _ string, content []byte) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
firstLine := getLines(content, 1)[0]
|
firstLine := getFirstLine(content)
|
||||||
|
if len(firstLine) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range sourceMapRegexps {
|
for _, r := range sourceMapRegexps {
|
||||||
if r.Match(firstLine) {
|
if r.Match(firstLine) {
|
||||||
return true
|
return true
|
||||||
@ -203,7 +207,7 @@ func isCompiledCoffeeScript(path, ext string, content []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
firstLine := getLines(content, 1)[0]
|
firstLine := getFirstLine(content)
|
||||||
lastLines := getLines(content, -2)
|
lastLines := getLines(content, -2)
|
||||||
|
|
||||||
if string(firstLine) == "(function() {" &&
|
if string(firstLine) == "(function() {" &&
|
||||||
@ -753,6 +757,14 @@ func isGeneratedJooq(_, ext string, content []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFirstLine(content []byte) []byte {
|
||||||
|
lines := getLines(content, 1)
|
||||||
|
if len(lines) > 0 {
|
||||||
|
return lines[0]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// getLines returns up to the first n lines. A negative index will return up to
|
// getLines returns up to the first n lines. A negative index will return up to
|
||||||
// the last n lines in reverse order.
|
// the last n lines in reverse order.
|
||||||
func getLines(content []byte, n int) [][]byte {
|
func getLines(content []byte, n int) [][]byte {
|
||||||
|
@ -8,6 +8,10 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestGetFirstLineEmptyContent(t *testing.T) {
|
||||||
|
require.Nil(t, getFirstLine(nil))
|
||||||
|
}
|
||||||
|
|
||||||
func TestForEachLine(t *testing.T) {
|
func TestForEachLine(t *testing.T) {
|
||||||
const sample = "foo\nbar\nboomboom\nbleepbloop\n"
|
const sample = "foo\nbar\nboomboom\nbleepbloop\n"
|
||||||
var lines = strings.Split(sample, "\n")
|
var lines = strings.Split(sample, "\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user