Skip to content

Commit

Permalink
chore: tweak linter warning
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Sep 20, 2024
1 parent 6a369a0 commit 9640de1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,19 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
case *ast.OrderedListItem, *ast.UnorderedListItem, *ast.TaskListItem:
var listKind ast.ListKind
var indent int
switch nodes[i].(type) {
switch item := nodes[i].(type) {
case *ast.OrderedListItem:
listKind = ast.OrderedList
indent = nodes[i].(*ast.OrderedListItem).Indent
indent = item.Indent
case *ast.UnorderedListItem:
listKind = ast.UnorderedList
indent = nodes[i].(*ast.UnorderedListItem).Indent
indent = item.Indent
case *ast.TaskListItem:
listKind = ast.DescrpitionList
indent = nodes[i].(*ast.TaskListItem).Indent
indent = item.Indent
}
indent = indent / 2

indent /= 2
if prevResultNode == nil || prevResultNode.Type() != ast.ListNode || prevResultNode.(*ast.List).Kind != listKind || prevResultNode.(*ast.List).Indent > indent {
prevResultNode = &ast.List{
BaseBlock: ast.BaseBlock{},
Expand All @@ -143,9 +144,12 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
continue
}

listNode := prevResultNode.(*ast.List)
listNode, ok := prevResultNode.(*ast.List)
if !ok {
continue
}
if listNode.Indent != indent {
parent := findPossibleParent(listNode, indent)
parent := findListPossibleParent(listNode, indent)
if parent == nil {
parent = &ast.List{
BaseBlock: ast.BaseBlock{},
Expand Down Expand Up @@ -190,7 +194,7 @@ func mergeTextNodes(nodes []ast.Node) []ast.Node {
return result
}

func findPossibleParent(listNode *ast.List, indent int) *ast.List {
func findListPossibleParent(listNode *ast.List, indent int) *ast.List {
if listNode.Indent == indent {
return listNode
}
Expand All @@ -204,5 +208,5 @@ func findPossibleParent(listNode *ast.List, indent int) *ast.List {
if lastChild.Type() != ast.ListNode {
return nil
}
return findPossibleParent(lastChild.(*ast.List), indent)
return findListPossibleParent(lastChild.(*ast.List), indent)
}

0 comments on commit 9640de1

Please sign in to comment.