Skip to content

Commit 379dd6f

Browse files
committed
Refactor code-style
1 parent 99eccf9 commit 379dd6f

File tree

4 files changed

+363
-312
lines changed

4 files changed

+363
-312
lines changed

lib/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/**
22
* @typedef {import('mdast').Literal} Literal
3-
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
3+
*
44
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext
5+
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension
56
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle
67
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension
78
*
8-
* @typedef {import('micromark-extension-frontmatter').Options} Options
9-
* @typedef {import('micromark-extension-frontmatter').Matter} Matter
109
* @typedef {import('micromark-extension-frontmatter').Info} Info
10+
* @typedef {import('micromark-extension-frontmatter').Matter} Matter
11+
* @typedef {import('micromark-extension-frontmatter').Options} Options
1112
*/
1213

14+
import {ok as assert} from 'devlop'
1315
import {toMatters} from 'micromark-extension-frontmatter'
1416

1517
/**
1618
* Create an extension for `mdast-util-from-markdown`.
1719
*
1820
* @param {Options | null | undefined} [options]
19-
* Configuration.
21+
* Configuration (optional).
2022
* @returns {FromMarkdownExtension}
2123
* Extension for `mdast-util-from-markdown`.
2224
*/
@@ -62,7 +64,8 @@ function opener(matter) {
6264
*/
6365
function close(token) {
6466
const data = this.resume()
65-
const node = /** @type {Literal} */ (this.stack[this.stack.length - 1])
67+
const node = this.stack[this.stack.length - 1]
68+
assert('value' in node)
6669
this.exit(token)
6770
// Remove the initial and final eol.
6871
node.value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
@@ -81,7 +84,7 @@ function value(token) {
8184
* Create an extension for `mdast-util-to-markdown`.
8285
*
8386
* @param {Options | null | undefined} [options]
84-
* Configuration.
87+
* Configuration (optional).
8588
* @returns {ToMarkdownExtension}
8689
* Extension for `mdast-util-to-markdown`.
8790
*/
@@ -140,7 +143,7 @@ function handler(matter) {
140143
*
141144
* @param {Matter} matter
142145
* Structure.
143-
* @param {'open' | 'close'} prop
146+
* @param {'close' | 'open'} prop
144147
* Field to get.
145148
* @returns {string}
146149
* Fence.
@@ -158,7 +161,7 @@ function fence(matter, prop) {
158161
*
159162
* @param {Info | string} schema
160163
* Info object or value.
161-
* @param {'open' | 'close'} prop
164+
* @param {'close' | 'open'} prop
162165
* Field to get.
163166
* @returns {string}
164167
* Thing to use for the opening or closing.

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
],
3838
"dependencies": {
3939
"@types/mdast": "^4.0.0",
40+
"devlop": "^1.0.0",
4041
"mdast-util-from-markdown": "^2.0.0",
4142
"mdast-util-to-markdown": "^2.0.0",
4243
"micromark-extension-frontmatter": "^2.0.0"
@@ -80,6 +81,16 @@
8081
"strict": true
8182
},
8283
"xo": {
84+
"overrides": [
85+
{
86+
"files": [
87+
"**/*.ts"
88+
],
89+
"rules": {
90+
"@typescript-eslint/consistent-type-definitions": "off"
91+
}
92+
}
93+
],
8394
"prettier": true
8495
}
8596
}

test-types.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
import type {Literal} from 'mdast'
22

3-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
43
interface Toml extends Literal {
54
type: 'toml'
65
}
76

8-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
97
interface Json extends Literal {
108
type: 'json'
119
}
1210

13-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
1411
interface Custom extends Literal {
1512
type: 'custom'
1613
}
1714

1815
declare module 'mdast' {
19-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2016
interface RootContentMap {
2117
custom: Custom
2218
json: Json
2319
toml: Toml
2420
}
2521

26-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2722
interface FrontmatterContentMap {
2823
custom: Custom
2924
json: Json

0 commit comments

Comments
 (0)