Skip to content

Commit 9640de1

Browse files
committed
chore: tweak linter warning
1 parent 6a369a0 commit 9640de1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

parser/parser.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,19 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
120120
case *ast.OrderedListItem, *ast.UnorderedListItem, *ast.TaskListItem:
121121
var listKind ast.ListKind
122122
var indent int
123-
switch nodes[i].(type) {
123+
switch item := nodes[i].(type) {
124124
case *ast.OrderedListItem:
125125
listKind = ast.OrderedList
126-
indent = nodes[i].(*ast.OrderedListItem).Indent
126+
indent = item.Indent
127127
case *ast.UnorderedListItem:
128128
listKind = ast.UnorderedList
129-
indent = nodes[i].(*ast.UnorderedListItem).Indent
129+
indent = item.Indent
130130
case *ast.TaskListItem:
131131
listKind = ast.DescrpitionList
132-
indent = nodes[i].(*ast.TaskListItem).Indent
132+
indent = item.Indent
133133
}
134-
indent = indent / 2
134+
135+
indent /= 2
135136
if prevResultNode == nil || prevResultNode.Type() != ast.ListNode || prevResultNode.(*ast.List).Kind != listKind || prevResultNode.(*ast.List).Indent > indent {
136137
prevResultNode = &ast.List{
137138
BaseBlock: ast.BaseBlock{},
@@ -143,9 +144,12 @@ func mergeListItemNodes(nodes []ast.Node) []ast.Node {
143144
continue
144145
}
145146

146-
listNode := prevResultNode.(*ast.List)
147+
listNode, ok := prevResultNode.(*ast.List)
148+
if !ok {
149+
continue
150+
}
147151
if listNode.Indent != indent {
148-
parent := findPossibleParent(listNode, indent)
152+
parent := findListPossibleParent(listNode, indent)
149153
if parent == nil {
150154
parent = &ast.List{
151155
BaseBlock: ast.BaseBlock{},
@@ -190,7 +194,7 @@ func mergeTextNodes(nodes []ast.Node) []ast.Node {
190194
return result
191195
}
192196

193-
func findPossibleParent(listNode *ast.List, indent int) *ast.List {
197+
func findListPossibleParent(listNode *ast.List, indent int) *ast.List {
194198
if listNode.Indent == indent {
195199
return listNode
196200
}
@@ -204,5 +208,5 @@ func findPossibleParent(listNode *ast.List, indent int) *ast.List {
204208
if lastChild.Type() != ast.ListNode {
205209
return nil
206210
}
207-
return findPossibleParent(lastChild.(*ast.List), indent)
211+
return findListPossibleParent(lastChild.(*ast.List), indent)
208212
}

0 commit comments

Comments
 (0)