Skip to content

Commit 16cea75

Browse files
committedJul 15, 2021
Update unified
1 parent 30060d3 commit 16cea75

File tree

36 files changed

+173
-279
lines changed

36 files changed

+173
-279
lines changed
 

‎lib/configuration.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
2-
* @typedef {import('unified').Settings} Settings
3-
* @typedef {import('unified').Plugin} Plugin
4-
* @typedef {import('unified').PluginTuple} PluginTuple
2+
* @typedef {import('unified').Plugin<unknown[]>} Plugin
3+
* @typedef {import('unified').PluginTuple<unknown[]>} PluginTuple
54
* @typedef {import('unified').PluggableList} PluggableList
65
*
6+
* @typedef {Record<string, unknown>} Settings
7+
*
78
* @typedef {Record<string, Settings|null|undefined>} PluginIdObject
89
* @typedef {Array<string|[string, ...unknown[]]>} PluginIdList
910
*
@@ -205,7 +206,7 @@ export class Configuration {
205206
async function loadScriptOrModule(_, filePath) {
206207
// C8 bug on Node@12
207208
/* c8 ignore next 4 */
208-
// @ts-expect-error: Should be a config.
209+
// @ts-expect-error: Assume it matches config.
209210
// type-coverage:ignore-next-line
210211
return loadFromAbsolutePath(filePath, this.cwd)
211212
}
@@ -214,7 +215,7 @@ async function loadScriptOrModule(_, filePath) {
214215
async function loadYaml(buf, filePath) {
215216
// C8 bug on Node@12
216217
/* c8 ignore next 4 */
217-
// @ts-expect-error: Should be a config.
218+
// @ts-expect-error: Assume it matches config.
218219
return jsYaml.load(String(buf), {filename: path.basename(filePath)})
219220
}
220221

@@ -225,9 +226,10 @@ async function loadJson(buf, filePath) {
225226

226227
// C8 bug on Node@12
227228
/* c8 ignore next 7 */
228-
// @ts-expect-error: Should be a config.
229+
// @ts-expect-error: Assume it matches config.
229230
return path.basename(filePath) === 'package.json'
230-
? // @ts-expect-error: `this` is the configuration context.
231+
? // @ts-expect-error: `this` is the configuration context, TS doesn’t like
232+
// `this` on callbacks.
231233
// type-coverage:ignore-next-line
232234
result[this.packageField]
233235
: result
@@ -282,7 +284,7 @@ async function merge(target, raw, options) {
282284

283285
// Keep order sequential instead of parallel.
284286
/* eslint-disable no-await-in-loop */
285-
// @ts-expect-error: fine.
287+
// @ts-expect-error: Spreading is fine.
286288
// type-coverage:ignore-next-line
287289
await (Array.isArray(value) ? use(...value) : use(value, undefined))
288290
/* eslint-enable no-await-in-loop */
@@ -376,7 +378,6 @@ async function merge(target, raw, options) {
376378
function addPlugin(plugin, value) {
377379
const entry = find(target.plugins, plugin)
378380

379-
// To do: <https://github.com/unifiedjs/unified/pull/145>.
380381
if (value === null) {
381382
value = undefined
382383
}

‎lib/file-pipeline/configure.js

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export function configure(context, file, next) {
6464
)
6565

6666
try {
67-
// @ts-expect-error: unified types are wrong.
6867
context.processor.use(plugin, options, context.fileSet)
6968
/* Should not happen anymore! */
7069
/* c8 ignore next 3 */

‎lib/file-pipeline/stringify.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ export function stringify(context, file) {
6262
if (value === undefined || value === null) {
6363
// Empty.
6464
} else if (typeof value === 'string' || isBuffer(value)) {
65-
// @ts-expect-error: fine.
65+
// @ts-expect-error: `isBuffer` checks buffer.
6666
file.value = value
6767
} else {
68-
// @ts-expect-error: non-string compiler.
6968
file.result = value
7069
}
7170

‎lib/file-pipeline/transform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function transform(context, file, next) {
2121
next()
2222
} else {
2323
debug('Transforming document `%s`', file.path)
24-
// @ts-expect-error: `tree` is defined.
24+
// @ts-expect-error: `tree` is defined at this point.
2525
context.processor.run(context.tree, file, (error, node) => {
2626
debug('Transformed document (error: %s)', error)
2727
context.tree = node

‎lib/find-up.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class FindUp {
209209
*/
210210
function found(error, result) {
211211
/** @type {Callback[]} */
212-
// @ts-expect-error: always a list.
212+
// @ts-expect-error: always a list if found.
213213
const cbs = self.cache[directory]
214214
self.cache[directory] = error || result
215215
applyAll(cbs, error || result)

‎lib/finder.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ export function finder(input, options, callback) {
4646
// Glob errors are unusual.
4747
// other errors are on the vfile results.
4848
/* c8 ignore next 2 */
49-
if (error) {
49+
if (error || !result) {
5050
callback(error)
5151
} else {
52-
// @ts-expect-error: either `error` or `result` is given.
5352
callback(null, {oneFileMode: oneFileMode(result), files: result.output})
5453
}
5554
})
@@ -124,10 +123,9 @@ function expand(input, options, next) {
124123
function done1(error, files) {
125124
// `search` currently does not give errors.
126125
/* c8 ignore next 2 */
127-
if (error) {
126+
if (error || !files) {
128127
next(error)
129128
} else {
130-
// @ts-expect-error: either `error` or `files` are given.
131129
next(null, {input: paths, output: files})
132130
}
133131
}

‎lib/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* @typedef {import('vfile').VFile} VFile
3+
* @typedef {import('unified').Processor} Processor
34
* @typedef {import('./file-set.js').FileSet} FileSet
45
* @typedef {import('./file-set.js').Completer} Completer
56
* @typedef {import('./ignore.js').ResolveFrom} ResolveFrom
@@ -58,7 +59,7 @@
5859
*
5960
* @typedef Options
6061
* Options for unified engine
61-
* @property {import('unified').Processor<>} processor
62+
* @property {Processor} processor
6263
* Unified processor to transform files
6364
* @property {string} [cwd]
6465
* Directory to search files in, load plugins from, and more.
@@ -181,10 +182,11 @@ import {fileSetPipeline} from './file-set-pipeline/index.js'
181182
export function engine(options, callback) {
182183
/** @type {Settings} */
183184
const settings = {}
185+
/** @type {NodeJS.ReadStream} */
186+
// @ts-expect-error: `PassThrough` sure is readable.
184187
let stdin = new PassThrough()
185188

186189
try {
187-
// @ts-expect-error: fine.
188190
stdin = process.stdin
189191
// Obscure bug in Node (seen on Windows).
190192
// See: <https://github.com/nodejs/node/blob/f856234/lib/internal/process/stdio.js#L82>,

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"tape": "^5.0.0",
6868
"type-coverage": "^2.0.0",
6969
"typescript": "^4.0.0",
70-
"unified": "^10.0.0-beta.1",
70+
"unified": "^10.0.0",
7171
"vfile": "^5.0.0",
7272
"vfile-reporter-json": "^3.0.0",
7373
"vfile-reporter-pretty": "^6.0.0",

‎test/completers.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
2+
* @typedef {import('unified').Plugin<[unknown, FileSet]>} FileSetPlugin
23
* @typedef {import('../index.js').FileSet} FileSet
34
*/
45

@@ -28,10 +29,7 @@ test('completers', (t) => {
2829
processor: noop,
2930
streamError: stderr.stream,
3031
plugins: [
31-
/**
32-
* @param {unknown} _
33-
* @param {FileSet} set
34-
*/
32+
/** @type {FileSetPlugin} */
3533
function (_, set) {
3634
t.equal(typeof set, 'object', 'should pass a set')
3735
t.equal(typeof set.use, 'function', 'should have a `use` method')
@@ -104,10 +102,7 @@ test('completers', (t) => {
104102
processor: noop,
105103
streamError: stderr.stream,
106104
plugins: [
107-
/**
108-
* @param {unknown} _
109-
* @param {FileSet} set
110-
*/
105+
/** @type {FileSetPlugin} */
111106
function (_, set) {
112107
set.add('bar.text')
113108
}

‎test/configuration-default.js

+6-16
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ test('`defaultConfig`', (t) => {
2121

2222
engine(
2323
{
24-
// @ts-expect-error: unified types are wrong.
25-
processor: noop().use(addTest),
24+
processor: noop().use(function () {
25+
Object.assign(this, {t})
26+
}),
2627
streamError: stderr.stream,
2728
cwd: path.join(fixtures, 'config-default'),
2829
files: ['.'],
@@ -38,12 +39,6 @@ test('`defaultConfig`', (t) => {
3839
)
3940
}
4041
)
41-
42-
function addTest() {
43-
// Used in test.
44-
// type-coverage:ignore-next-line
45-
this.t = t
46-
}
4742
})
4843

4944
t.test('should use found otherwise', (t) => {
@@ -53,8 +48,9 @@ test('`defaultConfig`', (t) => {
5348

5449
engine(
5550
{
56-
// @ts-expect-error: unified types are wrong.
57-
processor: noop().use(addTest),
51+
processor: noop().use(function () {
52+
Object.assign(this, {t})
53+
}),
5854
streamError: stderr.stream,
5955
cwd: path.join(fixtures, 'config-default'),
6056
files: ['.'],
@@ -70,11 +66,5 @@ test('`defaultConfig`', (t) => {
7066
)
7167
}
7268
)
73-
74-
function addTest() {
75-
// Used in test.
76-
// type-coverage:ignore-next-line
77-
this.t = t
78-
}
7969
})
8070
})

‎test/configuration-plugins.js

+9-24
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ test('configuration', (t) => {
1717

1818
engine(
1919
{
20-
// @ts-expect-error: unified types are wrong.
21-
processor: noop().use(addTest),
20+
processor: noop().use(function () {
21+
Object.assign(this, {t})
22+
}),
2223
cwd: path.join(fixtures, 'config-plugins-cascade'),
2324
streamError: stderr.stream,
2425
files: ['.'],
@@ -34,12 +35,6 @@ test('configuration', (t) => {
3435
)
3536
}
3637
)
37-
38-
function addTest() {
39-
// Used in test.
40-
// type-coverage:ignore-next-line
41-
this.t = t
42-
}
4338
})
4439

4540
t.test('should support an ESM plugin w/ an `.mjs` extname', (t) => {
@@ -50,8 +45,9 @@ test('configuration', (t) => {
5045

5146
engine(
5247
{
53-
// @ts-expect-error: unified types are wrong.
54-
processor: noop().use(addTest),
48+
processor: noop().use(function () {
49+
Object.assign(this, {t})
50+
}),
5551
cwd: path.join(fixtures, 'config-plugins-esm-mjs'),
5652
streamError: stderr.stream,
5753
files: ['one.txt'],
@@ -65,12 +61,6 @@ test('configuration', (t) => {
6561
)
6662
}
6763
)
68-
69-
function addTest() {
70-
// Used in test.
71-
// type-coverage:ignore-next-line
72-
this.t = t
73-
}
7464
})
7565

7666
t.test('should support an ESM plugin w/ a `.js` extname', (t) => {
@@ -81,8 +71,9 @@ test('configuration', (t) => {
8171

8272
engine(
8373
{
84-
// @ts-expect-error: unified types are wrong.
85-
processor: noop().use(addTest),
74+
processor: noop().use(function () {
75+
Object.assign(this, {t})
76+
}),
8677
cwd: path.join(fixtures, 'config-plugins-esm-js'),
8778
streamError: stderr.stream,
8879
files: ['one.txt'],
@@ -96,12 +87,6 @@ test('configuration', (t) => {
9687
)
9788
}
9889
)
99-
100-
function addTest() {
101-
// Used in test.
102-
// type-coverage:ignore-next-line
103-
this.t = t
104-
}
10590
})
10691

10792
t.test('should handle failing plugins', (t) => {

‎test/configuration-presets.js

+28-40
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ test('configuration-presets', (t) => {
5151

5252
engine(
5353
{
54-
// @ts-expect-error: unified types are wrong.
55-
processor: noop().use(addTest),
54+
processor: noop().use(function () {
55+
Object.assign(this, {t})
56+
}),
5657
cwd: path.join(fixtures, 'config-presets-local'),
5758
streamError: stderr.stream,
5859
files: ['.'],
@@ -67,12 +68,6 @@ test('configuration-presets', (t) => {
6768
)
6869
}
6970
)
70-
71-
function addTest() {
72-
// Used in test.
73-
// type-coverage:ignore-next-line
74-
this.t = t
75-
}
7671
})
7772

7873
t.test('should handle missing plugins in presets', (t) => {
@@ -114,8 +109,9 @@ test('configuration-presets', (t) => {
114109

115110
engine(
116111
{
117-
// @ts-expect-error: unified types are wrong.
118-
processor: noop().use(addTest),
112+
processor: noop().use(function () {
113+
Object.assign(this, {t})
114+
}),
119115
cwd: path.join(fixtures, 'config-plugins-reconfigure'),
120116
streamError: stderr.stream,
121117
files: ['.'],
@@ -130,12 +126,6 @@ test('configuration-presets', (t) => {
130126
)
131127
}
132128
)
133-
134-
function addTest() {
135-
// Used in test.
136-
// type-coverage:ignore-next-line
137-
this.t = t
138-
}
139129
})
140130

141131
t.test('should reconfigure imported plugins', (t) => {
@@ -146,8 +136,9 @@ test('configuration-presets', (t) => {
146136

147137
engine(
148138
{
149-
// @ts-expect-error: unified types are wrong.
150-
processor: noop().use(addTest),
139+
processor: noop().use(function () {
140+
Object.assign(this, {t})
141+
}),
151142
cwd: path.join(fixtures, 'config-preset-plugins-reconfigure'),
152143
streamError: stderr.stream,
153144
files: ['.'],
@@ -162,12 +153,6 @@ test('configuration-presets', (t) => {
162153
)
163154
}
164155
)
165-
166-
function addTest() {
167-
// Used in test.
168-
// type-coverage:ignore-next-line
169-
this.t = t
170-
}
171156
})
172157

173158
t.test('Should reconfigure: turn plugins off', (t) => {
@@ -202,15 +187,16 @@ test('configuration-presets', (t) => {
202187

203188
engine(
204189
{
205-
// @ts-expect-error: unified types are wrong.
206190
processor: noop().use(function () {
207-
/**
208-
* @type {ParserFunction}
209-
* @returns {Literal}
210-
*/
211-
this.Parser = function (doc) {
212-
return {type: 'text', value: doc}
213-
}
191+
Object.assign(this, {
192+
/**
193+
* @type {ParserFunction}
194+
* @returns {Literal}
195+
*/
196+
Parser(doc) {
197+
return {type: 'text', value: doc}
198+
}
199+
})
214200

215201
t.deepEqual(this.data('settings'), {alpha: true}, 'should configure')
216202
}),
@@ -237,16 +223,18 @@ test('configuration-presets', (t) => {
237223

238224
engine(
239225
{
240-
// @ts-expect-error: unified types are wrong.
241226
processor: noop().use(function () {
242227
t.deepEqual(this.data('settings'), {alpha: true}, 'should configure')
243-
/**
244-
* @type {ParserFunction}
245-
* @returns {Literal}
246-
*/
247-
this.Parser = function (doc) {
248-
return {type: 'text', value: doc}
249-
}
228+
229+
Object.assign(this, {
230+
/**
231+
* @type {ParserFunction}
232+
* @returns {Literal}
233+
*/
234+
Parser(doc) {
235+
return {type: 'text', value: doc}
236+
}
237+
})
250238
}),
251239
cwd: path.join(fixtures, 'config-settings-reconfigure-b'),
252240
streamError: stderr.stream,

‎test/configuration-transform.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ test('`configTransform`', (t) => {
2222

2323
engine(
2424
{
25-
// @ts-expect-error: unified types are wrong.
26-
processor: noop().use(addTest),
25+
processor: noop().use(function () {
26+
Object.assign(this, {t})
27+
}),
2728
streamError: stderr.stream,
2829
cwd: path.join(fixtures, 'config-transform'),
2930
files: ['.'],
@@ -61,11 +62,5 @@ test('`configTransform`', (t) => {
6162
)
6263
}
6364
)
64-
65-
function addTest() {
66-
// Used in test.
67-
// type-coverage:ignore-next-line
68-
this.t = t
69-
}
7065
})
7166
})

‎test/configuration.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,18 @@ test('configuration', (t) => {
382382

383383
engine(
384384
{
385-
// @ts-expect-error: unified types are wrong.
386385
processor: noop().use(function () {
387386
t.deepEqual(this.data('settings'), {alpha: true}, 'should configure')
388-
/**
389-
* @type {ParserFunction}
390-
* @returns {Literal}
391-
*/
392-
this.Parser = (doc) => {
393-
return {type: 'text', value: doc}
394-
}
387+
388+
Object.assign(this, {
389+
/**
390+
* @type {ParserFunction}
391+
* @returns {Literal}
392+
*/
393+
Parser(doc) {
394+
return {type: 'text', value: doc}
395+
}
396+
})
395397
}),
396398
cwd: path.join(fixtures, 'config-settings'),
397399
streamError: stderr.stream,

‎test/fixtures/config-default/test-defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
module.exports = function (options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-default/test-found.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
module.exports = function (options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-basic-reconfigure/preset/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function plugin(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-cascade/nested/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
module.exports = function () {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-esm-js/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function test() {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-esm-mjs/test.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function test() {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function plugin() {
33
throw new Error('Should not run')
44
}

‎test/fixtures/config-plugins-reconfigure/preset/array-to-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function arrayToObject(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-reconfigure/preset/merge-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function mergeObject(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-reconfigure/preset/object-to-array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function objectToArray(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-reconfigure/preset/string-to-array.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function stringToArray(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-plugins-reconfigure/preset/string-to-object.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function stringToObject(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-preset-plugins-reconfigure/preset/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function plugin(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-presets-local/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function plugin(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-presets-local/preset/plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
export default function plugin(options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/config-transform/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @type {import('unified').Plugin} */
1+
/** @type {import('unified').Plugin<unknown[]>} */
22
module.exports = function (options) {
33
/** @type {import('tape').Test} */
44
// @ts-expect-error: hush.

‎test/fixtures/throwing-plugin/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @type {import('unified').Plugin}
2+
* @type {import('unified').Plugin<unknown[]>}
33
* @param {unknown} options
44
*/
55
module.exports = function (options) {

‎test/output.js

+35-72
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* @typedef {import('unified').CompilerFunction} CompilerFunction
3-
* @typedef {import('unified').Transformer} Transformer
4-
* @typedef {import('unist').Literal} Literal
2+
* @typedef {import('unified').Compiler} Compiler
3+
* @typedef {import('unist').Literal<string>} Literal
54
*/
65

76
import fs from 'fs'
@@ -26,14 +25,10 @@ test('output', (t) => {
2625

2726
engine(
2827
{
29-
// @ts-expect-error: unified types are wrong.
3028
processor: noop().use(() => {
31-
/**
32-
* @type {Transformer}
33-
* @param {Literal} tree
34-
*/
3529
return function (tree) {
36-
tree.value = 'two'
30+
const text = /** @type {Literal} */ (tree)
31+
text.value = 'two'
3732
}
3833
}),
3934
cwd,
@@ -61,14 +56,10 @@ test('output', (t) => {
6156

6257
engine(
6358
{
64-
// @ts-expect-error: unified types are wrong.
6559
processor: noop().use(() => {
66-
/**
67-
* @type {Transformer}
68-
* @param {Literal} tree
69-
*/
7060
return function (tree) {
71-
tree.value = 'two'
61+
const text = /** @type {Literal} */ (tree)
62+
text.value = 'two'
7263
}
7364
}),
7465
cwd,
@@ -96,14 +87,10 @@ test('output', (t) => {
9687

9788
engine(
9889
{
99-
// @ts-expect-error: unified types are wrong.
10090
processor: noop().use(() => {
101-
/**
102-
* @type {Transformer}
103-
* @param {Literal} tree
104-
*/
10591
return function (tree) {
106-
tree.value = 'two'
92+
const text = /** @type {Literal} */ (tree)
93+
text.value = 'two'
10794
}
10895
}),
10996
cwd,
@@ -132,14 +119,10 @@ test('output', (t) => {
132119

133120
engine(
134121
{
135-
// @ts-expect-error: unified types are wrong.
136122
processor: noop().use(() => {
137-
/**
138-
* @type {Transformer}
139-
* @param {Literal} tree
140-
*/
141123
return function (tree) {
142-
tree.value = 'two'
124+
const text = /** @type {Literal} */ (tree)
125+
text.value = 'two'
143126
}
144127
}),
145128
streamOut: stdout.stream,
@@ -167,14 +150,10 @@ test('output', (t) => {
167150

168151
engine(
169152
{
170-
// @ts-expect-error: unified types are wrong.
171153
processor: noop().use(() => {
172-
/**
173-
* @type {Transformer}
174-
* @param {Literal} tree
175-
*/
176154
return function (tree) {
177-
tree.value = 'two'
155+
const text = /** @type {Literal} */ (tree)
156+
text.value = 'two'
178157
}
179158
}),
180159
cwd,
@@ -205,14 +184,10 @@ test('output', (t) => {
205184

206185
engine(
207186
{
208-
// @ts-expect-error: unified types are wrong.
209187
processor: noop().use(() => {
210-
/**
211-
* @type {Transformer}
212-
* @param {Literal} tree
213-
*/
214188
return function (tree) {
215-
tree.value = 'two'
189+
const text = /** @type {Literal} */ (tree)
190+
text.value = 'two'
216191
}
217192
}),
218193
cwd,
@@ -244,14 +219,10 @@ test('output', (t) => {
244219

245220
engine(
246221
{
247-
// @ts-expect-error: unified types are wrong.
248222
processor: noop().use(() => {
249-
/**
250-
* @type {Transformer}
251-
* @param {Literal} tree
252-
*/
253223
return function (tree) {
254-
tree.value = 'two'
224+
const text = /** @type {Literal} */ (tree)
225+
text.value = 'two'
255226
}
256227
}),
257228
cwd,
@@ -323,14 +294,10 @@ test('output', (t) => {
323294

324295
engine(
325296
{
326-
// @ts-expect-error: unified types are wrong.
327297
processor: noop().use(() => {
328-
/**
329-
* @type {Transformer}
330-
* @param {Literal} tree
331-
*/
332298
return function (tree) {
333-
tree.value = 'two'
299+
const text = /** @type {Literal} */ (tree)
300+
text.value = 'two'
334301
}
335302
}),
336303
cwd,
@@ -360,14 +327,10 @@ test('output', (t) => {
360327

361328
engine(
362329
{
363-
// @ts-expect-error: unified types are wrong.
364330
processor: noop().use(() => {
365-
/**
366-
* @type {Transformer}
367-
* @param {Literal} tree
368-
*/
369331
return function (tree, file) {
370-
tree.value = 'two'
332+
const text = /** @type {Literal} */ (tree)
333+
text.value = 'two'
371334
file.history = []
372335
}
373336
}),
@@ -494,12 +457,12 @@ test('output', (t) => {
494457

495458
engine(
496459
{
497-
// @ts-expect-error: unified types are wrong.
498460
processor: noop().use(function () {
499-
/** @type {CompilerFunction} */
500-
this.Compiler = function () {
501-
return Buffer.from('bravo')
502-
}
461+
Object.assign(this, {
462+
Compiler() {
463+
return Buffer.from('bravo')
464+
}
465+
})
503466
}),
504467
cwd,
505468
streamOut: stdout.stream,
@@ -526,12 +489,12 @@ test('output', (t) => {
526489

527490
engine(
528491
{
529-
// @ts-expect-error: unified types are wrong.
530492
processor: noop().use(function () {
531-
/** @type {CompilerFunction} */
532-
this.Compiler = function () {
533-
return null
534-
}
493+
Object.assign(this, {
494+
Compiler() {
495+
return null
496+
}
497+
})
535498
}),
536499
cwd,
537500
streamOut: stdout.stream,
@@ -558,12 +521,12 @@ test('output', (t) => {
558521

559522
engine(
560523
{
561-
// @ts-expect-error: unified types are wrong.
562524
processor: noop().use(function () {
563-
/** @type {CompilerFunction} */
564-
this.Compiler = function () {
565-
return {type: 'some-virtual-dom'}
566-
}
525+
Object.assign(this, {
526+
Compiler() {
527+
return {type: 'some-virtual-dom'}
528+
}
529+
})
567530
}),
568531
cwd,
569532
streamOut: stdout.stream,

‎test/settings-and-plugins.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ test('settings', (t) => {
2222

2323
engine(
2424
{
25-
// @ts-expect-error: unified types wrong.
2625
processor: noop().use(function () {
2726
t.deepEqual(this.data('settings'), {alpha: true}, 'should configure')
2827

29-
/**
30-
* @type {ParserFunction}
31-
* @returns {Literal}
32-
*/
33-
this.Parser = function (doc) {
34-
return {type: 'text', value: doc}
35-
}
28+
Object.assign(this, {
29+
/**
30+
* @type {ParserFunction}
31+
* @returns {Literal}
32+
*/
33+
Parser(doc) {
34+
return {type: 'text', value: doc}
35+
}
36+
})
3637
}),
3738
cwd: path.join(fixtures, 'one-file'),
3839
streamError: stderr.stream,
@@ -57,21 +58,22 @@ test('settings', (t) => {
5758

5859
engine(
5960
{
60-
// @ts-expect-error: unified types wrong.
6161
processor: noop().use(function () {
6262
t.deepEqual(
6363
this.data('settings'),
6464
{alpha: false, bravo: 'charlie', delta: 1},
6565
'should configure'
6666
)
6767

68-
/**
69-
* @type {ParserFunction}
70-
* @returns {Literal}
71-
*/
72-
this.Parser = function (doc) {
73-
return {type: 'text', value: doc}
74-
}
68+
Object.assign(this, {
69+
/**
70+
* @type {ParserFunction}
71+
* @returns {Literal}
72+
*/
73+
Parser(doc) {
74+
return {type: 'text', value: doc}
75+
}
76+
})
7577
}),
7678
cwd: path.join(fixtures, 'config-settings-cascade'),
7779
streamError: stderr.stream,
@@ -140,10 +142,8 @@ test('plugins', (t) => {
140142

141143
engine(
142144
{
143-
// @ts-expect-error: unified types wrong.
144145
processor: noop().use(function () {
145-
// @ts-expect-error: tests.
146-
this.t = t
146+
Object.assign(this, {t})
147147
}),
148148
cwd: path.join(fixtures, 'config-plugins-basic-reconfigure'),
149149
streamError: stderr.stream,
@@ -171,10 +171,8 @@ test('plugins', (t) => {
171171

172172
engine(
173173
{
174-
// @ts-expect-error: unified types wrong.
175174
processor: noop().use(function () {
176-
// @ts-expect-error: tests.
177-
this.t = t
175+
Object.assign(this, {t})
178176
}),
179177
cwd: path.join(fixtures, 'config-plugins-basic-reconfigure'),
180178
streamError: stderr.stream,

‎test/tree.js

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
2-
* @typedef {import('unified').Transformer} Transformer
3-
* @typedef {import('unist').Literal} Literal
2+
* @typedef {import('unist').Literal<string>} Literal
43
*/
54

65
import fs from 'fs'
@@ -51,14 +50,10 @@ test('tree', (t) => {
5150

5251
engine(
5352
{
54-
// @ts-expect-error: unified types are wrong.
5553
processor: noop().use(() => {
56-
/**
57-
* @type {Transformer}
58-
* @param {Literal} tree
59-
*/
6054
return function (tree) {
61-
tree.value = 'two'
55+
const text = /** @type {Literal} */ (tree)
56+
text.value = 'two'
6257
}
6358
}),
6459
cwd,
@@ -94,14 +89,10 @@ test('tree', (t) => {
9489

9590
engine(
9691
{
97-
// @ts-expect-error: unified types are wrong.
9892
processor: noop().use(() => {
99-
/**
100-
* @type {Transformer}
101-
* @param {Literal} tree
102-
*/
10393
return function (tree) {
104-
tree.value = 'two'
94+
const text = /** @type {Literal} */ (tree)
95+
text.value = 'two'
10596
}
10697
}),
10798
cwd,
@@ -133,14 +124,10 @@ test('tree', (t) => {
133124

134125
engine(
135126
{
136-
// @ts-expect-error: unified types are wrong.
137127
processor: noop().use(() => {
138-
/**
139-
* @type {Transformer}
140-
* @param {Literal} tree
141-
*/
142128
return function (tree) {
143-
tree.value = 'two'
129+
const text = /** @type {Literal} */ (tree)
130+
text.value = 'two'
144131
}
145132
}),
146133
cwd,

‎test/util/noop-processor.js

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
/**
2-
* @typedef {import('unified').ParserFunction} ParserFunction
3-
* @typedef {import('unified').CompilerFunction} CompilerFunction
4-
* @typedef {import('unist').Literal} Literal
2+
* @typedef {import('unist').Literal<string>} Literal
53
*/
64

75
import {unified} from 'unified'
86

9-
// @ts-expect-error: unified types are wrong.
10-
export const noop = unified().use(function () {
11-
/**
12-
* @type {ParserFunction}
13-
* @returns {Literal}
14-
*/
15-
this.Parser = (doc) => {
16-
return {type: 'text', value: doc}
17-
}
7+
/** @type {import('unified').Plugin<unknown[]>} */
8+
function plug() {
9+
Object.assign(this, {
10+
/** @param {string} doc */
11+
Parser(doc) {
12+
return {type: 'text', value: doc}
13+
},
14+
/** @param {Literal} tree */
15+
Compiler(tree) {
16+
return tree.value
17+
}
18+
})
19+
}
1820

19-
/**
20-
* @type {CompilerFunction}
21-
* @param {Literal} tree
22-
*/
23-
// @ts-expect-error: fine.
24-
this.Compiler = (tree) => {
25-
return tree.value
26-
}
27-
})
21+
export const noop = unified().use(plug)

‎test/util/spy.js

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export function spy() {
88

99
/**
1010
* @param {string} chunk
11-
* @param {BufferEncoding|undefined} [encoding]
12-
* @param {((error: Error|null|undefined) => void)|undefined} [callback]
1311
*/
1412
// @ts-expect-error: hush.
1513
stream.write = (chunk, encoding, callback) => {

0 commit comments

Comments
 (0)
Please sign in to comment.