Skip to content

Commit c930d3d

Browse files
committed
Add strict to tsconfig.json
1 parent fa4e24c commit c930d3d

12 files changed

+37
-29
lines changed

lib/footer.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ export function footer(h) {
4040
const tail = content[content.length - 1]
4141

4242
if (tail && tail.type === 'paragraph') {
43-
// @ts-ignore it’s a paragraph, TypeScript…
4443
tail.children.push(backReference)
4544
} else {
46-
// @ts-ignore Indeed, link directly added in block content.
45+
// @ts-expect-error Indeed, link directly added in block content.
4746
content.push(backReference)
4847
}
4948

@@ -64,10 +63,10 @@ export function footer(h) {
6463
'section',
6564
{className: ['footnotes'], role: 'doc-endnotes'},
6665
wrap(
67-
[].concat(
66+
[
6867
thematicBreak(h),
6968
list(h, {type: 'list', ordered: true, children: listItems})
70-
),
69+
],
7170
true
7271
)
7372
)

lib/handlers/html.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ import {u} from 'unist-builder'
1212
* @param {HTML} node
1313
*/
1414
export function html(h, node) {
15-
// @ts-ignore non-standard raw nodes.
15+
// @ts-expect-error non-standard raw nodes.
1616
return h.dangerous ? h.augment(node, u('raw', node.value)) : null
1717
}

lib/handlers/list-item.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ export function listItem(h, node, parent) {
5656
}
5757

5858
let index = -1
59-
/** @type {Content} */
60-
let child
6159

6260
while (++index < result.length) {
63-
child = result[index]
61+
const child = result[index]
6462

6563
// Add eols before nodes, except if this is a loose, first paragraph.
6664
if (
@@ -79,11 +77,10 @@ export function listItem(h, node, parent) {
7977
}
8078
}
8179

80+
const tail = result[result.length - 1]
81+
8282
// Add a final eol.
83-
if (
84-
result.length > 0 &&
85-
(loose || !('tagName' in child) || child.tagName !== 'p')
86-
) {
83+
if (tail && (loose || !('tagName' in tail) || tail.tagName !== 'p')) {
8784
wrapped.push(u('text', '\n'))
8885
}
8986

@@ -103,7 +100,7 @@ function listLoose(node) {
103100
loose = listItemLoose(children[index])
104101
}
105102

106-
return loose
103+
return Boolean(loose)
107104
}
108105

109106
/**

lib/handlers/list.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @typedef {import('mdast').List} List
3+
* @typedef {import('hast').Element} Element
34
* @typedef {import('hast').Properties} Properties
45
* @typedef {import('../index.js').Handler} Handler
56
*/
@@ -10,6 +11,7 @@ import {all} from '../traverse.js'
1011
/**
1112
* @type {Handler}
1213
* @param {List} node
14+
* @returns {Element}
1315
*/
1416
export function list(h, node) {
1517
/** @type {Properties} */
@@ -29,9 +31,9 @@ export function list(h, node) {
2931
if (
3032
item.type === 'element' &&
3133
item.tagName === 'li' &&
32-
// @ts-ignore looks like properties.
34+
// @ts-expect-error looks like properties.
3335
item.properties.className &&
34-
// @ts-ignore looks like properties.
36+
// @ts-expect-error looks like properties.
3537
item.properties.className.includes('task-list-item')
3638
) {
3739
props.className = ['contains-task-list']

lib/handlers/root.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ import {wrap} from '../wrap.js'
1212
* @param {Root} node
1313
*/
1414
export function root(h, node) {
15-
// @ts-ignore top-level is a root.
15+
// @ts-expect-error top-level is a root.
1616
return h.augment(node, u('root', wrap(all(h, node))))
1717
}

lib/handlers/thematic-break.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/**
22
* @typedef {import('mdast').ThematicBreak} ThematicBreak
3+
* @typedef {import('hast').Element} Element
34
* @typedef {import('../index.js').Handler} Handler
45
*/
56

67
/**
78
* @type {Handler}
89
* @param {ThematicBreak} [node]
10+
* @returns {Element}
911
*/
1012
export function thematicBreak(h, node) {
1113
return h(node, 'hr')

lib/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @callback Handler
2626
* @param {H} h Handle context
27-
* @param {Node} node mdast node to handle
27+
* @param {any} node mdast node to handle
2828
* @param {Parent|null} parent Parent of `node`
2929
* @returns {Content|Array.<Content>|null|undefined} hast node
3030
*
@@ -97,7 +97,7 @@ function factory(tree, options) {
9797

9898
visit(tree, 'footnoteDefinition', onfootnotedefinition)
9999

100-
// @ts-ignore Hush, it’s fine!
100+
// @ts-expect-error Hush, it’s fine!
101101
return h
102102

103103
/**
@@ -135,7 +135,6 @@ function factory(tree, options) {
135135
}
136136

137137
if (left) {
138-
// @ts-ignore looks like a node vs. position.
139138
const ctx = 'type' in left ? left : {position: left}
140139

141140
if (!generated(ctx)) {
@@ -157,7 +156,7 @@ function factory(tree, options) {
157156
props = {}
158157
}
159158

160-
// @ts-ignore augmenting an element yields an element.
159+
// @ts-expect-error augmenting an element yields an element.
161160
return augment(node, {
162161
type: 'element',
163162
tagName,
@@ -193,7 +192,7 @@ export function toHast(tree, options) {
193192
const foot = footer(h)
194193

195194
if (foot) {
196-
// @ts-ignore If there’s a footer, there were definitions, meaning block
195+
// @ts-expect-error If there’s a footer, there were definitions, meaning block
197196
// content.
198197
// So assume `node` is a parent node.
199198
node.children.push(u('text', '\n'), foot)

lib/traverse.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const own = {}.hasOwnProperty
1515
/**
1616
* Transform an unknown node.
1717
* @type {Handler}
18+
* @param {Node} node
1819
*/
1920
function unknown(h, node) {
2021
if (text(node)) {
@@ -26,6 +27,7 @@ function unknown(h, node) {
2627

2728
/**
2829
* @type {Handler}
30+
* @param {Node} node
2931
*/
3032
export function one(h, node, parent) {
3133
const type = node && node.type
@@ -69,9 +71,10 @@ function text(node) {
6971

7072
/**
7173
* @type {Handler}
74+
* @param {unknown} node
7275
*/
7376
function returnNode(h, node) {
74-
// @ts-ignore pass through any unknown node.
77+
// @ts-expect-error pass through any unknown node.
7578
return node.children ? {...node, children: all(h, node)} : node
7679
}
7780

@@ -81,14 +84,14 @@ function returnNode(h, node) {
8184
*/
8285
export function all(h, parent) {
8386
/** @type {Array.<Node>} */
84-
// @ts-ignore looks like a parent.
87+
// @ts-expect-error looks like a parent.
8588
const nodes = parent.children || []
8689
/** @type {Array.<Content>} */
8790
const values = []
8891
let index = -1
8992

9093
while (++index < nodes.length) {
91-
// @ts-ignore looks like a parent.
94+
// @ts-expect-error looks like a parent.
9295
const result = one(h, nodes[index], parent)
9396

9497
if (result) {

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
"typeCoverage": {
8989
"atLeast": 100,
9090
"detail": true,
91-
"strict": true
91+
"strict": true,
92+
"#": "needed `any`s",
93+
"ignoreFiles": [
94+
"lib/index.d.ts"
95+
]
9296
}
9397
}

test/core.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {toHast} from '../index.js'
55
test('toHast()', (t) => {
66
t.throws(
77
() => {
8-
// @ts-ignore runtime.
8+
// @ts-expect-error runtime.
99
toHast(u('bar', [true]))
1010
},
1111
/Expected node, got `true`/,
@@ -79,6 +79,7 @@ test('toHast()', (t) => {
7979
'tango'
8080
)
8181
),
82+
// @ts-expect-error: `null`s are fine-ish (and given by `unist-util-position`)
8283
u(
8384
'element',
8485
{

test/handlers-option.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ test('handlers option', (t) => {
5050

5151
t.deepEqual(
5252
toHast(customMdast, {
53-
// @ts-ignore `hast` expected, but this returns unknown mdast nodes.
54-
unknownHandler(_, node) {
53+
// @ts-expect-error `hast` expected, but this returns unknown mdast nodes.
54+
unknownHandler(_, /** @type {object} */ node) {
5555
return node
5656
}
5757
}),

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"declaration": true,
1111
"emitDeclarationOnly": true,
1212
"allowSyntheticDefaultImports": true,
13-
"skipLibCheck": true
13+
"skipLibCheck": true,
14+
"strict": true
1415
}
1516
}

0 commit comments

Comments
 (0)