Skip to content

Commit b7905dc

Browse files
committed
Refactor code-style
1 parent f464497 commit b7905dc

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@ export const affixEmoticonModifier = modifyChildren(mergeAffixEmoticon)
1616
*/
1717
function mergeAffixEmoticon(node, index, ancestor) {
1818
const previous = ancestor.children[index - 1]
19-
var childIndex = -1
2019

2120
if (index && parent(previous) && parent(node)) {
22-
var children = node.children
21+
const children = node.children
22+
let childIndex = -1
2323

2424
while (++childIndex < children.length) {
2525
const child = children[childIndex]
2626

2727
if (child.type === 'EmoticonNode') {
28-
previous.children = [].concat(
29-
previous.children,
30-
children.slice(0, childIndex + 1)
31-
)
28+
previous.children.push(...children.slice(0, childIndex + 1))
3229
node.children = children.slice(childIndex + 1)
3330

3431
if (child.position && node.position && previous.position) {

package.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@
7070
"trailingComma": "none"
7171
},
7272
"xo": {
73-
"prettier": true,
74-
"rules": {
75-
"capitalized-comments": "off",
76-
"no-var": "off",
77-
"prefer-arrow-callback": "off"
78-
}
73+
"prettier": true
7974
},
8075
"remarkConfig": {
8176
"plugins": [

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {emoticonModifier} from 'nlcst-emoticon-modifier'
3333
import {inspect} from 'unist-util-inspect'
3434
import {ParseEnglish} from 'parse-english'
3535

36-
var english = new ParseEnglish()
36+
const english = new ParseEnglish()
3737

3838
english.useFirst('tokenizeSentence', emoticonModifier)
3939
english.useFirst('tokenizeParagraph', affixEmoticonModifier)

test/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import {removePosition} from 'unist-util-remove-position'
1414
import {affixEmoticonModifier} from '../index.js'
1515

1616
/** @type {Node} */
17-
var lollipop = JSON.parse(
17+
const lollipop = JSON.parse(
1818
String(fs.readFileSync(path.join('test', 'fixtures', 'lollipop.json')))
1919
)
2020

2121
/** @type {Node} */
22-
var smile = JSON.parse(
22+
const smile = JSON.parse(
2323
String(fs.readFileSync(path.join('test', 'fixtures', 'smile.json')))
2424
)
2525

26-
test('affixEmoticonModifier()', function (t) {
26+
test('affixEmoticonModifier()', (t) => {
2727
t.throws(
28-
function () {
28+
() => {
2929
// @ts-ignore runtime.
3030
affixEmoticonModifier({})
3131
},
@@ -67,9 +67,10 @@ test('affixEmoticonModifier()', function (t) {
6767
* @param {boolean} [positionless=false]
6868
*/
6969
function process(fixture, positionless) {
70-
var processor = unified().use(english).use(plugin).freeze()
70+
const processor = unified().use(english).use(plugin).freeze()
7171

7272
if (positionless) {
73+
// Fine.
7374
// type-coverage:ignore-next-line
7475
processor.Parser.prototype.position = false
7576
}
@@ -79,10 +80,13 @@ function process(fixture, positionless) {
7980

8081
// Add modifier to processor.
8182
function plugin() {
83+
// Fine.
8284
// type-coverage:ignore-next-line
8385
this.Parser.prototype.useFirst('tokenizeSentence', emojiModifier)
86+
// Fine.
8487
// type-coverage:ignore-next-line
8588
this.Parser.prototype.useFirst('tokenizeSentence', emoticonModifier)
89+
// Fine.
8690
// type-coverage:ignore-next-line
8791
this.Parser.prototype.useFirst('tokenizeParagraph', affixEmoticonModifier)
8892
}

0 commit comments

Comments
 (0)