Skip to content

Commit 3d73d14

Browse files
committed
Refactor code-style
1 parent a3106c5 commit 3d73d14

File tree

5 files changed

+59
-40
lines changed

5 files changed

+59
-40
lines changed

index.d.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1-
import type {Literal} from 'nlcst'
1+
import type {Data, Literal} from 'nlcst'
2+
3+
// Expose runtime code.
4+
export {emoticonModifier} from './lib/index.js'
25

36
/**
47
* Emoticon node.
58
*/
6-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
79
export interface Emoticon extends Literal {
10+
/**
11+
* Node type of emoticon node.
12+
*/
813
type: 'EmoticonNode'
14+
15+
/**
16+
* Data associated by the ecosystem.
17+
*/
18+
data?: EmoticonData | undefined
919
}
1020

21+
/**
22+
* Emoticon node data.
23+
*/
24+
export interface EmoticonData extends Data {}
25+
26+
// Register node type.
1127
declare module 'nlcst' {
12-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1328
interface RootContentMap {
1429
emoticon: Emoticon
1530
}
1631

17-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1832
interface SentenceContentMap {
1933
emoticon: Emoticon
2034
}
2135
}
22-
23-
export {emoticonModifier} from './lib/index.js'

lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* @typedef {import('nlcst').Sentence} Sentence
33
* @typedef {import('nlcst').SentenceContent} SentenceContent
4-
* @typedef {import('../complex-types.js').Emoticon} Emoticon
4+
* @typedef {import('../index.js').Emoticon} Emoticon
55
*/
66

7+
import {emoticon} from 'emoticon'
78
import {toString} from 'nlcst-to-string'
89
import {modifyChildren} from 'unist-util-modify-children'
9-
import {emoticon} from 'emoticon'
1010

1111
// Magic numbers.
1212
//

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"@types/node": "^20.0.0",
4444
"c8": "^8.0.0",
4545
"is-hidden": "^2.0.0",
46-
"parse-english": "^6.0.0",
46+
"parse-english": "^7.0.0",
4747
"prettier": "^3.0.0",
4848
"remark-cli": "^11.0.0",
4949
"remark-preset-wooorm": "^9.0.0",
@@ -80,6 +80,14 @@
8080
},
8181
"xo": {
8282
"overrides": [
83+
{
84+
"files": [
85+
"**/*.ts"
86+
],
87+
"rules": {
88+
"@typescript-eslint/consistent-type-definitions": "off"
89+
}
90+
},
8391
{
8492
"files": "test/**/*.js",
8593
"rules": {

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Merge emoticons in a `SentenceNode` into `EmoticonNode`s.
111111

112112
###### Returns
113113

114-
Nothing (`void`).
114+
Nothing (`undefined`).
115115

116116
### `Emoticon`
117117

@@ -147,7 +147,7 @@ import {visit} from 'unist-util-visit'
147147
/** @type {import('nlcst').Root} */
148148
const tree = getNodeSomeHow()
149149

150-
visit(tree, (node) => {
150+
visit(tree, function (node) {
151151
// `node` can now be a `Emoticon` node.
152152
})
153153
```

test/index.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* @typedef {import('nlcst').Root} Root
3-
* @typedef {import('../complex-types.js').Emoticon} Emoticon
43
*/
54

65
import assert from 'node:assert/strict'
@@ -11,29 +10,20 @@ import {emoticon} from 'emoticon'
1110
import {isHidden} from 'is-hidden'
1211
import {toString} from 'nlcst-to-string'
1312
import {emoticonModifier} from '../index.js'
14-
import * as mod from '../index.js'
1513

1614
const parser = new ParseEnglish()
1715
parser.tokenizeSentencePlugins.unshift(emoticonModifier)
1816

19-
test('emoticonModifier', async () => {
20-
assert.deepEqual(
21-
Object.keys(mod).sort(),
22-
['emoticonModifier'],
23-
'should expose the public api'
24-
)
17+
test('emoticonModifier', async function (t) {
18+
await t.test('should expose the public api', async function () {
19+
assert.deepEqual(Object.keys(await import('../index.js')).sort(), [
20+
'emoticonModifier'
21+
])
22+
})
23+
})
2524

25+
test('fixtures', async function (t) {
2626
const root = new URL('fixtures/', import.meta.url)
27-
28-
assert.throws(
29-
() => {
30-
// @ts-expect-error runtime.
31-
emoticonModifier({})
32-
},
33-
/Missing children in `parent`/,
34-
'should throw when not given a parent'
35-
)
36-
3727
const files = await fs.readdir(root)
3828
let index = -1
3929

@@ -42,30 +32,39 @@ test('emoticonModifier', async () => {
4232

4333
if (isHidden(file)) continue
4434

45-
/** @type {Root} */
46-
const tree = JSON.parse(String(await fs.readFile(new URL(file, root))))
4735
const name = file.split('.').slice(0, -1).join('.')
48-
const input = toString(tree)
4936

50-
assert.deepEqual(parser.parse(input), tree, name)
37+
await t.test(name, async function () {
38+
/** @type {Root} */
39+
const tree = JSON.parse(String(await fs.readFile(new URL(file, root))))
40+
const input = toString(tree)
41+
42+
assert.deepEqual(parser.parse(input), tree)
43+
})
5144
}
5245
})
5346

54-
test('emoticons', () => {
47+
test('emoticons', async function (t) {
5548
let index = -1
5649

5750
while (++index < emoticon.length) {
5851
const list = emoticon[index].emoticons
5952
let offset = -1
6053

6154
while (++offset < list.length) {
62-
const tree = parser.parse('Who doesn’t like ' + list[offset] + '?')
63-
/** @type {Emoticon} */
64-
// @ts-expect-error: fine.
65-
const node = tree.children[0].children[0].children[6]
55+
const value = list[offset]
56+
57+
await t.test(value, async function () {
58+
const tree = parser.parse('Who doesn’t like ' + value + '?')
59+
const paragraph = tree.children[0]
60+
assert(paragraph.type === 'ParagraphNode')
61+
const sentence = paragraph.children[0]
62+
assert(sentence.type === 'SentenceNode')
63+
const node = sentence.children[6]
64+
assert(node.type === 'EmoticonNode')
6665

67-
assert.strictEqual(node.type, 'EmoticonNode', list[offset] + ' type')
68-
assert.strictEqual(node.value, list[offset], list[offset] + ' value')
66+
assert.equal(node.value, value)
67+
})
6968
}
7069
}
7170
})

0 commit comments

Comments
 (0)