Skip to content

Commit 749da41

Browse files
committed
Refactor code-style
1 parent 890150c commit 749da41

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* @typedef {import('./lib/index.js').Handler} Handler
3+
* @typedef {import('./lib/index.js').Info} Info
34
* @typedef {import('./lib/index.js').Options} Options
4-
* @typedef {import('./lib/index.js').TestFunction} TestFunction
55
* @typedef {import('./lib/index.js').Test} Test
6-
* @typedef {import('./lib/index.js').Info} Info
6+
* @typedef {import('./lib/index.js').TestFunction} TestFunction
77
*/
88

99
export {headingRange} from './lib/index.js'

lib/index.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* @typedef {import('mdast').Content} Content
23
* @typedef {import('mdast').Heading} Heading
34
* @typedef {import('mdast').Root} Root
45
* @typedef {import('unist').Node} UnistNode
@@ -89,27 +90,18 @@
8990
* Node to search for.
9091
*/
9192

92-
/**
93-
* @typedef {Child<Root, Parent<Root, Heading>>} Sibling
94-
* Collect nodes in `Tree` that can be parents of `Child`.
95-
* @template {UnistNode} Tree
96-
* All node types in a tree.
97-
* @template {UnistNode} Node
98-
* Node to search for.
99-
*/
100-
10193
/**
10294
* @callback Handler
10395
* Callback called when a section is found.
10496
* @param {Heading} start
10597
* Start of section (a heading node matching `test`).
106-
* @param {Array<Sibling<Root, Heading>>} between
98+
* @param {Array<Content>} between
10799
* Nodes between `start` and `end`.
108-
* @param {Sibling<Root, Heading> | undefined} end
100+
* @param {Content | undefined} end
109101
* End of section, if any.
110102
* @param {Info} scope
111103
* Extra info.
112-
* @returns {Array<Sibling<Root, Heading> | null | undefined> | null | undefined | void}
104+
* @returns {Array<Content | null | undefined> | null | undefined | void}
113105
* Results.
114106
*
115107
* If nothing is returned, nothing will be changed.
@@ -176,8 +168,6 @@ import {toString} from 'mdast-util-to-string'
176168
// eslint-disable-next-line complexity
177169
export function headingRange(tree, options, handler) {
178170
let test = options
179-
// To do: smarter types to allow siblings of headings.
180-
/** @type {Array<Sibling<Root, Heading>>} */
181171
const children = 'children' in tree ? tree.children : []
182172
let ignoreFinalDefinitions = false
183173

@@ -260,7 +250,7 @@ export function headingRange(tree, options, handler) {
260250
if (nodes) {
261251
// Ensure no empty nodes are inserted.
262252
// This could be the case if `end` is in `nodes` but no `end` node exists.
263-
/** @type {Array<Sibling<Root, Heading>>} */
253+
/** @type {Array<Content>} */
264254
const result = []
265255
let index = -1
266256

test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function checkAndRemove(value, options) {
338338

339339
headingRange(tree, options, function (start, _, end, scope) {
340340
assert.equal(typeof scope.start, 'number')
341-
assert.ok(typeof scope.end === 'number' || scope.end === null)
341+
assert.ok(typeof scope.end === 'number' || scope.end === undefined)
342342
assert.equal(scope.parent && scope.parent.type, 'root')
343343
return [start, end]
344344
})

0 commit comments

Comments
 (0)