Skip to content

Commit 49571df

Browse files
committed
Refactor code-style
1 parent f9c6ae3 commit 49571df

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

Diff for: index.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import escape from 'escape-string-regexp'
3636
import {visitParents} from 'unist-util-visit-parents'
3737
import {convert} from 'unist-util-is'
3838

39-
var own = {}.hasOwnProperty
39+
const own = {}.hasOwnProperty
4040

4141
/**
4242
* @param tree mdast tree
@@ -64,9 +64,9 @@ export const findAndReplace =
6464
*/
6565
function (tree, find, replace, options) {
6666
/** @type {Options} */
67-
var settings
67+
let settings
6868
/** @type {FindAndReplaceSchema|FindAndReplaceList} */
69-
var schema
69+
let schema
7070

7171
if (typeof find === 'string' || find instanceof RegExp) {
7272
// @ts-expect-error don’t expect options twice.
@@ -82,9 +82,9 @@ export const findAndReplace =
8282
settings = {}
8383
}
8484

85-
var ignored = convert(settings.ignore || [])
86-
var pairs = toPairs(schema)
87-
var pairIndex = -1
85+
const ignored = convert(settings.ignore || [])
86+
const pairs = toPairs(schema)
87+
let pairIndex = -1
8888

8989
while (++pairIndex < pairs.length) {
9090
visitParents(tree, 'text', visitor)
@@ -94,11 +94,11 @@ export const findAndReplace =
9494

9595
/** @type {import('unist-util-visit-parents').Visitor<Text>} */
9696
function visitor(node, parents) {
97-
var index = -1
97+
let index = -1
9898
/** @type {Parent} */
99-
var parent
99+
let parent
100100
/** @type {Parent} */
101-
var grandparent
101+
let grandparent
102102

103103
while (++index < parents.length) {
104104
// @ts-expect-error mdast vs. unist parent.
@@ -127,18 +127,18 @@ export const findAndReplace =
127127
* @returns {VisitorResult}
128128
*/
129129
function handler(node, parent) {
130-
var find = pairs[pairIndex][0]
131-
var replace = pairs[pairIndex][1]
130+
const find = pairs[pairIndex][0]
131+
const replace = pairs[pairIndex][1]
132132
/** @type {Array.<PhrasingContent>} */
133-
var nodes = []
134-
var start = 0
135-
var index = parent.children.indexOf(node)
133+
let nodes = []
134+
let start = 0
135+
let index = parent.children.indexOf(node)
136136
/** @type {number} */
137-
var position
137+
let position
138138
/** @type {RegExpMatchArray} */
139-
var match
139+
let match
140140
/** @type {Array.<PhrasingContent>|PhrasingContent|string|false|undefined|null} */
141-
var value
141+
let value
142142

143143
find.lastIndex = 0
144144

@@ -196,11 +196,11 @@ export const findAndReplace =
196196
* @returns {Pairs}
197197
*/
198198
function toPairs(schema) {
199-
var index = -1
199+
let index = -1
200200
/** @type {Pairs} */
201-
var result = []
201+
const result = []
202202
/** @type {string} */
203-
var key
203+
let key
204204

205205
if (typeof schema !== 'object') {
206206
throw new TypeError('Expected array or object as schema')

Diff for: package.json

+1-5
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": [

Diff for: readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {u} from 'unist-builder'
2828
import {inspect} from 'unist-util-inspect'
2929
import {findAndReplace} from 'mdast-util-find-and-replace'
3030

31-
var tree = u('paragraph', [
31+
const tree = u('paragraph', [
3232
u('text', 'Some '),
3333
u('emphasis', [u('text', 'emphasis')]),
3434
u('text', ' and '),

Diff for: test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import test from 'tape'
22
import {u} from 'unist-builder'
33
import {findAndReplace} from './index.js'
44

5-
test('findAndReplace', function (t) {
5+
test('findAndReplace', (t) => {
66
t.throws(
7-
function () {
7+
() => {
88
// @ts-expect-error runtime.
99
findAndReplace(create(), true)
1010
},
@@ -44,7 +44,7 @@ test('findAndReplace', function (t) {
4444
findAndReplace(
4545
create(),
4646
/em(\w+)is/,
47-
function (/** @type {string} */ _, /** @type {string} */ $1) {
47+
(/** @type {string} */ _, /** @type {string} */ $1) => {
4848
return '[' + $1 + ']'
4949
}
5050
),
@@ -61,7 +61,7 @@ test('findAndReplace', function (t) {
6161
)
6262

6363
t.deepEqual(
64-
findAndReplace(create(), 'emphasis', function () {
64+
findAndReplace(create(), 'emphasis', () => {
6565
return u('delete', [u('break')])
6666
}),
6767
u('paragraph', [

0 commit comments

Comments
 (0)