Skip to content

Commit 3732e98

Browse files
committed
Refactor code-style
1 parent 6f7b407 commit 3732e98

File tree

10 files changed

+174
-161
lines changed

10 files changed

+174
-161
lines changed

lib/any.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {pseudo} from './pseudo.js'
1717
import {test} from './test.js'
1818
import {root} from './util.js'
1919

20-
var type = zwitch('type', {
20+
const type = zwitch('type', {
2121
// @ts-expect-error: hush.
2222
unknown: unknownType,
2323
invalid: invalidType,
@@ -42,8 +42,8 @@ export function any(query, node, state) {
4242
* @param {SelectState} state
4343
*/
4444
function selectors(query, node, state) {
45-
var collect = collector(state.one)
46-
var index = -1
45+
const collect = collector(state.one)
46+
let index = -1
4747

4848
while (++index < query.selectors.length) {
4949
collect(ruleSet(query.selectors[index], node, state))
@@ -67,7 +67,7 @@ function ruleSet(query, node, state) {
6767
* @param {SelectState} state
6868
*/
6969
function rule(query, tree, state) {
70-
var collect = collector(state.one)
70+
const collect = collector(state.one)
7171

7272
if (state.shallow && query.rule) {
7373
throw new Error('Expected selector without nesting')
@@ -110,8 +110,8 @@ function rule(query, tree, state) {
110110
* @returns {S}
111111
*/
112112
function configure(query, state) {
113-
var pseudos = query.pseudos || []
114-
var index = -1
113+
const pseudos = query.pseudos || []
114+
let index = -1
115115

116116
while (++index < pseudos.length) {
117117
if (pseudo.needsIndex.includes(pseudos[index].name)) {
@@ -143,9 +143,9 @@ function invalidType() {
143143
*/
144144
function collector(one) {
145145
/** @type {Array.<Node>} */
146-
var result = []
146+
const result = []
147147
/** @type {boolean} */
148-
var found
148+
let found
149149

150150
collect.result = result
151151

@@ -157,7 +157,7 @@ function collector(one) {
157157
* @param {Node|Array.<Node>} node
158158
*/
159159
function collect(node) {
160-
var index = -1
160+
let index = -1
161161

162162
if ('length' in node) {
163163
while (++index < node.length) {

lib/attribute.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import {zwitch} from 'zwitch'
88

9-
var handle = zwitch('operator', {
9+
const handle = zwitch('operator', {
1010
// @ts-expect-error: hush.
1111
unknown: unknownOperator,
1212
// @ts-expect-error: hush.
@@ -30,7 +30,7 @@ var handle = zwitch('operator', {
3030
* @param {Node} node
3131
*/
3232
export function attribute(query, node) {
33-
var index = -1
33+
let index = -1
3434

3535
while (++index < query.attrs.length) {
3636
if (!handle(query.attrs[index], node)) return false
@@ -70,7 +70,7 @@ function exact(query, node) {
7070
function containsArray(query, node) {
7171
/** @type {unknown} */
7272
// @ts-expect-error: Looks like a record.
73-
var value = node[query.name]
73+
const value = node[query.name]
7474

7575
if (value === null || value === undefined) return false
7676

@@ -95,7 +95,7 @@ function containsArray(query, node) {
9595
function begins(query, node) {
9696
/** @type {unknown} */
9797
// @ts-expect-error: Looks like a record.
98-
var value = node[query.name]
98+
const value = node[query.name]
9999

100100
return (
101101
query.value &&
@@ -113,7 +113,7 @@ function begins(query, node) {
113113
function ends(query, node) {
114114
/** @type {unknown} */
115115
// @ts-expect-error: Looks like a record.
116-
var value = node[query.name]
116+
const value = node[query.name]
117117

118118
return (
119119
query.value &&
@@ -131,7 +131,7 @@ function ends(query, node) {
131131
function containsString(query, node) {
132132
/** @type {unknown} */
133133
// @ts-expect-error: Looks like a record.
134-
var value = node[query.name]
134+
const value = node[query.name]
135135
return query.value && typeof value === 'string' && value.includes(query.value)
136136
}
137137

lib/nest.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import {zwitch} from 'zwitch'
1212
import {parent} from './util.js'
1313

14-
var own = {}.hasOwnProperty
14+
const own = {}.hasOwnProperty
1515

16-
var handle = zwitch('nestingOperator', {
16+
const handle = zwitch('nestingOperator', {
1717
// @ts-expect-error: hush.
1818
unknown: unknownNesting,
1919
// @ts-expect-error: hush.
@@ -72,7 +72,7 @@ function descendant(query, node, index, parent, state) {
7272
throw new Error('Expected `iterator` to be defined')
7373
}
7474

75-
var previous = state.iterator
75+
const previous = state.iterator
7676

7777
state.iterator = iterator
7878
child(query, node, index, parent, state)
@@ -161,7 +161,7 @@ class WalkIterator {
161161
* @returns {this}
162162
*/
163163
prefillTypeIndex(x, y) {
164-
var [start, end] = this.defaults(x, y)
164+
let [start, end] = this.defaults(x, y)
165165

166166
if (this.typeIndex) {
167167
while (start < end) {
@@ -179,12 +179,12 @@ class WalkIterator {
179179
* @returns {this}
180180
*/
181181
each(x, y) {
182-
var [start, end] = this.defaults(x, y)
183-
var child = this.parent.children[start]
182+
const [start, end] = this.defaults(x, y)
183+
const child = this.parent.children[start]
184184
/** @type {number} */
185-
var index
185+
let index
186186
/** @type {number} */
187-
var nodeIndex
187+
let nodeIndex
188188

189189
if (start >= end) return this
190190

@@ -236,7 +236,7 @@ class WalkIterator {
236236
* @returns {this}
237237
*/
238238
done() {
239-
var index = -1
239+
let index = -1
240240

241241
while (++index < this.delayed.length) {
242242
this.delayed[index].call(this)
@@ -272,7 +272,7 @@ class TypeIndex {
272272
* @returns {number}
273273
*/
274274
index(node) {
275-
var type = node.type
275+
const type = node.type
276276

277277
this.nodes++
278278

lib/parse.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ import {zwitch} from 'zwitch'
1313

1414
/** @type {import('nth-check').default} */
1515
// @ts-expect-error
16-
var nthCheck = fauxEsmNthCheck.default
16+
const nthCheck = fauxEsmNthCheck.default
1717

18-
var nth = new Set([
18+
const nth = new Set([
1919
'nth-child',
2020
'nth-last-child',
2121
'nth-of-type',
2222
'nth-last-of-type'
2323
])
2424

25-
var parser = new CssSelectorParser()
25+
const parser = new CssSelectorParser()
2626

2727
parser.registerAttrEqualityMods('~', '^', '$', '*')
2828
parser.registerSelectorPseudos('any', 'matches', 'not', 'has')
2929
parser.registerNestingOperators('>', '+', '~')
3030

3131
// @ts-expect-error: hush.
32-
var compile = zwitch('type', {handlers: {selectors, ruleSet, rule}})
32+
const compile = zwitch('type', {handlers: {selectors, ruleSet, rule}})
3333

3434
/**
3535
* @param {string} selector
@@ -48,8 +48,8 @@ export function parse(selector) {
4848
* @param {Selectors} query
4949
*/
5050
function selectors(query) {
51-
var selectors = query.selectors
52-
var index = -1
51+
const selectors = query.selectors
52+
let index = -1
5353

5454
while (++index < selectors.length) {
5555
compile(selectors[index])
@@ -69,10 +69,10 @@ function ruleSet(query) {
6969
* @param {Rule} query
7070
*/
7171
function rule(query) {
72-
var pseudos = query.pseudos || []
73-
var index = -1
72+
const pseudos = query.pseudos || []
73+
let index = -1
7474
/** @type {RulePseudo|RulePseudoNth} */
75-
var pseudo
75+
let pseudo
7676

7777
while (++index < pseudos.length) {
7878
pseudo = pseudos[index]

lib/pseudo.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {zwitch} from 'zwitch'
1414
import {convert} from 'unist-util-is'
1515
import {parent} from './util.js'
1616

17-
var is = convert()
17+
const is = convert()
1818

19-
var handle = zwitch('name', {
19+
const handle = zwitch('name', {
2020
// @ts-expect-error: hush.
2121
unknown: unknownPseudo,
2222
invalid: invalidPseudo,
@@ -82,8 +82,8 @@ pseudo.needsIndex = [
8282
* @returns {boolean}
8383
*/
8484
export function pseudo(query, node, index, parent, state) {
85-
var pseudos = query.pseudos
86-
var offset = -1
85+
const pseudos = query.pseudos
86+
let offset = -1
8787

8888
while (++offset < pseudos.length) {
8989
if (!handle(pseudos[offset], node, index, parent, state)) return false
@@ -101,15 +101,13 @@ export function pseudo(query, node, index, parent, state) {
101101
* @returns {boolean}
102102
*/
103103
function matches(query, node, _1, _2, state) {
104-
var shallow = state.shallow
105-
var one = state.one
106-
/** @type {boolean} */
107-
var result
104+
const shallow = state.shallow
105+
const one = state.one
108106

109107
state.one = true
110108
state.shallow = true
111109

112-
result = state.any(query.value, node, state)[0] === node
110+
const result = state.any(query.value, node, state)[0] === node
113111

114112
state.shallow = shallow
115113
state.one = one
@@ -346,19 +344,17 @@ function assertDeep(state, query) {
346344
* @returns {boolean}
347345
*/
348346
function hasSelector(query, node, _1, _2, state) {
349-
var shallow = state.shallow
350-
var one = state.one
351-
var scopeNodes = state.scopeNodes
352-
var value = appendScope(query.value)
353-
var anything = state.any
354-
/** @type {boolean} */
355-
var result
347+
const shallow = state.shallow
348+
const one = state.one
349+
const scopeNodes = state.scopeNodes
350+
const value = appendScope(query.value)
351+
const anything = state.any
356352

357353
state.shallow = false
358354
state.one = true
359355
state.scopeNodes = [node]
360356

361-
result = Boolean(anything(value, node, state)[0])
357+
const result = Boolean(anything(value, node, state)[0])
362358

363359
state.shallow = shallow
364360
state.one = one
@@ -372,11 +368,11 @@ function hasSelector(query, node, _1, _2, state) {
372368
*/
373369
function appendScope(value) {
374370
/** @type {Selectors} */
375-
var selector =
371+
const selector =
376372
value.type === 'ruleSet' ? {type: 'selectors', selectors: [value]} : value
377-
var index = -1
373+
let index = -1
378374
/** @type {Rule} */
379-
var rule
375+
let rule
380376

381377
while (++index < selector.selectors.length) {
382378
rule = selector.selectors[index].rule

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,7 @@
8585
"xo": {
8686
"prettier": true,
8787
"rules": {
88-
"no-var": "off",
89-
"prefer-arrow-callback": "off",
90-
"max-params": "off",
91-
"unicorn/no-array-for-each": "off"
88+
"max-params": "off"
9289
}
9390
},
9491
"remarkConfig": {

test/all.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'tape'
22
import {u} from 'unist-builder'
33
import {selectAll} from '../index.js'
44

5-
test('all together now', function (t) {
5+
test('all together now', (t) => {
66
t.deepEqual(
77
selectAll(
88
'a > b[d]:nth-of-type(odd)',

0 commit comments

Comments
 (0)