Skip to content

Commit

Permalink
Merge pull request #43 from moorereason/clean-lint
Browse files Browse the repository at this point in the history
Clean lint
  • Loading branch information
yuin committed Dec 1, 2019
2 parents 2f292e5 + 74e1374 commit 615d570
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func Walk(n Node, walker Walker) error {
}
if status != WalkSkipChildren {
for c := n.FirstChild(); c != nil; c = c.NextSibling() {
if err := Walk(c, walker); err != nil {
if err = Walk(c, walker); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion commonmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

. "github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

type commonmarkSpecTestCase struct {
Expand Down
2 changes: 1 addition & 1 deletion extension/definition_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestDefinitionList(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion extension/footnote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestFootnote(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion extension/strikethrough_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestStrikethrough(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions extension/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func (b *tableParagraphTransformer) parseRow(segment text.Segment, alignments []
closure = len(line[pos:])
}
node := ast.NewTableCell()
segment := text.NewSegment(segment.Start+pos, segment.Start+pos+closure)
segment = segment.TrimLeftSpace(source)
segment = segment.TrimRightSpace(source)
node.Lines().Append(segment)
seg := text.NewSegment(segment.Start+pos, segment.Start+pos+closure)
seg = seg.TrimLeftSpace(source)
seg = seg.TrimRightSpace(source)
node.Lines().Append(seg)
node.Alignment = alignment
row.AppendChild(row, node)
pos += closure + 1
Expand Down
2 changes: 1 addition & 1 deletion extension/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestTable(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion extension/tasklist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestTaskList(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion extension/typographer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/testutil"
)

func TestTypographer(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions fuzz/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package fuzz

import (
"bytes"

"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
)

// Fuzz runs automated fuzzing against goldmark.
func Fuzz(data []byte) int {
markdown := goldmark.New(
goldmark.WithRendererOptions(
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

. "github.com/yuin/goldmark"
"github.com/yuin/goldmark/testutil"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/testutil"
)

func TestAttributeAndAutoHeadingID(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions parser/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package parser

import (
"bytes"
"io"
"strconv"

"github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
"strconv"
)

var attrNameID = []byte("id")
Expand Down Expand Up @@ -104,7 +106,7 @@ func parseAttribute(reader text.Reader) (Attribute, bool) {
}
i := 0
for ; i < len(line); i++ {
c := line[i]
c = line[i]
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '_' || c == ':' || c == '.' || c == '-') {
Expand All @@ -125,7 +127,6 @@ func parseAttribute(reader text.Reader) (Attribute, bool) {
return Attribute{}, false
}
return Attribute{Name: name, Value: value}, true

}

func parseAttributeValue(reader text.Reader) (interface{}, bool) {
Expand Down Expand Up @@ -153,7 +154,6 @@ func parseAttributeValue(reader text.Reader) (interface{}, bool) {
return nil, false
}
return value, true

}

func parseAttributeArray(reader text.Reader) ([]interface{}, bool) {
Expand Down Expand Up @@ -228,7 +228,7 @@ func parseAttributeString(reader text.Reader) ([]byte, bool) {
return nil, false
}

func scanAttributeDecimal(reader text.Reader, w *bytes.Buffer) {
func scanAttributeDecimal(reader text.Reader, w io.ByteWriter) {
for {
c := reader.Peek()
if util.IsNumeric(c) {
Expand Down
20 changes: 10 additions & 10 deletions parser/atx_heading.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ func (b *atxHeadingParser) Open(parent ast.Node, reader text.Reader, pc Context)
start--
closureClose := -1
closureOpen := -1
for i := start; i < stop; {
c := line[i]
if util.IsEscapedPunctuation(line, i) {
i += 2
} else if util.IsSpace(c) && i < stop-1 && line[i+1] == '#' {
closureOpen = i + 1
j := i + 1
for ; j < stop && line[j] == '#'; j++ {
for j := start; j < stop; {
c := line[j]
if util.IsEscapedPunctuation(line, j) {
j += 2
} else if util.IsSpace(c) && j < stop-1 && line[j+1] == '#' {
closureOpen = j + 1
k := j + 1
for ; k < stop && line[k] == '#'; k++ {
}
closureClose = j
closureClose = k
break
} else {
i++
j++
}
}
if closureClose > 0 {
Expand Down
2 changes: 1 addition & 1 deletion parser/code_span.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s *codeSpanParser) Parse(parent ast.Node, block text.Reader, pc Context) a
}
closure := i - oldi
if closure == opener && (i+1 >= len(line) || line[i+1] != '`') {
segment := segment.WithStop(segment.Start + i - closure)
segment = segment.WithStop(segment.Start + i - closure)
if !segment.IsEmpty() {
node.AppendChild(node, ast.NewRawTextSegment(segment))
}
Expand Down
11 changes: 6 additions & 5 deletions parser/html_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package parser

import (
"bytes"
"regexp"
"strings"

"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
"regexp"
"strings"
)

var allowedBlockTags = map[string]bool{
Expand Down Expand Up @@ -97,12 +98,12 @@ var htmlBlockType7Regexp = regexp.MustCompile(`^[ ]{0,3}<(/)?([a-zA-Z0-9]+)(` +
type htmlBlockParser struct {
}

var defaultHtmlBlockParser = &htmlBlockParser{}
var defaultHTMLBlockParser = &htmlBlockParser{}

// NewHTMLBlockParser return a new BlockParser that can parse html
// blocks.
func NewHTMLBlockParser() BlockParser {
return defaultHtmlBlockParser
return defaultHTMLBlockParser
}

func (b *htmlBlockParser) Trigger() []byte {
Expand Down Expand Up @@ -133,7 +134,7 @@ func (b *htmlBlockParser) Open(parent ast.Node, reader text.Reader, pc Context)
isCloseTag := match[2] > -1 && bytes.Equal(line[match[2]:match[3]], []byte("/"))
hasAttr := match[6] != match[7]
tagName = strings.ToLower(string(line[match[4]:match[5]]))
_, ok := allowedBlockTags[strings.ToLower(string(tagName))]
_, ok := allowedBlockTags[tagName]
if ok {
node = ast.NewHTMLBlock(ast.HTMLBlockType6)
} else if tagName != "script" && tagName != "style" && tagName != "pre" && !ast.IsParagraph(last) && !(isCloseTag && hasAttr) { // type 7 can not interrupt paragraph
Expand Down
3 changes: 1 addition & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ retry:
if w > 3 && !bp.CanAcceptIndentedLine() {
continue
}
lastBlock := pc.LastOpenedBlock()
lastBlock = pc.LastOpenedBlock()
last := lastBlock.Node
node, state := bp.Open(parent, reader, pc)
if node != nil {
Expand Down Expand Up @@ -1177,5 +1177,4 @@ func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context)
for _, ip := range p.closeBlockers {
ip.CloseBlock(parent, block, pc)
}

}
2 changes: 1 addition & 1 deletion parser/thematic_break.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type thematicBreakPraser struct {

var defaultThematicBreakPraser = &thematicBreakPraser{}

// NewThematicBreakPraser returns a new BlockParser that
// NewThematicBreakParser returns a new BlockParser that
// parses thematic breaks.
func NewThematicBreakParser() BlockParser {
return defaultThematicBreakPraser
Expand Down
5 changes: 2 additions & 3 deletions renderer/renderer.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Package renderer renders the given AST to certain formats.
// Package renderer renders the given AST to certain formats.
package renderer

import (
"bufio"
"io"
"sync"

"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/util"

"sync"
)

// A Config struct is a data structure that holds configuration of the Renderer.
Expand Down
4 changes: 4 additions & 0 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type TestingT interface {
FailNow()
}

// MarkdownTestCase represents a test case.
type MarkdownTestCase struct {
No int
Markdown string
Expand All @@ -30,6 +31,7 @@ type MarkdownTestCase struct {
const attributeSeparator = "//- - - - - - - - -//"
const caseSeparator = "//= = = = = = = = = = = = = = = = = = = = = = = =//"

// DoTestCaseFile runs test cases in a given file.
func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
fp, err := os.Open(filename)
if err != nil {
Expand Down Expand Up @@ -86,12 +88,14 @@ func DoTestCaseFile(m goldmark.Markdown, filename string, t TestingT) {
DoTestCases(m, cases, t)
}

// DoTestCases runs a set of test cases.
func DoTestCases(m goldmark.Markdown, cases []MarkdownTestCase, t TestingT) {
for _, testCase := range cases {
DoTestCase(m, testCase, t)
}
}

// DoTestCase runs a test case.
func DoTestCase(m goldmark.Markdown, testCase MarkdownTestCase, t TestingT) {
var ok bool
var out bytes.Buffer
Expand Down
7 changes: 4 additions & 3 deletions text/reader.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package text

import (
"github.com/yuin/goldmark/util"
"io"
"regexp"
"unicode/utf8"

"github.com/yuin/goldmark/util"
)

const invalidValue = -1
Expand Down Expand Up @@ -138,7 +139,7 @@ func (r *reader) LineOffset() int {
if r.source[i] == '\t' {
v += util.TabWidth(v)
} else {
v += 1
v++
}
}
r.lineOffset = v - r.pos.Padding
Expand Down Expand Up @@ -355,7 +356,7 @@ func (r *blockReader) LineOffset() int {
if r.source[i] == '\t' {
v += util.TabWidth(v)
} else {
v += 1
v++
}
}
r.lineOffset = v - r.pos.Padding
Expand Down
2 changes: 1 addition & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func URLEscape(v []byte, resolveReference bool) []byte {
cob.Write(v[n:i])
stop := i + int(u8len)
if stop > len(v) {
i += 1
i++
n = i
continue
}
Expand Down

0 comments on commit 615d570

Please sign in to comment.