Skip to content

Commit 9dc1e50

Browse files
committed
Refactor code-style
1 parent bfafa4b commit 9dc1e50

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* @returns {node is Y}
4949
*/
5050

51-
export var is =
51+
export const is =
5252
/**
5353
* Check if a node passes a test.
5454
* When a `parent` node is known the `index` of node should also be given.
@@ -77,7 +77,7 @@ export var is =
7777
*/
7878
// eslint-disable-next-line max-params
7979
function is(node, test, index, parent, context) {
80-
var check = convert(test)
80+
const check = convert(test)
8181

8282
if (
8383
index !== undefined &&
@@ -111,7 +111,7 @@ export var is =
111111
}
112112
)
113113

114-
export var convert =
114+
export const convert =
115115
/**
116116
* @type {(
117117
* (<T extends Node>(test: T['type']|Partial<T>|TestFunctionPredicate<T>) => AssertPredicate<T>) &
@@ -139,8 +139,7 @@ export var convert =
139139
}
140140

141141
if (typeof test === 'object') {
142-
// @ts-ignore looks like a list of tests / partial test object.
143-
return 'length' in test ? anyFactory(test) : propsFactory(test)
142+
return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
144143
}
145144

146145
if (typeof test === 'function') {
@@ -156,8 +155,8 @@ export var convert =
156155
*/
157156
function anyFactory(tests) {
158157
/** @type {Array.<AssertAnything>} */
159-
var checks = []
160-
var index = -1
158+
const checks = []
159+
let index = -1
161160

162161
while (++index < tests.length) {
163162
checks[index] = convert(tests[index])
@@ -171,7 +170,7 @@ function anyFactory(tests) {
171170
* @returns {boolean}
172171
*/
173172
function any(...parameters) {
174-
var index = -1
173+
let index = -1
175174

176175
while (++index < checks.length) {
177176
if (checks[index].call(this, ...parameters)) return true
@@ -195,7 +194,7 @@ function propsFactory(check) {
195194
*/
196195
function all(node) {
197196
/** @type {string} */
198-
var key
197+
let key
199198

200199
for (key in check) {
201200
if (node[key] !== check[key]) return

package.json

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

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ npm install unist-util-is
2626
```js
2727
import {is} from 'unist-util-is'
2828

29-
var node = {type: 'strong'}
30-
var parent = {type: 'paragraph', children: [node]}
29+
const node = {type: 'strong'}
30+
const parent = {type: 'paragraph', children: [node]}
3131

3232
function test(node, n) {
3333
return n === 5

test/main.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import {is} from '../index.js'
66
* @typedef {import('unist').Parent} Parent
77
*/
88

9-
test('unist-util-is', function (t) {
10-
var node = {type: 'strong'}
11-
var parent = {type: 'paragraph', children: []}
9+
test('unist-util-is', (t) => {
10+
const node = {type: 'strong'}
11+
const parent = {type: 'paragraph', children: []}
1212

1313
t.throws(
14-
function () {
14+
() => {
1515
// @ts-ignore runtime.
1616
is(null, false)
1717
},
@@ -20,23 +20,23 @@ test('unist-util-is', function (t) {
2020
)
2121

2222
t.throws(
23-
function () {
23+
() => {
2424
is(node, null, -1, parent)
2525
},
2626
/Expected positive finite index/,
2727
'should throw when `index` is invalid (#1)'
2828
)
2929

3030
t.throws(
31-
function () {
31+
() => {
3232
is(node, null, Number.POSITIVE_INFINITY, parent)
3333
},
3434
/Expected positive finite index/,
3535
'should throw when `index` is invalid (#2)'
3636
)
3737

3838
t.throws(
39-
function () {
39+
() => {
4040
// @ts-ignore runtime.
4141
is(node, null, false, parent)
4242
},
@@ -45,7 +45,7 @@ test('unist-util-is', function (t) {
4545
)
4646

4747
t.throws(
48-
function () {
48+
() => {
4949
// @ts-ignore runtime.
5050
is(node, null, 0, {})
5151
},
@@ -54,7 +54,7 @@ test('unist-util-is', function (t) {
5454
)
5555

5656
t.throws(
57-
function () {
57+
() => {
5858
// @ts-ignore runtime.
5959
is(node, null, 0, {type: 'paragraph'})
6060
},
@@ -63,15 +63,15 @@ test('unist-util-is', function (t) {
6363
)
6464

6565
t.throws(
66-
function () {
66+
() => {
6767
is(node, null, 0)
6868
},
6969
/Expected both parent and index/,
7070
'should throw `parent` xor `index` are given (#1)'
7171
)
7272

7373
t.throws(
74-
function () {
74+
() => {
7575
is(node, null, null, parent)
7676
},
7777
/Expected both parent and index/,
@@ -89,7 +89,7 @@ test('unist-util-is', function (t) {
8989
t.ok(is(parent, {type: 'paragraph'}), 'should match partially (#3)')
9090
t.notok(is(node, {type: 'paragraph'}), 'should match partially (#4)')
9191

92-
t.test('should accept a test', function (t) {
92+
t.test('should accept a test', (t) => {
9393
/**
9494
* @param {unknown} _
9595
* @param {number} n
@@ -106,8 +106,8 @@ test('unist-util-is', function (t) {
106106
t.end()
107107
})
108108

109-
t.test('should invoke test', function (t) {
110-
var context = {foo: 'bar'}
109+
t.test('should invoke test', (t) => {
110+
const context = {foo: 'bar'}
111111

112112
t.plan(4)
113113

@@ -130,8 +130,8 @@ test('unist-util-is', function (t) {
130130
t.ok(is(node, ['strong', 'emphasis']), 'should match arrays (#1)')
131131
t.notok(is(node, ['b', 'i']), 'should match arrays (#2)')
132132

133-
t.test('should match arrays (#3)', function (t) {
134-
var context = {foo: 'bar'}
133+
t.test('should match arrays (#3)', (t) => {
134+
const context = {foo: 'bar'}
135135

136136
t.plan(5)
137137

test/property.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fc from 'fast-check'
33
import lodash from 'lodash'
44
import {is} from '../index.js'
55

6-
var {isObject, isPlainObject, pick, cloneDeep} = lodash
6+
const {isObject, isPlainObject, pick, cloneDeep} = lodash
77

88
test('unist-util-is properties', (t) => {
99
t.plan(4)

0 commit comments

Comments
 (0)