Skip to content

Commit 51eff15

Browse files
committed
Refactor code-style
1 parent b8f403e commit 51eff15

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

Diff for: index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import {convert} from 'unist-util-is'
1111

12-
export var findBefore =
12+
export const findBefore =
1313
/**
1414
* @type {(
1515
* (<T extends Node>(node: Parent, index: Node|number, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>) => T|null) &
@@ -24,7 +24,7 @@ export var findBefore =
2424
* @returns {Node|null}
2525
*/
2626
function (parent, index, test) {
27-
var is = convert(test)
27+
const is = convert(test)
2828

2929
if (!parent || !parent.type || !parent.children) {
3030
throw new Error('Expected parent node')

Diff for: package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,7 @@
6464
"trailingComma": "none"
6565
},
6666
"xo": {
67-
"prettier": true,
68-
"rules": {
69-
"import/no-mutable-exports": "off",
70-
"no-var": "off",
71-
"prefer-arrow-callback": "off"
72-
}
67+
"prettier": true
7368
},
7469
"remarkConfig": {
7570
"plugins": [

Diff for: readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm install unist-util-find-before
2727
import {u} from 'unist-builder'
2828
import {findBefore} from 'unist-util-find-before'
2929

30-
var tree = u('tree', [
30+
const tree = u('tree', [
3131
u('leaf', 'leaf 1'),
3232
u('node', [u('leaf', 'leaf 2'), u('leaf', 'leaf 3')]),
3333
u('leaf', 'leaf 4'),
@@ -37,7 +37,7 @@ var tree = u('tree', [
3737
u('leaf', 'leaf 7')
3838
])
3939

40-
var empty = tree.children[5]
40+
const empty = tree.children[5]
4141

4242
console.log(findBefore(tree, empty, 'node'))
4343
```

Diff for: test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import test from 'tape'
88
import remark from 'remark'
99
import {findBefore} from './index.js'
1010

11-
test('unist-util-find-before', function (t) {
11+
test('unist-util-find-before', (t) => {
1212
/** @type {Root} */
1313
// @ts-expect-error: fine.
14-
var tree = remark().parse('Some *emphasis*, **importance**, and `code`.')
14+
const tree = remark().parse('Some *emphasis*, **importance**, and `code`.')
1515

1616
assert(tree.type === 'root')
17-
var paragraph = tree.children[0]
17+
const paragraph = tree.children[0]
1818
assert(paragraph.type === 'paragraph')
19-
var head = paragraph.children[0]
19+
const head = paragraph.children[0]
2020
assert(head.type === 'text')
21-
var next = paragraph.children[1]
21+
const next = paragraph.children[1]
2222
assert(next.type === 'emphasis')
2323

2424
t.throws(
25-
function () {
25+
() => {
2626
// @ts-ignore runtime
2727
findBefore()
2828
},
@@ -31,7 +31,7 @@ test('unist-util-find-before', function (t) {
3131
)
3232

3333
t.throws(
34-
function () {
34+
() => {
3535
// @ts-ignore runtime
3636
findBefore({type: 'foo'})
3737
},
@@ -40,7 +40,7 @@ test('unist-util-find-before', function (t) {
4040
)
4141

4242
t.throws(
43-
function () {
43+
() => {
4444
// @ts-ignore runtime
4545
findBefore({type: 'foo', children: []})
4646
},
@@ -49,23 +49,23 @@ test('unist-util-find-before', function (t) {
4949
)
5050

5151
t.throws(
52-
function () {
52+
() => {
5353
findBefore({type: 'foo', children: []}, -1)
5454
},
5555
/Expected positive finite number as index/,
5656
'should fail without index (#2)'
5757
)
5858

5959
t.throws(
60-
function () {
60+
() => {
6161
findBefore({type: 'foo', children: []}, {type: 'bar'})
6262
},
6363
/Expected child node or index/,
6464
'should fail without index (#3)'
6565
)
6666

6767
t.throws(
68-
function () {
68+
() => {
6969
// @ts-ignore runtime
7070
findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, false)
7171
},
@@ -74,7 +74,7 @@ test('unist-util-find-before', function (t) {
7474
)
7575

7676
t.throws(
77-
function () {
77+
() => {
7878
// @ts-ignore runtime
7979
findBefore({type: 'foo', children: [{type: 'bar'}]}, 1, true)
8080
},

0 commit comments

Comments
 (0)