Skip to content

Commit c83d4fc

Browse files
committed
Refactor code-style
1 parent 8d7f081 commit c83d4fc

File tree

3 files changed

+67
-65
lines changed

3 files changed

+67
-65
lines changed

package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@
6767
"trailingComma": "none"
6868
},
6969
"xo": {
70-
"prettier": true,
71-
"rules": {
72-
"no-var": "off",
73-
"prefer-arrow-callback": "off"
74-
}
70+
"prettier": true
7571
},
7672
"remarkConfig": {
7773
"plugins": [

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ npm install unist-util-modify-children
2727
import u from 'unist-builder'
2828
import {modifyChildren} from 'unist-util-modify-children'
2929

30-
var modify = modifyChildren(modifier)
30+
const modify = modifyChildren(modifier)
3131

32-
var tree = u('root', [
32+
const tree = u('root', [
3333
u('leaf', '1'),
3434
u('node', [u('leaf', '2')]),
3535
u('leaf', '3')

test.js

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {modifyChildren} from './index.js'
88

99
function noop() {}
1010

11-
test('modifyChildren()', function (t) {
11+
test('modifyChildren()', (t) => {
1212
t.throws(
13-
function () {
13+
() => {
1414
// @ts-expect-error runtime.
1515
modifyChildren(noop)()
1616
},
@@ -19,25 +19,25 @@ test('modifyChildren()', function (t) {
1919
)
2020

2121
t.throws(
22-
function () {
22+
() => {
2323
// @ts-expect-error runtime.
2424
modifyChildren(noop)({})
2525
},
2626
/Missing children in `parent`/,
2727
'should throw without parent'
2828
)
2929

30-
t.test('should invoke `fn` for each child in `parent`', function (st) {
31-
var children = [
30+
t.test('should invoke `fn` for each child in `parent`', (st) => {
31+
const children = [
3232
{type: 'x', value: 0},
3333
{type: 'x', value: 1},
3434
{type: 'x', value: 2},
3535
{type: 'x', value: 3}
3636
]
37-
var context = {type: 'y', children}
38-
var n = -1
37+
const context = {type: 'y', children}
38+
let n = -1
3939

40-
modifyChildren(function (child, index, parent) {
40+
modifyChildren((child, index, parent) => {
4141
n++
4242
st.strictEqual(child, children[n])
4343
st.strictEqual(index, n)
@@ -47,8 +47,8 @@ test('modifyChildren()', function (t) {
4747
st.end()
4848
})
4949

50-
t.test('should work when new children are added', function (st) {
51-
var children = [
50+
t.test('should work when new children are added', (st) => {
51+
const children = [
5252
{type: 'x', value: 0},
5353
{type: 'x', value: 1},
5454
{type: 'x', value: 2},
@@ -57,22 +57,24 @@ test('modifyChildren()', function (t) {
5757
{type: 'x', value: 5},
5858
{type: 'x', value: 6}
5959
]
60-
var n = -1
61-
62-
modifyChildren(function (
63-
/** @type {ExampleLiteral} */ child,
64-
index,
65-
/** @type {ExampleParent} */ parent
66-
) {
67-
n++
68-
69-
if (index < 3) {
70-
parent.children.push({type: 'x', value: parent.children.length})
60+
let n = -1
61+
62+
modifyChildren(
63+
(
64+
/** @type {ExampleLiteral} */ child,
65+
index,
66+
/** @type {ExampleParent} */ parent
67+
) => {
68+
n++
69+
70+
if (index < 3) {
71+
parent.children.push({type: 'x', value: parent.children.length})
72+
}
73+
74+
st.deepEqual(child, children[n])
75+
st.deepEqual(index, n)
7176
}
72-
73-
st.deepEqual(child, children[n])
74-
st.deepEqual(index, n)
75-
})(
77+
)(
7678
/** @type {ExampleParent} */ ({
7779
type: 'y',
7880
children: [
@@ -87,15 +89,15 @@ test('modifyChildren()', function (t) {
8789
st.end()
8890
})
8991

90-
t.test('should skip forwards', function (st) {
91-
var children = [
92+
t.test('should skip forwards', (st) => {
93+
const children = [
9294
{type: 'x', value: 0},
9395
{type: 'x', value: 1},
9496
{type: 'x', value: 2},
9597
{type: 'x', value: 3}
9698
]
97-
var n = -1
98-
var context = {
99+
let n = -1
100+
const context = {
99101
type: 'y',
100102
children: [
101103
{type: 'x', value: 0},
@@ -104,26 +106,28 @@ test('modifyChildren()', function (t) {
104106
]
105107
}
106108

107-
modifyChildren(function (
108-
/** @type {ExampleLiteral} */ child,
109-
index,
110-
/** @type {ExampleParent} */ parent
111-
) {
112-
st.deepEqual(child, children[++n])
113-
114-
if (child.value === 1) {
115-
parent.children.splice(index + 1, 0, {type: 'x', value: 2})
116-
return index + 1
109+
modifyChildren(
110+
(
111+
/** @type {ExampleLiteral} */ child,
112+
index,
113+
/** @type {ExampleParent} */ parent
114+
) => {
115+
st.deepEqual(child, children[++n])
116+
117+
if (child.value === 1) {
118+
parent.children.splice(index + 1, 0, {type: 'x', value: 2})
119+
return index + 1
120+
}
117121
}
118-
})(context)
122+
)(context)
119123

120124
st.deepEqual(context.children, children)
121125

122126
st.end()
123127
})
124128

125-
t.test('should skip backwards', function (st) {
126-
var calls = [
129+
t.test('should skip backwards', (st) => {
130+
const calls = [
127131
{type: 'x', value: 0},
128132
{type: 'x', value: 1},
129133
{type: 'x', value: -1},
@@ -132,8 +136,8 @@ test('modifyChildren()', function (t) {
132136
{type: 'x', value: 2},
133137
{type: 'x', value: 3}
134138
]
135-
var n = -1
136-
var context = {
139+
let n = -1
140+
const context = {
137141
type: 'y',
138142
children: [
139143
{type: 'x', value: 0},
@@ -142,21 +146,23 @@ test('modifyChildren()', function (t) {
142146
{type: 'x', value: 3}
143147
]
144148
}
145-
var inserted = false
146-
147-
modifyChildren(function (
148-
/** @type {ExampleLiteral} */ child,
149-
_,
150-
/** @type {ExampleParent} */ parent
151-
) {
152-
st.deepEqual(child, calls[++n])
153-
154-
if (!inserted && child.value === 1) {
155-
inserted = true
156-
parent.children.unshift({type: 'x', value: -1})
157-
return -1
149+
let inserted = false
150+
151+
modifyChildren(
152+
(
153+
/** @type {ExampleLiteral} */ child,
154+
_,
155+
/** @type {ExampleParent} */ parent
156+
) => {
157+
st.deepEqual(child, calls[++n])
158+
159+
if (!inserted && child.value === 1) {
160+
inserted = true
161+
parent.children.unshift({type: 'x', value: -1})
162+
return -1
163+
}
158164
}
159-
})(context)
165+
)(context)
160166

161167
st.deepEqual(context.children, [
162168
{type: 'x', value: -1},

0 commit comments

Comments
 (0)