Skip to content

Commit 96de28a

Browse files
committed
Refactor types
1 parent fa97705 commit 96de28a

File tree

7 files changed

+50
-18
lines changed

7 files changed

+50
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
coverage/
55
node_modules/
66
yarn.lock
7+
!/index.d.ts

index.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export {inspectColor, inspectNoColor, inspect} from './lib/index.js'
2+
3+
// To do: next major: remove.
4+
/**
5+
* Deprecated, use `Options`.
6+
*/
7+
export type InspectOptions = Options
8+
9+
/**
10+
* Configuration.
11+
*/
12+
export interface Options {
13+
/**
14+
* Whether to include positional information (default: `true`).
15+
*/
16+
showPositions?: boolean | null | undefined
17+
}

index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
/**
2-
* @typedef {import('./lib/index.js').Options} Options
3-
*
4-
* @typedef {Options} InspectOptions
5-
* Deprecated, use `Options`.
6-
*/
7-
8-
export {inspect, inspectColor, inspectNoColor} from './lib/index.js'
1+
// Note: types exposed from `index.d.ts`.
2+
export {inspectColor, inspectNoColor, inspect} from './lib/index.js'

lib/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/**
2-
* @typedef {import('unist').Node} Node
2+
* @import {Options} from 'unist-util-inspect'
3+
* @import {Node} from 'unist'
34
*/
45

56
/**
6-
* @typedef Options
7-
* Configuration.
8-
* @property {boolean | null | undefined} [showPositions=true]
9-
* Whether to include positional information (default: `true`).
10-
*
117
* @typedef State
128
* Info passed around.
139
* @property {boolean} showPositions
@@ -29,6 +25,7 @@ import {color} from '#conditional-color'
2925
/* c8 ignore next */
3026
export const inspect = color ? inspectColor : inspectNoColor
3127

28+
// To do: next major (?): use `Object.hasOwn`.
3229
const own = {}.hasOwnProperty
3330

3431
const bold = ansiColor(1, 22)

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@
8686
"strict": true
8787
},
8888
"xo": {
89+
"overrides": [
90+
{
91+
"files": [
92+
"**/*.d.ts"
93+
],
94+
"rules": {
95+
"@typescript-eslint/array-type": [
96+
"error",
97+
{
98+
"default": "generic"
99+
}
100+
],
101+
"@typescript-eslint/ban-types": [
102+
"error",
103+
{
104+
"extendDefaults": true
105+
}
106+
],
107+
"@typescript-eslint/consistent-type-definitions": [
108+
"error",
109+
"interface"
110+
]
111+
}
112+
}
113+
],
89114
"prettier": true,
90115
"rules": {
91116
"unicorn/prefer-string-replace-all": "off"

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('nlcst').Root} NlcstRoot
2+
* @import {Root as NlcstRoot} from 'nlcst'
33
*/
44

55
import assert from 'node:assert/strict'

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
"exactOptionalPropertyTypes": true,
88
"lib": ["es2022"],
99
"module": "node16",
10-
// Remove after `retext` update.
11-
"skipLibCheck": true,
1210
"strict": true,
1311
"target": "es2022"
1412
},
1513
"exclude": ["coverage/", "node_modules/"],
16-
"include": ["**/*.js"]
14+
"include": ["**/*.js", "index.d.ts"]
1715
}

0 commit comments

Comments
 (0)