Skip to content

Commit

Permalink
Add strict to tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 26, 2021
1 parent 03d0c61 commit f3c7e62
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
19 changes: 7 additions & 12 deletions lib/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @typedef ContentsOptions
* @property {boolean} [tight=false] Whether to compile list-items tightly.
* @property {boolean} [ordered=false] Whether to compile list-items as an ordered list, otherwise they are unordered.
* @property {string} [prefix=null] Add a prefix to links to headings in the table of contents. Useful for example when later going from mdast to hast and sanitizing with `hast-util-sanitize`.
* @property {string|null} [prefix=null] Add a prefix to links to headings in the table of contents. Useful for example when later going from mdast to hast and sanitizing with `hast-util-sanitize`.
*/

import extend from 'extend'
Expand Down Expand Up @@ -97,7 +97,7 @@ function insert(entry, parent, settings) {
entry.depth--
insert(
entry,
// @ts-ignore It’s a `list`, we just checked.
// @ts-expect-error It’s a `list`, we just checked.
parent.children[parent.children.length - 1],
settings
)
Expand Down Expand Up @@ -157,20 +157,15 @@ function one(node) {
node.type === 'footnote' ||
node.type === 'footnoteReference'
) {
// @ts-ignore Looks like a parent.
// @ts-expect-error Looks like a parent.
return all(node.children)
}

let copy = extend({}, node)
if ('children' in copy) delete copy.children
delete copy.position

copy = extend(true, {}, copy)

if ('children' in node) {
// @ts-ignore Looks like a parent.
copy.children = all(node.children)
const {children, position, ...copy} = node
return Object.assign(extend(true, {}, copy), {children: all(node.children)})
}

return copy
const {position, ...copy} = node
return extend(true, {}, copy)
}
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* @property {string} [heading] Heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
*
* @typedef Result
* @property {number} index
* @property {number} endIndex
* @property {List} map
* @property {number|null} index
* @property {number|null} endIndex
* @property {List|null} map
*/

import {search} from './search.js'
Expand Down
17 changes: 11 additions & 6 deletions lib/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const slugs = new Slugger()
* Search a node for a toc.
*
* @param {Node} root
* @param {RegExp} expression
* @param {RegExp|null} expression
* @param {SearchOptions} settings
* @returns {SearchResult}
*/
Expand All @@ -44,7 +44,7 @@ export function search(root, expression, settings) {
const parents = convert(settings.parents || ((d) => d === root))
/** @type {Array.<SearchEntry>} */
const map = []
/** @type {number} */
/** @type {number|undefined} */
let index
/** @type {number} */
let endIndex
Expand All @@ -60,7 +60,7 @@ export function search(root, expression, settings) {
return {
index: index || -1,
// <sindresorhus/eslint-plugin-unicorn#980>
// @ts-ignore Looks like a parent.
// @ts-expect-error Looks like a parent.
endIndex: index ? endIndex || root.children.length : -1, // eslint-disable-line unicorn/explicit-length-check
map
}
Expand All @@ -69,7 +69,7 @@ export function search(root, expression, settings) {
function onheading(node, position, parent) {
const value = toString(node, {includeImageAlt: false})
/** @type {string} */
// @ts-ignore `hProperties` from <https://github.com/syntax-tree/mdast-util-to-hast>
// @ts-expect-error `hProperties` from <https://github.com/syntax-tree/mdast-util-to-hast>
const id = node.data && node.data.hProperties && node.data.hProperties.id
const slug = slugs.slug(id || value)

Expand All @@ -78,14 +78,19 @@ export function search(root, expression, settings) {
}

// Our opening heading.
if (expression && !index && expression.test(value)) {
if (position !== null && expression && !index && expression.test(value)) {
index = position + 1
opening = node
return
}

// Our closing heading.
if (opening && !endIndex && node.depth <= opening.depth) {
if (
position !== null &&
opening &&
!endIndex &&
node.depth <= opening.depth
) {
endIndex = position
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test('mdast-util-toc', (t) => {

t.throws(
() => {
// @ts-ignore runtime.
// @ts-expect-error runtime.
toc()
},
/Cannot read property 'children' of undefined/,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"skipLibCheck": true,
"strict": true
}
}

0 comments on commit f3c7e62

Please sign in to comment.