Skip to content

Commit a4f9d57

Browse files
committed
Refactor code-style
1 parent 29d3553 commit a4f9d57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1753
-1463
lines changed

index.d.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type {Literal} from 'hast'
1+
import type {Data, Literal} from 'hast'
22
import type {State} from './lib/state.js'
33

44
// Expose types.
5-
export type {State, Handler, Handlers, Options} from './lib/state.js'
5+
export type {Handler, Handlers, Options, State} from './lib/state.js'
66

77
// To do: next major: remove.
88
/**
@@ -13,33 +13,39 @@ export type H = State
1313
// Expose JS API.
1414
export {handlers as defaultHandlers} from './lib/handlers/index.js'
1515
// To do: next major: remove.
16-
export {one, all} from './lib/state.js'
16+
export {all, one} from './lib/state.js'
1717
export {toHast} from './lib/index.js'
1818

19-
// Expose node type.
2019
/**
2120
* Raw string of HTML embedded into HTML AST.
2221
*/
23-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2422
export interface Raw extends Literal {
2523
/**
26-
* Node type.
24+
* Node type of raw.
2725
*/
2826
type: 'raw'
27+
28+
/**
29+
* Data associated with the hast raw.
30+
*/
31+
data?: RawData | undefined
2932
}
3033

34+
/**
35+
* Info associated with hast raw nodes by the ecosystem.
36+
*/
37+
export interface RawData extends Data {}
38+
3139
// Register nodes in content.
3240
declare module 'hast' {
33-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
34-
interface RootContentMap {
41+
interface ElementContentMap {
3542
/**
3643
* Raw string of HTML embedded into HTML AST.
3744
*/
3845
raw: Raw
3946
}
4047

41-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
42-
interface ElementContentMap {
48+
interface RootContentMap {
4349
/**
4450
* Raw string of HTML embedded into HTML AST.
4551
*/

lib/handlers/blockquote.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `blockquote` node into hast.
912
*

lib/handlers/break.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* @typedef {import('../state.js').State} State
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn an mdast `break` node into hast.
1013
*

lib/handlers/code.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* @typedef {import('hast').Properties} Properties
44
* @typedef {import('mdast').Code} Code
55
* @typedef {import('../state.js').State} State
6-
76
*/
87

8+
// Make VS Code show references to the above types.
9+
''
10+
911
/**
1012
* Turn an mdast `code` node into hast.
1113
*
@@ -20,7 +22,7 @@ export function code(state, node) {
2022
const value = node.value ? node.value + '\n' : ''
2123
// To do: next major, use `node.lang` w/o regex, the splitting’s been going
2224
// on for years in remark now.
23-
const lang = node.lang ? node.lang.match(/^[^ \t]+(?=[ \t]|$)/) : null
25+
const lang = node.lang ? node.lang.match(/^[^ \t]+(?=[ \t]|$)/) : undefined
2426
/** @type {Properties} */
2527
const properties = {}
2628

lib/handlers/delete.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
* @typedef {import('hast').Element} Element
33
* @typedef {import('mdast').Delete} Delete
44
* @typedef {import('../state.js').State} State
5-
65
*/
76

7+
// Make VS Code show references to the above types.
8+
''
9+
810
/**
911
* Turn an mdast `delete` node into hast.
1012
*

lib/handlers/emphasis.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `emphasis` node into hast.
912
*

lib/handlers/footnote-reference.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('mdast').FootnoteReference} FootnoteReference
32
* @typedef {import('hast').Element} Element
3+
* @typedef {import('mdast').FootnoteReference} FootnoteReference
44
* @typedef {import('../state.js').State} State
55
*/
66

lib/handlers/heading.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `heading` node into hast.
912
*

lib/handlers/html.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/**
22
* @typedef {import('hast').Element} Element
3-
* @typedef {import('mdast').HTML} Html
3+
* @typedef {import('mdast').Html} Html
44
* @typedef {import('../state.js').State} State
55
* @typedef {import('../../index.js').Raw} Raw
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn an mdast `html` node into hast (`raw` node in dangerous mode, otherwise
1013
* nothing).
@@ -13,7 +16,7 @@
1316
* Info passed around.
1417
* @param {Html} node
1518
* mdast node.
16-
* @returns {Raw | Element | null}
19+
* @returns {Element | Raw | undefined}
1720
* hast node.
1821
*/
1922
export function html(state, node) {
@@ -24,6 +27,5 @@ export function html(state, node) {
2427
return state.applyData(node, result)
2528
}
2629

27-
// To do: next major: return `undefined`.
28-
return null
30+
return undefined
2931
}

lib/handlers/image-reference.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('hast').ElementContent} ElementContent
32
* @typedef {import('hast').Element} Element
3+
* @typedef {import('hast').ElementContent} ElementContent
44
* @typedef {import('hast').Properties} Properties
55
* @typedef {import('mdast').ImageReference} ImageReference
66
* @typedef {import('../state.js').State} State
@@ -16,7 +16,7 @@ import {revert} from '../revert.js'
1616
* Info passed around.
1717
* @param {ImageReference} node
1818
* mdast node.
19-
* @returns {ElementContent | Array<ElementContent>}
19+
* @returns {Array<ElementContent> | ElementContent}
2020
* hast node.
2121
*/
2222
export function imageReference(state, node) {

lib/handlers/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,5 @@ export const handlers = {
5959

6060
// Return nothing for nodes that are ignored.
6161
function ignore() {
62-
// To do: next major: return `undefined`.
63-
return null
62+
return undefined
6463
}

lib/handlers/inline-code.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* @typedef {import('../state.js').State} State
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn an mdast `inlineCode` node into hast.
1013
*

lib/handlers/link-reference.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {revert} from '../revert.js'
1616
* Info passed around.
1717
* @param {LinkReference} node
1818
* mdast node.
19-
* @returns {ElementContent | Array<ElementContent>}
19+
* @returns {Array<ElementContent> | ElementContent}
2020
* hast node.
2121
*/
2222
export function linkReference(state, node) {

lib/handlers/list-item.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
* @typedef {import('hast').Element} Element
33
* @typedef {import('hast').ElementContent} ElementContent
44
* @typedef {import('hast').Properties} Properties
5-
* @typedef {import('mdast').Content} Content
65
* @typedef {import('mdast').ListItem} ListItem
7-
* @typedef {import('mdast').Parent} Parent
8-
* @typedef {import('mdast').Root} Root
6+
* @typedef {import('mdast').Parents} Parents
97
* @typedef {import('../state.js').State} State
108
*/
119

12-
/**
13-
* @typedef {Root | Content} Nodes
14-
* @typedef {Extract<Nodes, Parent>} Parents
15-
*/
10+
// Make VS Code show references to the above types.
11+
''
1612

1713
/**
1814
* Turn an mdast `listItem` node into hast.
@@ -123,7 +119,7 @@ function listLoose(node) {
123119
function listItemLoose(node) {
124120
const spread = node.spread
125121

126-
return spread === undefined || spread === null
122+
return spread === null || spread === undefined
127123
? node.children.length > 1
128124
: spread
129125
}

lib/handlers/list.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* @typedef {import('../state.js').State} State
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn an mdast `list` node into hast.
1013
*

lib/handlers/paragraph.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `paragraph` node into hast.
912
*

lib/handlers/root.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
/**
2+
* @typedef {import('hast').Parents} HastParents
23
* @typedef {import('hast').Root} HastRoot
3-
* @typedef {import('hast').Element} HastElement
44
* @typedef {import('mdast').Root} MdastRoot
55
* @typedef {import('../state.js').State} State
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn an mdast `root` node into hast.
1013
*
1114
* @param {State} state
1215
* Info passed around.
1316
* @param {MdastRoot} node
1417
* mdast node.
15-
* @returns {HastRoot | HastElement}
18+
* @returns {HastParents}
1619
* hast node.
1720
*/
1821
export function root(state, node) {

lib/handlers/strong.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `strong` node into hast.
912
*

lib/handlers/table-cell.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `tableCell` node into hast.
912
*

lib/handlers/table-row.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/**
2-
* @typedef {import('hast').Properties} Properties
32
* @typedef {import('hast').Element} Element
43
* @typedef {import('hast').ElementContent} ElementContent
5-
* @typedef {import('mdast').Content} Content
6-
* @typedef {import('mdast').Parent} Parent
7-
* @typedef {import('mdast').Root} Root
4+
* @typedef {import('hast').Properties} Properties
5+
* @typedef {import('mdast').Parents} Parents
86
* @typedef {import('mdast').TableRow} TableRow
97
* @typedef {import('../state.js').State} State
108
*/
119

12-
/**
13-
* @typedef {Root | Content} Nodes
14-
* @typedef {Extract<Nodes, Parent>} Parents
15-
*/
10+
// Make VS Code show references to the above types.
11+
''
1612

1713
/**
1814
* Turn an mdast `tableRow` node into hast.

lib/handlers/table.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7-
import {pointStart, pointEnd} from 'unist-util-position'
7+
import {pointEnd, pointStart} from 'unist-util-position'
88

99
/**
1010
* Turn an mdast `table` node into hast.

lib/handlers/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {trimLines} from 'trim-lines'
1414
* Info passed around.
1515
* @param {MdastText} node
1616
* mdast node.
17-
* @returns {HastText | HastElement}
17+
* @returns {HastElement | HastText}
1818
* hast node.
1919
*/
2020
export function text(state, node) {

lib/handlers/thematic-break.js

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @typedef {import('../state.js').State} State
55
*/
66

7+
// Make VS Code show references to the above types.
8+
''
9+
710
/**
811
* Turn an mdast `thematicBreak` node into hast.
912
*

0 commit comments

Comments
 (0)