Skip to content

Commit 14b0af0

Browse files
committed
Refactor code-style
1 parent 10b2c11 commit 14b0af0

File tree

4 files changed

+48
-53
lines changed

4 files changed

+48
-53
lines changed

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import {convert} from 'unist-util-is'
1616

1717
/** @type {Array.<Node>} */
18-
var empty = []
18+
const empty = []
1919

20-
export var remove =
20+
export const remove =
2121
/**
2222
* @type {(
2323
* (<T extends Node>(node: T, options: RemoveOptions, test: Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => T|null) &
@@ -35,8 +35,8 @@ export var remove =
3535
* @returns {Node|null}
3636
*/
3737
function (tree, options, test) {
38-
var is = convert(test || options)
39-
var cascade =
38+
const is = convert(test || options)
39+
const cascade =
4040
options.cascade === undefined || options.cascade === null
4141
? true
4242
: options.cascade
@@ -55,9 +55,9 @@ export var remove =
5555
function preorder(node, index, parent) {
5656
/** @type {Array.<Node>} */
5757
// @ts-ignore looks like a parent.
58-
var children = node.children || empty
59-
var childIndex = -1
60-
var position = 0
58+
const children = node.children || empty
59+
let childIndex = -1
60+
let position = 0
6161

6262
if (is(node, index, parent)) {
6363
return null

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@
7272
"trailingComma": "none"
7373
},
7474
"xo": {
75-
"prettier": true,
76-
"rules": {
77-
"import/no-mutable-exports": "off",
78-
"no-var": "off",
79-
"prefer-arrow-callback": "off"
80-
}
75+
"prettier": true
8176
},
8277
"remarkConfig": {
8378
"plugins": [

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ npm install unist-util-remove
2828
import {u} from 'unist-builder'
2929
import {remove} from 'unist-util-remove'
3030

31-
var tree = u('root', [
31+
const tree = u('root', [
3232
u('leaf', '1'),
3333
u('node', [
3434
u('leaf', '2'),

test.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import test from 'tape'
1212
import {u} from 'unist-builder'
1313
import {remove} from './index.js'
1414

15-
test('should compare nodes by partial properties', function (t) {
16-
var tree = u('node', [u('leaf', '1'), u('leaf', '2')])
17-
var children = tree.children
18-
var first = tree.children[0]
15+
test('should compare nodes by partial properties', (t) => {
16+
const tree = u('node', [u('leaf', '1'), u('leaf', '2')])
17+
const children = tree.children
18+
const first = tree.children[0]
1919

20-
var next = remove(tree, {value: '2'})
20+
const next = remove(tree, {value: '2'})
2121

2222
t.equal(next, tree)
2323
t.deepEqual(tree, u('node', [first]))
@@ -27,13 +27,13 @@ test('should compare nodes by partial properties', function (t) {
2727
t.end()
2828
})
2929

30-
test('should remove nodes with children', function (t) {
31-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
32-
var children = tree.children
33-
var first = tree.children[0]
34-
var last = tree.children[1]
30+
test('should remove nodes with children', (t) => {
31+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
32+
const children = tree.children
33+
const first = tree.children[0]
34+
const last = tree.children[1]
3535

36-
var next = remove(tree, test)
36+
const next = remove(tree, test)
3737

3838
t.equal(next, tree)
3939
t.deepEqual(tree, u('root', [last]))
@@ -51,22 +51,22 @@ test('should remove nodes with children', function (t) {
5151
}
5252
})
5353

54-
test('should return `null` if root node is removed', function (t) {
55-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
54+
test('should return `null` if root node is removed', (t) => {
55+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
5656

5757
t.equal(remove(tree, 'root'), null)
5858

5959
t.end()
6060
})
6161

62-
test('should cascade-remove parent nodes', function (t) {
63-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
64-
var children = tree.children
62+
test('should cascade-remove parent nodes', (t) => {
63+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
64+
const children = tree.children
6565
// @ts-ignore it exists!
66-
var first = children[0].children[0]
67-
var last = children[1]
66+
const first = children[0].children[0]
67+
const last = children[1]
6868

69-
var next = remove(tree, test)
69+
const next = remove(tree, test)
7070

7171
t.equal(next, tree)
7272
t.deepEqual(tree, u('root', [last]))
@@ -84,18 +84,18 @@ test('should cascade-remove parent nodes', function (t) {
8484
}
8585
})
8686

87-
test('should cascade-remove root nodes', function (t) {
88-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
87+
test('should cascade-remove root nodes', (t) => {
88+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
8989

90-
var next = remove(tree, 'leaf')
90+
const next = remove(tree, 'leaf')
9191

9292
t.equal(next, null)
9393

9494
t.end()
9595
})
9696

97-
test('should not cascade-remove nodes that were empty initially', function (t) {
98-
var tree = u('node', [u('node', []), u('node', [u('leaf')])])
97+
test('should not cascade-remove nodes that were empty initially', (t) => {
98+
const tree = u('node', [u('node', []), u('node', [u('leaf')])])
9999

100100
remove(tree, 'leaf')
101101

@@ -104,8 +104,8 @@ test('should not cascade-remove nodes that were empty initially', function (t) {
104104
t.end()
105105
})
106106

107-
test('should support type tests', function (t) {
108-
var tree = u('node', [u('node', [u('leaf', '1')]), u('leaf', '2')])
107+
test('should support type tests', (t) => {
108+
const tree = u('node', [u('node', [u('leaf', '1')]), u('leaf', '2')])
109109

110110
remove(tree, {cascade: false}, 'leaf')
111111

@@ -114,8 +114,8 @@ test('should support type tests', function (t) {
114114
t.end()
115115
})
116116

117-
test('should support function tests', function (t) {
118-
var tree = u('node', [u('node', [u('leaf', '1')]), u('leaf', '2')])
117+
test('should support function tests', (t) => {
118+
const tree = u('node', [u('node', [u('leaf', '1')]), u('leaf', '2')])
119119

120120
remove(tree, {cascade: false}, test)
121121

@@ -132,24 +132,24 @@ test('should support function tests', function (t) {
132132
}
133133
})
134134

135-
test('opts.cascade = true', function (t) {
136-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
135+
test('opts.cascade = true', (t) => {
136+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
137137

138-
var next = remove(tree, {cascade: true}, 'leaf')
138+
const next = remove(tree, {cascade: true}, 'leaf')
139139

140140
t.equal(next, null)
141141

142142
t.end()
143143
})
144144

145-
test('opts.cascade = false', function (t) {
146-
var tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
147-
var siblings = tree.children
148-
var node = siblings[0]
145+
test('opts.cascade = false', (t) => {
146+
const tree = u('root', [u('node', [u('leaf', '1')]), u('leaf', '2')])
147+
const siblings = tree.children
148+
const node = siblings[0]
149149
// @ts-ignore it exists!
150-
var children = node.children
150+
const children = node.children
151151

152-
var next = remove(tree, {cascade: false}, 'leaf')
152+
const next = remove(tree, {cascade: false}, 'leaf')
153153

154154
t.equal(next, tree)
155155
t.deepEqual(tree, u('root', [u('node', [])]))
@@ -161,8 +161,8 @@ test('opts.cascade = false', function (t) {
161161
t.end()
162162
})
163163

164-
test('example from readme', function (t) {
165-
var tree = u('root', [
164+
test('example from readme', (t) => {
165+
const tree = u('root', [
166166
u('leaf', '1'),
167167
u('node', [
168168
u('leaf', '2'),

0 commit comments

Comments
 (0)