From 9640de1955cd90b17a37440ccc179044efc8965a Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 20 Sep 2024 08:06:13 +0800 Subject: [PATCH] chore: tweak linter warning --- parser/parser.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index e52a057..e4520f7 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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{}, @@ -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{}, @@ -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 } @@ -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) }