Skip to content

Commit 513ebeb

Browse files
committed
Refactor code-style
1 parent dc929a8 commit 513ebeb

File tree

4 files changed

+49
-48
lines changed

4 files changed

+49
-48
lines changed

index.test-d.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import {expectType} from 'tsd'
21
import type {Root, Heading, Paragraph} from 'mdast'
2+
import {expectType} from 'tsd'
33
import {squeezeParagraphs} from './index.js'
44

55
const root: Root = {type: 'root', children: []}
66
const paragraph: Paragraph = {type: 'paragraph', children: []}
77
const heading: Heading = {type: 'heading', depth: 1, children: []}
8-
/* eslint-disable @typescript-eslint/consistent-type-assertions */
98
const headingOrParagraph = {type: 'paragraph', children: []} as
109
| Heading
1110
| Paragraph
12-
/* eslint-enable @typescript-eslint/consistent-type-assertions */
1311

1412
expectType<Root>(squeezeParagraphs(root))
1513
expectType<Paragraph | null>(squeezeParagraphs(paragraph))

lib/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export function squeezeParagraphs(tree) {
4343
function emptyParagraph(node) {
4444
return (
4545
node.type === 'paragraph' &&
46-
node.children.every(
47-
(child) => child.type === 'text' && /^\s*$/.test(child.value)
48-
)
46+
node.children.every(function (child) {
47+
return child.type === 'text' && /^\s*$/.test(child.value)
48+
})
4949
)
5050
}

package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,17 @@
8484
"strict": true
8585
},
8686
"xo": {
87-
"prettier": true,
88-
"rules": {
89-
"@typescript-eslint/ban-types": "off"
90-
}
87+
"overrides": [
88+
{
89+
"files": [
90+
"**/*.ts"
91+
],
92+
"rules": {
93+
"@typescript-eslint/ban-types": "off",
94+
"@typescript-eslint/consistent-type-assertions": "off"
95+
}
96+
}
97+
],
98+
"prettier": true
9199
}
92100
}

test.js

+33-38
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1-
/**
2-
* @typedef {import('mdast').Root} Root
3-
* @typedef {import('mdast').Paragraph} Paragraph
4-
*/
5-
61
import assert from 'node:assert/strict'
72
import test from 'node:test'
83
import {u} from 'unist-builder'
94
import {squeezeParagraphs} from './index.js'
105

11-
test('squeezeParagraphs', () => {
12-
assert.deepEqual(
13-
squeezeParagraphs(
14-
/** @type {Root} */ (
15-
u('root', [
16-
u('paragraph', []),
17-
u('paragraph', [u('text', 'first')]),
18-
u('paragraph', []),
19-
u('paragraph', [u('text', ''), u('text', ' \n')]),
20-
u('paragraph', [
21-
u('text', 'second'),
22-
u('text', ' '),
23-
u('text', 'value')
24-
]),
25-
u('paragraph', []),
26-
u('list', {ordered: false, start: null, loose: false}, [
27-
u('listItem', {loose: false}, [u('paragraph', [])]),
28-
u('listItem', {loose: false}, [
29-
u('paragraph', [u('text', ' '), u('text', ' ')])
30-
])
31-
])
32-
])
33-
)
34-
),
35-
u('root', [
6+
test('squeezeParagraphs', async function (t) {
7+
await t.test('should work on a tree', async function () {
8+
const tree = u('root', [
9+
u('paragraph', []),
3610
u('paragraph', [u('text', 'first')]),
11+
u('paragraph', []),
12+
u('paragraph', [u('text', ''), u('text', ' \n')]),
3713
u('paragraph', [u('text', 'second'), u('text', ' '), u('text', 'value')]),
14+
u('paragraph', []),
3815
u('list', {ordered: false, start: null, loose: false}, [
39-
u('listItem', {loose: false}, []),
40-
u('listItem', {loose: false}, [])
16+
u('listItem', {loose: false}, [u('paragraph', [])]),
17+
u('listItem', {loose: false}, [
18+
u('paragraph', [u('text', ' '), u('text', ' ')])
19+
])
4120
])
4221
])
43-
)
4422

45-
assert.deepEqual(
46-
squeezeParagraphs(/** @type {Paragraph} */ (u('paragraph', []))),
47-
null,
48-
'should return `null` for empty paragraphs'
49-
)
23+
assert.deepEqual(
24+
squeezeParagraphs(tree),
25+
u('root', [
26+
u('paragraph', [u('text', 'first')]),
27+
u('paragraph', [
28+
u('text', 'second'),
29+
u('text', ' '),
30+
u('text', 'value')
31+
]),
32+
u('list', {ordered: false, start: null, loose: false}, [
33+
u('listItem', {loose: false}, []),
34+
u('listItem', {loose: false}, [])
35+
])
36+
])
37+
)
38+
})
39+
40+
await t.test('should return `null` for empty paragraphs', async function () {
41+
const tree = u('paragraph', [])
42+
43+
assert.deepEqual(squeezeParagraphs(tree), null)
44+
})
5045
})

0 commit comments

Comments
 (0)