Skip to content

Commit bf2a575

Browse files
committed
Refactor code-style
1 parent 5d7089b commit bf2a575

File tree

4 files changed

+332
-266
lines changed

4 files changed

+332
-266
lines changed

index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export {gfmFootnoteFromMarkdown, gfmFootnoteToMarkdown} from './lib/index.js'
22

33
declare module 'mdast-util-to-markdown' {
4-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
54
interface ConstructNameMap {
65
/**
76
* Footnote reference.

lib/index.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
/**
2-
* @typedef {import('mdast').FootnoteReference} FootnoteReference
32
* @typedef {import('mdast').FootnoteDefinition} FootnoteDefinition
3+
* @typedef {import('mdast').FootnoteReference} FootnoteReference
44
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
55
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
66
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
7-
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
87
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
98
* @typedef {import('mdast-util-to-markdown').Map} Map
9+
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
1010
*/
1111

12+
import {ok as assert} from 'devlop'
1213
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
1314

1415
footnoteReference.peek = footnoteReferencePeek
1516

16-
// To do: next major: rename `context` -> `state`, `safeOptions` to `info`, use
17-
// utilities on `state`.
18-
1917
/**
2018
* Create an extension for `mdast-util-from-markdown` to enable GFM footnotes
2119
* in markdown.
@@ -80,9 +78,8 @@ function enterFootnoteDefinitionLabelString() {
8078
*/
8179
function exitFootnoteDefinitionLabelString(token) {
8280
const label = this.resume()
83-
const node = /** @type {FootnoteDefinition} */ (
84-
this.stack[this.stack.length - 1]
85-
)
81+
const node = this.stack[this.stack.length - 1]
82+
assert(node.type === 'footnoteDefinition')
8683
node.label = label
8784
node.identifier = normalizeIdentifier(
8885
this.sliceSerialize(token)
@@ -119,9 +116,8 @@ function enterFootnoteCallString() {
119116
*/
120117
function exitFootnoteCallString(token) {
121118
const label = this.resume()
122-
const node = /** @type {FootnoteDefinition} */ (
123-
this.stack[this.stack.length - 1]
124-
)
119+
const node = this.stack[this.stack.length - 1]
120+
assert(node.type === 'footnoteReference')
125121
node.label = label
126122
node.identifier = normalizeIdentifier(
127123
this.sliceSerialize(token)
@@ -140,13 +136,13 @@ function exitFootnoteCall(token) {
140136
* @type {ToMarkdownHandle}
141137
* @param {FootnoteReference} node
142138
*/
143-
function footnoteReference(node, _, context, safeOptions) {
144-
const tracker = context.createTracker(safeOptions)
139+
function footnoteReference(node, _, state, info) {
140+
const tracker = state.createTracker(info)
145141
let value = tracker.move('[^')
146-
const exit = context.enter('footnoteReference')
147-
const subexit = context.enter('reference')
142+
const exit = state.enter('footnoteReference')
143+
const subexit = state.enter('reference')
148144
value += tracker.move(
149-
context.safe(context.associationId(node), {
145+
state.safe(state.associationId(node), {
150146
...tracker.current(),
151147
before: value,
152148
after: ']'
@@ -167,13 +163,13 @@ function footnoteReferencePeek() {
167163
* @type {ToMarkdownHandle}
168164
* @param {FootnoteDefinition} node
169165
*/
170-
function footnoteDefinition(node, _, context, safeOptions) {
171-
const tracker = context.createTracker(safeOptions)
166+
function footnoteDefinition(node, _, state, info) {
167+
const tracker = state.createTracker(info)
172168
let value = tracker.move('[^')
173-
const exit = context.enter('footnoteDefinition')
174-
const subexit = context.enter('label')
169+
const exit = state.enter('footnoteDefinition')
170+
const subexit = state.enter('label')
175171
value += tracker.move(
176-
context.safe(context.associationId(node), {
172+
state.safe(state.associationId(node), {
177173
...tracker.current(),
178174
before: value,
179175
after: ']'
@@ -185,7 +181,7 @@ function footnoteDefinition(node, _, context, safeOptions) {
185181
)
186182
tracker.shift(4)
187183
value += tracker.move(
188-
context.indentLines(context.containerFlow(node, tracker.current()), map)
184+
state.indentLines(state.containerFlow(node, tracker.current()), map)
189185
)
190186
exit()
191187

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
],
3737
"dependencies": {
3838
"@types/mdast": "^4.0.0",
39+
"devlop": "^1.1.0",
3940
"mdast-util-from-markdown": "^2.0.0",
4041
"mdast-util-to-markdown": "^2.0.0",
4142
"micromark-util-normalize-identifier": "^2.0.0"
@@ -79,6 +80,16 @@
7980
"strict": true
8081
},
8182
"xo": {
83+
"overrides": [
84+
{
85+
"files": [
86+
"**/*.ts"
87+
],
88+
"rules": {
89+
"@typescript-eslint/consistent-type-definitions": "off"
90+
}
91+
}
92+
],
8293
"prettier": true
8394
}
8495
}

0 commit comments

Comments
 (0)