Skip to content

Commit

Permalink
chore: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
joerdav committed Nov 30, 2023
1 parent 84c4ec2 commit e7cbab8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
var ErrNoTasksHeading = errors.New("no xc block found")

const trimValues = "_*` "
const codeBlockStarter = "```"

type parser struct {
scanner *bufio.Scanner
Expand Down Expand Up @@ -187,15 +188,15 @@ func (p *parser) parseAttribute() (bool, error) {

func (p *parser) parseCodeBlock() error {
t := p.currentLine
if len(t) < 3 || t[:3] != "```" {
if len(t) < 3 || t[:3] != codeBlockStarter {
return nil
}
if len(p.currTask.Script) > 0 {
return fmt.Errorf("command block already exists for task %s", p.currTask.Name)
}
var ended bool
for p.scan() {
if len(p.currentLine) >= 3 && p.currentLine[:3] == "```" {
if len(p.currentLine) >= 3 && p.currentLine[:3] == codeBlockStarter {
ended = true
break
}
Expand Down
10 changes: 5 additions & 5 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func TestHeadingCaseInsensitive(t *testing.T) {
p, _ := NewParser(strings.NewReader(fmt.Sprintf(`
# %s
## a task
`+"```"+`
`+codeBlockStarter+`
some code
`+"```"+`
`+codeBlockStarter+`
`, tt.mdHeading)), tt.parserHeading)
_, err := p.parseTask()
if err != nil {
Expand All @@ -171,7 +171,7 @@ func TestUnTerminatedCodeBlock(t *testing.T) {
p, _ := NewParser(strings.NewReader(`
# Tasks
## a task
`+"```"+`
`+codeBlockStarter+`
some code
`), "tasks")
_, err := p.parseTask()
Expand Down Expand Up @@ -357,10 +357,10 @@ Requires: list, list2
` + "Env: `somevar=val`" + `
Inputs: FOO, BAR
` + "```" + `
` + codeBlockStarter + `
echo "Hello, world!"
echo "Hello, world2!"
` + "```")
` + codeBlockStarter)
}
file := buf.String()
for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit e7cbab8

Please sign in to comment.