Skip to content

Commit 780f6b9

Browse files
committed
Refactor code-style
1 parent b27f90b commit 780f6b9

File tree

5 files changed

+380
-343
lines changed

5 files changed

+380
-343
lines changed

index.d.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export {
1010
/**
1111
* MDX expression node, occurring in flow (block).
1212
*/
13-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1413
export interface MdxFlowExpression extends MdastLiteral {
1514
/**
1615
* Node type.
@@ -24,15 +23,13 @@ export interface MdxFlowExpression extends MdastLiteral {
2423
/**
2524
* Program node from estree.
2625
*/
27-
// eslint-disable-next-line @typescript-eslint/ban-types
2826
estree?: Program | null | undefined
2927
} & MdastLiteral['data']
3028
}
3129

3230
/**
3331
* MDX expression node, occurring in text (phrasing).
3432
*/
35-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
3633
export interface MdxTextExpression extends MdastLiteral {
3734
/**
3835
* Node type.
@@ -46,27 +43,25 @@ export interface MdxTextExpression extends MdastLiteral {
4643
/**
4744
* Program node from estree.
4845
*/
49-
// eslint-disable-next-line @typescript-eslint/ban-types
5046
estree?: Program | null | undefined
5147
} & MdastLiteral['data']
5248
}
5349

50+
// To do: next major: remove.
5451
/**
5552
* Deprecated: use `MdxFlowExpression`.
5653
*/
57-
// eslint-disable-next-line @typescript-eslint/naming-convention
5854
export type MDXFlowExpression = MdxFlowExpression
5955

56+
// To do: next major: remove.
6057
/**
6158
* Deprecated: use `MdxTextExpression`.
6259
*/
63-
// eslint-disable-next-line @typescript-eslint/naming-convention
6460
export type MDXTextExpression = MdxTextExpression
6561

6662
/**
6763
* MDX expression node, occurring in flow (block), for hast.
6864
*/
69-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
7065
export interface MdxFlowExpressionHast extends HastLiteral {
7166
/**
7267
* Node type.
@@ -80,15 +75,13 @@ export interface MdxFlowExpressionHast extends HastLiteral {
8075
/**
8176
* Program node from estree.
8277
*/
83-
// eslint-disable-next-line @typescript-eslint/ban-types
8478
estree?: Program | null | undefined
8579
} & HastLiteral['data']
8680
}
8781

8882
/**
8983
* MDX expression node, occurring in text (phrasing), for hast.
9084
*/
91-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
9285
export interface MdxTextExpressionHast extends HastLiteral {
9386
/**
9487
* Node type.
@@ -102,14 +95,12 @@ export interface MdxTextExpressionHast extends HastLiteral {
10295
/**
10396
* Program node from estree.
10497
*/
105-
// eslint-disable-next-line @typescript-eslint/ban-types
10698
estree?: Program | null | undefined
10799
} & HastLiteral['data']
108100
}
109101

110102
// Add nodes to mdast content.
111103
declare module 'mdast' {
112-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
113104
interface RootContentMap {
114105
/**
115106
* MDX expression node, occurring in text (phrasing).
@@ -121,15 +112,13 @@ declare module 'mdast' {
121112
mdxFlowExpression: MdxFlowExpression
122113
}
123114

124-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
125115
interface PhrasingContentMap {
126116
/**
127117
* MDX expression node, occurring in text (phrasing).
128118
*/
129119
mdxTextExpression: MdxTextExpression
130120
}
131121

132-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
133122
interface BlockContentMap {
134123
/**
135124
* MDX expression node, occurring in flow (block).
@@ -140,7 +129,6 @@ declare module 'mdast' {
140129

141130
// Add nodes to hast content.
142131
declare module 'hast' {
143-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
144132
interface RootContentMap {
145133
/**
146134
* MDX expression node, occurring in flow (block).
@@ -152,7 +140,6 @@ declare module 'hast' {
152140
mdxTextExpression: MdxTextExpressionHast
153141
}
154142

155-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
156143
interface ElementContentMap {
157144
/**
158145
* MDX expression node, occurring in flow (block).

lib/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
44
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
55
*
6-
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
76
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle
7+
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
88
*
99
* @typedef {import('../index.js').MdxFlowExpression} MdxFlowExpression
1010
* @typedef {import('../index.js').MdxTextExpression} MdxTextExpression
1111
*/
1212

13+
import {ok as assert} from 'devlop'
14+
1315
/**
1416
* Extension for `mdast-util-from-markdown` to enable MDX expressions.
1517
*
@@ -72,9 +74,8 @@ function enterMdxTextExpression(token) {
7274
function exitMdxExpression(token) {
7375
const value = this.resume()
7476
const estree = token.estree
75-
const node = /** @type {MdxFlowExpression | MdxTextExpression} */ (
76-
this.stack[this.stack.length - 1]
77-
)
77+
const node = this.stack[this.stack.length - 1]
78+
assert(node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression')
7879
this.exit(token)
7980
node.value = value
8081

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@types/estree-jsx": "^1.0.0",
4141
"@types/hast": "^3.0.0",
4242
"@types/mdast": "^4.0.0",
43+
"devlop": "^1.0.0",
4344
"mdast-util-from-markdown": "^2.0.0",
4445
"mdast-util-to-markdown": "^2.0.0"
4546
},
@@ -85,6 +86,18 @@
8586
"strict": true
8687
},
8788
"xo": {
89+
"overrides": [
90+
{
91+
"files": [
92+
"**/*.ts"
93+
],
94+
"rules": {
95+
"@typescript-eslint/ban-types": "off",
96+
"@typescript-eslint/consistent-type-definitions": "off",
97+
"@typescript-eslint/naming-convention": "off"
98+
}
99+
}
100+
],
88101
"prettier": true
89102
}
90103
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ import {visit} from 'unist-util-visit'
372372
/** @type {import('mdast').Root} */
373373
const tree = getMdastNodeSomeHow()
374374

375-
visit(tree, (node) => {
375+
visit(tree, function (node) {
376376
// `node` can now be an expression node.
377377
})
378378
```

0 commit comments

Comments
 (0)