Skip to content

Commit bfa3c39

Browse files
committed
Refactor code-style
1 parent 8ec1c56 commit bfa3c39

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

index.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
import {location} from 'vfile-location'
22

3-
var search = /\r?\n|\r/g
3+
const search = /\r?\n|\r/g
44

55
/**
66
* @param {import('unist').Node|import('unist').Position} value Value to get
77
* @param {import('vfile').VFile|import('vfile').VFileValue} file File in which `value` exists
88
* @returns {string|null}
99
*/
1010
export function source(value, file) {
11-
var doc = String(file)
12-
var loc = location(file)
11+
const doc = String(file)
12+
const loc = location(file)
1313
/** @type {import('unist').Position} */
14-
// @ts-ignore Looks like a node.
15-
var position = (value && value.position) || value || {}
16-
var startOffset = loc.toOffset(position.start)
17-
var endOffset = loc.toOffset(position.end)
18-
/** @type {Array.<string>} */
19-
var results = []
20-
/** @type {RegExpMatchArray} */
21-
var match
22-
/** @type {number} */
23-
var end
14+
// @ts-expect-error Looks like a node.
15+
const position = (value && value.position) || value || {}
16+
const endOffset = loc.toOffset(position.end)
17+
let startOffset = loc.toOffset(position.start)
2418

25-
if (startOffset === -1 || endOffset === -1) {
19+
if (endOffset === -1 || startOffset === -1) {
2620
return null
2721
}
2822

23+
/** @type {Array.<string>} */
24+
const results = []
25+
2926
while (startOffset < endOffset) {
3027
search.lastIndex = startOffset
31-
match = search.exec(doc)
32-
end = match && match.index < endOffset ? match.index : endOffset
28+
const match = search.exec(doc)
29+
const end = match && match.index < endOffset ? match.index : endOffset
3330
results.push(doc.slice(startOffset, end))
3431
startOffset = end
3532

package.json

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

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ Say we have the following file, `example.md`:
3333
And our script, `example.js`, looks as follows:
3434

3535
```js
36-
import {toVFile} from 'to-vfile'
37-
import unified from 'unified'
36+
import {readSync} from 'to-vfile'
37+
import {unified} from 'unified'
3838
import remarkParse from 'remark-parse'
3939
import {source} from 'unist-util-source'
4040

41-
var file = toVFile.readSync('example.md')
42-
var tree = unified()
41+
const file = readSync('example.md')
42+
const tree = unified()
4343
.use(remarkParse)
4444
.parse(file)
4545

test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import remark from 'remark'
1010
import {VFile} from 'vfile'
1111
import {source} from './index.js'
1212

13-
test('unist-util-source', function (t) {
14-
var file = new VFile('> + **[Hello](./example)**\n> world.')
13+
test('unist-util-source', (t) => {
14+
let file = new VFile('> + **[Hello](./example)**\n> world.')
1515
/** @type {Node} */
1616
// @ts-expect-error: hush.
17-
var node = remark().parse(file)
17+
let node = remark().parse(file)
1818

1919
t.equal(source(node, file), '> + **[Hello](./example)**\n> world.', 'root')
2020

0 commit comments

Comments
 (0)