Skip to content

Commit d526b6b

Browse files
committed
Refactor code-style
1 parent 5743ee5 commit d526b6b

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const isElement =
7777
*/
7878
// eslint-disable-next-line max-params
7979
function (node, test, index, parent, context) {
80-
var check = convertElement(test)
80+
const check = convertElement(test)
8181

8282
if (
8383
index !== undefined &&
@@ -158,8 +158,8 @@ export const convertElement =
158158
*/
159159
function anyFactory(tests) {
160160
/** @type {Array.<AssertAnything>} */
161-
var checks = []
162-
var index = -1
161+
const checks = []
162+
let index = -1
163163

164164
while (++index < tests.length) {
165165
checks[index] = convertElement(tests[index])
@@ -173,7 +173,7 @@ function anyFactory(tests) {
173173
* @returns {boolean}
174174
*/
175175
function any(...parameters) {
176-
var index = -1
176+
let index = -1
177177

178178
while (++index < checks.length) {
179179
if (checks[index].call(this, ...parameters)) {

package.json

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

test.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
import test from 'tape'
77
import {isElement} from './index.js'
88

9-
test('isElement', function (t) {
9+
test('isElement', (t) => {
1010
t.equal(isElement(), false, 'should return `false` without node')
1111
t.equal(isElement(null), false, 'should return `false` with `null`')
1212

1313
t.throws(
14-
function () {
14+
() => {
1515
// @ts-ignore runtime.
1616
isElement(null, true)
1717
},
1818
/Expected function, string, or array as test/,
1919
'should throw when the second parameter is invalid'
2020
)
2121

22-
t.test('isElement(node)', function (st) {
22+
t.test('isElement(node)', (st) => {
2323
st.equal(
2424
isElement({type: 'text'}),
2525
false,
@@ -41,7 +41,7 @@ test('isElement', function (t) {
4141
st.end()
4242
})
4343

44-
t.test('isElement(node, tagName)', function (st) {
44+
t.test('isElement(node, tagName)', (st) => {
4545
st.equal(
4646
isElement({type: 'text'}, 'div'),
4747
false,
@@ -69,7 +69,7 @@ test('isElement', function (t) {
6969
st.end()
7070
})
7171

72-
t.test('isElement(node, tagNames)', function (st) {
72+
t.test('isElement(node, tagNames)', (st) => {
7373
st.equal(
7474
isElement({type: 'text'}, ['div']),
7575
false,
@@ -103,17 +103,17 @@ test('isElement', function (t) {
103103
st.end()
104104
})
105105

106-
t.test('isElement(node, test)', function (st) {
106+
t.test('isElement(node, test)', (st) => {
107107
st.equal(
108-
isElement({type: 'text'}, function () {
108+
isElement({type: 'text'}, () => {
109109
throw new Error('!')
110110
}),
111111
false,
112112
'should not call `test` if the given node is not an element'
113113
)
114114

115115
st.equal(
116-
isElement({type: 'element', tagName: 'a', children: []}, function (node) {
116+
isElement({type: 'element', tagName: 'a', children: []}, (node) => {
117117
return node.children.length === 0
118118
}),
119119
true,
@@ -123,16 +123,16 @@ test('isElement', function (t) {
123123
st.equal(
124124
isElement(
125125
{type: 'element', tagName: 'a', children: [{type: 'text'}]},
126-
function (node) {
126+
(node) => {
127127
return node.children.length === 0
128128
}
129129
),
130130
false,
131131
'should call `test` if the given node is a valid element (2)'
132132
)
133133

134-
var ctx = {}
135-
var root = {
134+
const ctx = {}
135+
const root = {
136136
type: 'root',
137137
children: [{type: 'element', tagName: 'a', children: []}]
138138
}
@@ -161,59 +161,59 @@ test('isElement', function (t) {
161161
)
162162

163163
st.throws(
164-
function () {
165-
isElement(root.children[0], function () {}, 0)
164+
() => {
165+
isElement(root.children[0], () => {}, 0)
166166
},
167167
/Expected both parent and index/,
168168
'should throw if `index` is passed but not `parent`'
169169
)
170170

171171
st.throws(
172-
function () {
173-
isElement(root.children[0], function () {}, undefined, root)
172+
() => {
173+
isElement(root.children[0], () => {}, undefined, root)
174174
},
175175
/Expected both parent and index/,
176176
'should throw if `parent` is passed but not `index`'
177177
)
178178

179179
st.throws(
180-
function () {
180+
() => {
181181
// @ts-ignore runtime.
182-
isElement(root.children[0], function () {}, false)
182+
isElement(root.children[0], () => {}, false)
183183
},
184184
/Expected positive finite index for child node/,
185185
'should throw if `index` is not a number'
186186
)
187187

188188
st.throws(
189-
function () {
190-
isElement(root.children[0], function () {}, -1)
189+
() => {
190+
isElement(root.children[0], () => {}, -1)
191191
},
192192
/Expected positive finite index for child node/,
193193
'should throw if `index` is negative'
194194
)
195195

196196
st.throws(
197-
function () {
198-
isElement(root.children[0], function () {}, Number.POSITIVE_INFINITY)
197+
() => {
198+
isElement(root.children[0], () => {}, Number.POSITIVE_INFINITY)
199199
},
200200
/Expected positive finite index for child node/,
201201
'should throw if `index` is infinity'
202202
)
203203

204204
st.throws(
205-
function () {
205+
() => {
206206
// @ts-ignore runtime.
207-
isElement(root.children[0], function () {}, 0, true)
207+
isElement(root.children[0], () => {}, 0, true)
208208
},
209209
/Expected parent node/,
210210
'should throw if `parent` is not a node'
211211
)
212212

213213
st.throws(
214-
function () {
214+
() => {
215215
// @ts-ignore runtime.
216-
isElement(root.children[0], function () {}, 0, {type: 'root'})
216+
isElement(root.children[0], () => {}, 0, {type: 'root'})
217217
},
218218
/Expected parent node/,
219219
'should throw if `parent` is not a parent'

0 commit comments

Comments
 (0)