Skip to content

Commit cf6a0eb

Browse files
committed
Refactor code-style
1 parent b4c988e commit cf6a0eb

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

index.js

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

66
import {toString} from 'nlcst-to-string'
77

8-
var single = [
8+
const single = [
99
'-', // Hyphen-minus
1010
'–', // En dash
1111
'—', // Em dash
@@ -16,7 +16,7 @@ var single = [
1616
// Pair delimiters.
1717
// From common sense, and WikiPedia:
1818
// <https://en.wikipedia.org/wiki/Quotation_mark>.
19-
var pairs = {
19+
const pairs = {
2020
',': [','],
2121
'-': ['-'],
2222
'–': ['–'],
@@ -40,7 +40,7 @@ var pairs = {
4040
'「': ['」']
4141
}
4242

43-
var open = Object.keys(pairs)
43+
const open = Object.keys(pairs)
4444

4545
/**
4646
* Check if the node in `parent` at `position` is enclosed by matching
@@ -84,7 +84,7 @@ export function isLiteral(parent, index) {
8484
* @returns {Node|void}
8585
*/
8686
function isWrapped(parent, position) {
87-
var previous = siblingDelimiter(parent, position, -1, open)
87+
const previous = siblingDelimiter(parent, position, -1, open)
8888

8989
if (previous) {
9090
return siblingDelimiter(parent, position, 1, pairs[toString(previous)])
@@ -102,12 +102,10 @@ function isWrapped(parent, position) {
102102
* @returns {Node|void}
103103
*/
104104
function siblingDelimiter(parent, position, step, delimiters) {
105-
var index = position + step
106-
/** @type {Node} */
107-
var sibling
105+
let index = position + step
108106

109107
while (index > -1 && index < parent.children.length) {
110-
sibling = parent.children[index]
108+
const sibling = parent.children[index]
111109

112110
if (sibling.type === 'WordNode' || sibling.type === 'SourceNode') {
113111
return

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: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,16 @@ The word — quux — is meant as a literal.
4444
And our script, `example.js`, looks as follows:
4545

4646
```js
47-
import vfile from 'to-vfile'
48-
import unified from 'unified'
49-
import english from 'retext-english'
47+
import {readSync} from 'to-vfile'
48+
import {unified} from 'unified'
49+
import retextEnglish from 'retext-english'
5050
import {visit} from 'unist-util-visit'
5151
import {toString} from 'nlcst-to-string'
5252
import {isLiteral} from 'nlcst-is-literal'
5353

54-
var file = vfile.readSync('example.txt')
54+
const file = readSync('example.txt')
5555

56-
var tree = unified()
57-
.use(english)
58-
.parse(file)
56+
const tree = unified().use(retextEnglish).parse(file)
5957

6058
visit(tree, 'WordNode', visitor)
6159

test.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import retext from 'retext'
1010
import {visit} from 'unist-util-visit'
1111
import {isLiteral} from './index.js'
1212

13-
test('isLiteral()', function (t) {
13+
test('isLiteral()', (t) => {
1414
t.throws(
15-
function () {
15+
() => {
1616
// @ts-ignore runtime.
1717
isLiteral()
1818
},
@@ -21,7 +21,7 @@ test('isLiteral()', function (t) {
2121
)
2222

2323
t.throws(
24-
function () {
24+
() => {
2525
// @ts-ignore runtime.
2626
isLiteral({})
2727
},
@@ -30,7 +30,7 @@ test('isLiteral()', function (t) {
3030
)
3131

3232
t.throws(
33-
function () {
33+
() => {
3434
// @ts-ignore runtime.
3535
isLiteral({children: []})
3636
},
@@ -39,31 +39,31 @@ test('isLiteral()', function (t) {
3939
)
4040

4141
t.throws(
42-
function () {
42+
() => {
4343
// @ts-ignore runtime.
4444
isLiteral({children: []}, {type: 'a'})
4545
},
4646
/Node must be a child of `parent`/,
4747
'should throw if `node` is not in `parent`'
4848
)
4949

50-
t.doesNotThrow(function () {
51-
var n = {type: 'a'}
50+
t.doesNotThrow(() => {
51+
const n = {type: 'a'}
5252
// @ts-ignore runtime.
5353
isLiteral({children: [n]}, n)
5454
}, 'should not throw if `node` is in `parent`')
5555

56-
t.doesNotThrow(function () {
56+
t.doesNotThrow(() => {
5757
process(
5858
'Well? Ha! Funky',
59-
/** @type {Visitor} */ function (_, index, parent) {
59+
/** @type {Visitor} */ (_, index, parent) => {
6060
assert.strictEqual(isLiteral(parent, index), false)
6161
}
6262
)
6363
}, 'should work on single word sentences')
6464

65-
t.doesNotThrow(function () {
66-
var fixtures = [
65+
t.doesNotThrow(() => {
66+
const fixtures = [
6767
'Foo - is meant as a literal.',
6868
'Foo – is meant as a literal.',
6969
'Foo — is meant as a literal.',
@@ -74,12 +74,12 @@ test('isLiteral()', function (t) {
7474
'Foo: is meant as a literal.',
7575
'Foo; is meant as a literal.'
7676
]
77-
var index = -1
77+
let index = -1
7878

7979
while (++index < fixtures.length) {
8080
process(
8181
fixtures[index],
82-
/** @type {Visitor} */ function (_, index, parent) {
82+
/** @type {Visitor} */ (_, index, parent) => {
8383
assert.strictEqual(
8484
isLiteral(parent, index),
8585
index === 0,
@@ -90,8 +90,8 @@ test('isLiteral()', function (t) {
9090
}
9191
}, 'Initial')
9292

93-
t.doesNotThrow(function () {
94-
var fixtures = [
93+
t.doesNotThrow(() => {
94+
const fixtures = [
9595
'Meant as a literal is - foo.',
9696
'Meant as a literal is – foo.',
9797
'Meant as a literal is — foo.',
@@ -102,12 +102,12 @@ test('isLiteral()', function (t) {
102102
'Meant as a literal is: foo.',
103103
'Meant as a literal is; foo.'
104104
]
105-
var index = -1
105+
let index = -1
106106

107107
while (++index < fixtures.length) {
108108
process(
109109
fixtures[index],
110-
/** @type {Visitor} */ function (_, index, parent) {
110+
/** @type {Visitor} */ (_, index, parent) => {
111111
assert.strictEqual(
112112
isLiteral(parent, index),
113113
index === parent.children.length - 2,
@@ -118,8 +118,8 @@ test('isLiteral()', function (t) {
118118
}
119119
}, 'Final')
120120

121-
t.doesNotThrow(function () {
122-
var fixtures = [
121+
t.doesNotThrow(() => {
122+
const fixtures = [
123123
'The word, foo, is meant as a literal.',
124124
'The word -foo- is meant as a literal.',
125125
'The word –foo– is meant as a literal.',
@@ -147,13 +147,13 @@ test('isLiteral()', function (t) {
147147
'The word ⟨foo⟩ is meant as a literal.',
148148
'The word 「foo」 is meant as a literal.'
149149
]
150-
var index = -1
150+
let index = -1
151151

152152
while (++index < fixtures.length) {
153153
process(
154154
fixtures[index],
155-
/** @type {Visitor} */ function (_, place, parent) {
156-
var pos = 5
155+
/** @type {Visitor} */ (_, place, parent) => {
156+
let pos = 5
157157

158158
// Adjacent hyphens are part of the word.
159159
if (index === 1) {

0 commit comments

Comments
 (0)