Skip to content

Commit fa9072f

Browse files
committed
Add strict to tsconfig.json
1 parent cf6a0eb commit fa9072f

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ const single = [
1313
';' // Semi-colon
1414
]
1515

16-
// Pair delimiters.
17-
// From common sense, and UncycloPedia:
18-
// <https://en.wikipedia.org/wiki/Quotation_mark>.
16+
/**
17+
* Pair delimiters.
18+
* From common sense, and UncycloPedia:
19+
* <https://en.wikipedia.org/wiki/Quotation_mark>.
20+
*
21+
* @type {Record<string, string[]>}
22+
*/
1923
const pairs = {
2024
',': [','],
2125
'-': ['-'],
@@ -112,7 +116,7 @@ function siblingDelimiter(parent, position, step, delimiters) {
112116
}
113117

114118
if (sibling.type !== 'WhiteSpaceNode') {
115-
return delimiters.includes(toString(sibling)) && sibling
119+
return delimiters.includes(toString(sibling)) ? sibling : undefined
116120
}
117121

118122
index += step

test.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import assert from 'assert'
77
import test from 'tape'
8-
// @ts-ignore remove when typed.
8+
// @ts-expect-error remove when typed.
99
import retext from 'retext'
1010
import {visit} from 'unist-util-visit'
1111
import {isLiteral} from './index.js'
1212

1313
test('isLiteral()', (t) => {
1414
t.throws(
1515
() => {
16-
// @ts-ignore runtime.
16+
// @ts-expect-error runtime.
1717
isLiteral()
1818
},
1919
/Parent must be a node/,
@@ -22,7 +22,7 @@ test('isLiteral()', (t) => {
2222

2323
t.throws(
2424
() => {
25-
// @ts-ignore runtime.
25+
// @ts-expect-error runtime.
2626
isLiteral({})
2727
},
2828
/Parent must be a node/,
@@ -31,7 +31,7 @@ test('isLiteral()', (t) => {
3131

3232
t.throws(
3333
() => {
34-
// @ts-ignore runtime.
34+
// @ts-expect-error runtime.
3535
isLiteral({children: []})
3636
},
3737
/Index must be a number/,
@@ -40,7 +40,7 @@ test('isLiteral()', (t) => {
4040

4141
t.throws(
4242
() => {
43-
// @ts-ignore runtime.
43+
// @ts-expect-error runtime.
4444
isLiteral({children: []}, {type: 'a'})
4545
},
4646
/Node must be a child of `parent`/,
@@ -49,15 +49,18 @@ test('isLiteral()', (t) => {
4949

5050
t.doesNotThrow(() => {
5151
const n = {type: 'a'}
52-
// @ts-ignore runtime.
52+
// @ts-expect-error runtime.
5353
isLiteral({children: [n]}, n)
5454
}, 'should not throw if `node` is in `parent`')
5555

5656
t.doesNotThrow(() => {
5757
process(
5858
'Well? Ha! Funky',
5959
/** @type {Visitor} */ (_, index, parent) => {
60-
assert.strictEqual(isLiteral(parent, index), false)
60+
assert.strictEqual(
61+
parent && index !== null && isLiteral(parent, index),
62+
false
63+
)
6164
}
6265
)
6366
}, 'should work on single word sentences')
@@ -81,7 +84,7 @@ test('isLiteral()', (t) => {
8184
fixtures[index],
8285
/** @type {Visitor} */ (_, index, parent) => {
8386
assert.strictEqual(
84-
isLiteral(parent, index),
87+
parent && index !== null && isLiteral(parent, index),
8588
index === 0,
8689
String(index)
8790
)
@@ -109,8 +112,8 @@ test('isLiteral()', (t) => {
109112
fixtures[index],
110113
/** @type {Visitor} */ (_, index, parent) => {
111114
assert.strictEqual(
112-
isLiteral(parent, index),
113-
index === parent.children.length - 2,
115+
parent && index !== null && isLiteral(parent, index),
116+
parent && index === parent.children.length - 2,
114117
String(index)
115118
)
116119
}
@@ -166,7 +169,7 @@ test('isLiteral()', (t) => {
166169
}
167170

168171
assert.strictEqual(
169-
isLiteral(parent, place),
172+
parent && place !== null && isLiteral(parent, place),
170173
place === pos,
171174
String(index)
172175
)

tsconfig.json

Lines changed: 2 additions & 1 deletion
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)