Skip to content

Commit 21810d7

Browse files
committed
Change to yield undefined
1 parent 26dc4ad commit 21810d7

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

lib/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@
55
import {headingRank} from 'hast-util-heading-rank'
66
import {visit} from 'unist-util-visit'
77

8-
// To do next major: don’t return node.
98
/**
109
* Change the rank of all headings (`h1` to `h6`) in `tree`.
1110
*
1211
* Mutates the tree.
1312
* Caps the rank so that shifting would not create invalid headings (so no `h0` or
1413
* `h7`).
1514
*
16-
* @template {Nodes} T
17-
* Node type.
18-
* @param {T} tree
15+
* @param {Nodes} tree
1916
* Tree to change.
2017
* @param {number} shift
2118
* Non-null finite integer to use to shift ranks.
22-
* @returns {T}
23-
* Given, modified, tree.
19+
* @returns {undefined}
20+
* Nothing.
2421
* @throws
2522
* When `shift` is not a valid non-null finite integer.
2623
*/
@@ -42,6 +39,4 @@ export function shiftHeading(tree, shift) {
4239
node.tagName = 'h' + (rank > 6 ? 6 : rank < 1 ? 1 : rank)
4340
}
4441
})
45-
46-
return tree
4742
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Caps the rank so that shifting would not create invalid headings (so no `h0` or
140140

141141
###### Returns
142142

143-
Given, modified, tree ([`Node`][node]).
143+
Nothing (`undefined`).
144144

145145
###### Throws
146146

test.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,38 @@ test('shiftHeading', async function (t) {
4848
)
4949

5050
await t.test('should shift nodes upwards', async function () {
51-
assert.deepEqual(shiftHeading(h('h1', 'Alpha'), 1), h('h2', 'Alpha'))
51+
const tree = h('h1', 'Alpha')
52+
shiftHeading(tree, 1)
53+
assert.deepEqual(tree, h('h2', 'Alpha'))
5254
})
5355

5456
await t.test('should shift nodes downwards', async function () {
55-
assert.deepEqual(shiftHeading(h('h2', 'Bravo'), -1), h('h1', 'Bravo'))
57+
const tree = h('h2', 'Bravo')
58+
shiftHeading(tree, -1)
59+
assert.deepEqual(tree, h('h1', 'Bravo'))
5660
})
5761

5862
await t.test('should not shift upwards past h1', async function () {
59-
assert.deepEqual(shiftHeading(h('h2', 'Charlie'), -2), h('h1', 'Charlie'))
63+
const tree = h('h2', 'Charlie')
64+
shiftHeading(tree, -2)
65+
assert.deepEqual(tree, h('h1', 'Charlie'))
6066
})
6167

6268
await t.test('should not shift downwards past h6', async function () {
63-
assert.deepEqual(shiftHeading(h('h5', 'Delta'), 2), h('h6', 'Delta'))
69+
const tree = h('h5', 'Delta')
70+
shiftHeading(tree, 2)
71+
assert.deepEqual(tree, h('h6', 'Delta'))
6472
})
6573

6674
await t.test('should change a tree', async function () {
75+
const tree = h('main', [
76+
h('h1', 'Echo'),
77+
h('p', 'Foxtrot'),
78+
h('h5', 'Golf')
79+
])
80+
shiftHeading(tree, 2)
6781
assert.deepEqual(
68-
shiftHeading(
69-
h('main', [h('h1', 'Echo'), h('p', 'Foxtrot'), h('h5', 'Golf')]),
70-
2
71-
),
82+
tree,
7283
h('main', [h('h3', 'Echo'), h('p', 'Foxtrot'), h('h6', 'Golf')])
7384
)
7485
})

0 commit comments

Comments
 (0)