From 510fe9e752e1de1ed465d923155830b231c77590 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 23 Apr 2024 18:06:21 +0200 Subject: [PATCH] Update dev-dependencies --- .github/workflows/main.yml | 6 +- index.test-d.ts | 4 +- lib/callable-instance.js | 8 +- package.json | 13 +- readme.md | 282 ++++++++++++++++++------------------- test/data.js | 10 +- test/parse.js | 8 +- test/process.js | 4 +- test/types.d.ts | 2 +- test/use.js | 18 +-- 10 files changed, 179 insertions(+), 176 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9730654f..278e62fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,13 +7,13 @@ jobs: name: ${{matrix.node}} on ${{matrix.os}} runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{matrix.node}} - run: npm install - run: npm test - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 strategy: matrix: os: diff --git a/index.test-d.ts b/index.test-d.ts index 36ecbfab..7039373f 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -187,8 +187,8 @@ unified() unified().use(function () { // Function. - this.parser = function (doc, file) { - expectType(doc) + this.parser = function (document, file) { + expectType(document) expectType(file) return {type: ''} } diff --git a/lib/callable-instance.js b/lib/callable-instance.js index 17c693de..3e46cabf 100644 --- a/lib/callable-instance.js +++ b/lib/callable-instance.js @@ -18,18 +18,18 @@ export const CallableInstance = // type-coverage:ignore-next-line constr.prototype ) - const func = proto[property] + const value = proto[property] /** @type {(...parameters: Array) => unknown} */ const apply = function () { - return func.apply(apply, arguments) + return value.apply(apply, arguments) } Object.setPrototypeOf(apply, proto) - const names = Object.getOwnPropertyNames(func) + const names = Object.getOwnPropertyNames(value) for (const p of names) { - const descriptor = Object.getOwnPropertyDescriptor(func, p) + const descriptor = Object.getOwnPropertyDescriptor(value, p) if (descriptor) Object.defineProperty(apply, p, descriptor) } diff --git a/package.json b/package.json index 8d2fc6ef..9e538ce5 100644 --- a/package.json +++ b/package.json @@ -58,14 +58,14 @@ "@types/hast": "^3.0.0", "@types/mdast": "^4.0.0", "@types/node": "^20.0.0", - "c8": "^8.0.0", + "c8": "^9.0.0", "prettier": "^3.0.0", - "remark-cli": "^11.0.0", - "remark-preset-wooorm": "^9.0.0", - "tsd": "^0.29.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "tsd": "^0.31.0", "type-coverage": "^2.0.0", "typescript": "^5.0.0", - "xo": "^0.56.0" + "xo": "^0.58.0" }, "scripts": { "build": "tsc --build --clean && tsc --build && node script/fix-types.js && type-coverage && tsd", @@ -107,7 +107,8 @@ "rules": { "@typescript-eslint/ban-types": "off", "@typescript-eslint/consistent-type-definitions": "off", - "@typescript-eslint/naming-convention": "off" + "@typescript-eslint/naming-convention": "off", + "import/no-duplicates": "off" } } ], diff --git a/readme.md b/readme.md index ae0b67fe..d175d7f6 100644 --- a/readme.md +++ b/readme.md @@ -12,65 +12,65 @@ ## Contents -* [What is this?](#what-is-this) -* [When should I use this?](#when-should-i-use-this) -* [Install](#install) -* [Use](#use) -* [Overview](#overview) -* [API](#api) - * [`processor()`](#processor) - * [`processor.compiler`](#processorcompiler) - * [`processor.data([key[, value]])`](#processordatakey-value) - * [`processor.freeze()`](#processorfreeze) - * [`processor.parse(file)`](#processorparsefile) - * [`processor.parser`](#processorparser) - * [`processor.process(file[, done])`](#processorprocessfile-done) - * [`processor.processSync(file)`](#processorprocesssyncfile) - * [`processor.run(tree[, file][, done])`](#processorruntree-file-done) - * [`processor.runSync(tree[, file])`](#processorrunsynctree-file) - * [`processor.stringify(tree[, file])`](#processorstringifytree-file) - * [`processor.use(plugin[, options])`](#processoruseplugin-options) - * [`CompileResultMap`](#compileresultmap) - * [`CompileResults`](#compileresults) - * [`Compiler`](#compiler) - * [`Data`](#data) - * [`Parser`](#parser) - * [`Pluggable`](#pluggable) - * [`PluggableList`](#pluggablelist) - * [`Plugin`](#plugin) - * [`PluginTuple`](#plugintuple) - * [`Preset`](#preset) - * [`ProcessCallback`](#processcallback) - * [`Processor`](#processor-1) - * [`RunCallback`](#runcallback) - * [`Settings`](#settings) - * [`TransformCallback`](#transformcallback) - * [`Transformer`](#transformer) -* [Types](#types) -* [Compatibility](#compatibility) -* [Contribute](#contribute) -* [Sponsor](#sponsor) -* [Acknowledgments](#acknowledgments) -* [License](#license) +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [Overview](#overview) +* [API](#api) + * [`processor()`](#processor) + * [`processor.compiler`](#processorcompiler) + * [`processor.data([key[, value]])`](#processordatakey-value) + * [`processor.freeze()`](#processorfreeze) + * [`processor.parse(file)`](#processorparsefile) + * [`processor.parser`](#processorparser) + * [`processor.process(file[, done])`](#processorprocessfile-done) + * [`processor.processSync(file)`](#processorprocesssyncfile) + * [`processor.run(tree[, file][, done])`](#processorruntree-file-done) + * [`processor.runSync(tree[, file])`](#processorrunsynctree-file) + * [`processor.stringify(tree[, file])`](#processorstringifytree-file) + * [`processor.use(plugin[, options])`](#processoruseplugin-options) + * [`CompileResultMap`](#compileresultmap) + * [`CompileResults`](#compileresults) + * [`Compiler`](#compiler) + * [`Data`](#data) + * [`Parser`](#parser) + * [`Pluggable`](#pluggable) + * [`PluggableList`](#pluggablelist) + * [`Plugin`](#plugin) + * [`PluginTuple`](#plugintuple) + * [`Preset`](#preset) + * [`ProcessCallback`](#processcallback) + * [`Processor`](#processor-1) + * [`RunCallback`](#runcallback) + * [`Settings`](#settings) + * [`TransformCallback`](#transformcallback) + * [`Transformer`](#transformer) +* [Types](#types) +* [Compatibility](#compatibility) +* [Contribute](#contribute) +* [Sponsor](#sponsor) +* [Acknowledgments](#acknowledgments) +* [License](#license) ## What is this? unified is two things: -* **unified** is a collective of 500+ free and open source packages that work - with content as structured data (ASTs) -* `unified` (this project) is the core package, used in 1.3m+ projects on GH, - to process content with plugins +* **unified** is a collective of 500+ free and open source packages that work + with content as structured data (ASTs) +* `unified` (this project) is the core package, used in 1.3m+ projects on GH, + to process content with plugins Several ecosystems are built on unified around different kinds of content. Notably, [remark][] (markdown), [rehype][] (HTML), and [retext][] (natural language). These ecosystems can be connected together. -* for more about us, see [`unifiedjs.com`][site] -* for updates, see [@unifiedjs][twitter] on Twitter -* for questions, see [support][] -* to help, see [contribute][] and [sponsor][] below +* for more about us, see [`unifiedjs.com`][site] +* for updates, see [@unifiedjs][twitter] on Twitter +* for questions, see [support][] +* to help, see [contribute][] and [sponsor][] below ## When should I use this? @@ -205,10 +205,10 @@ const processor = unified() That processor can do different things. It can: -* …parse markdown (`parse`) -* …turn parsed markdown into HTML and format the HTML (`run`) -* …compile HTML (`stringify`) -* …do all of the above (`process`) +* …parse markdown (`parse`) +* …turn parsed markdown into HTML and format the HTML (`run`) +* …compile HTML (`stringify`) +* …do all of the above (`process`) Every processor implements another processor. To create a processor, call another processor. @@ -238,11 +238,11 @@ object with a `type` field. The semantics of nodes and the format of syntax trees is defined by other projects: -* [esast][] — JavaScript -* [hast][] — HTML -* [mdast][] — markdown -* [nlcst][] — natural language -* [xast][] — XML +* [esast][] — JavaScript +* [hast][] — HTML +* [mdast][] — markdown +* [nlcst][] — natural language +* [xast][] — XML There are many utilities for working with trees listed in each aforementioned project and maintained in the [`syntax-tree`][syntax-tree] organization. @@ -261,9 +261,9 @@ At their core, they parse text to a tree and compile that tree back to text. They also provide plugins that work with the syntax tree, without requiring that the end user has knowledge about that tree. -* [rehype][] (hast) — HTML -* [remark][] (mdast) — markdown -* [retext][] (nlcst) — natural language +* [rehype][] (hast) — HTML +* [remark][] (mdast) — markdown +* [retext][] (nlcst) — natural language @@ -272,24 +272,24 @@ that the end user has knowledge about that tree. Each aforementioned ecosystem comes with a large set of plugins that you can pick and choose from to do all kinds of things. -* [List of remark plugins][remark-plugins] · - [`remarkjs/awesome-remark`][awesome-remark] · - [`remark-plugin` topic][topic-remark-plugin] -* [List of rehype plugins][rehype-plugins] · - [`rehypejs/awesome-rehype`][awesome-rehype] · - [`rehype-plugin` topic][topic-rehype-plugin] -* [List of retext plugins][retext-plugins] · - [`retextjs/awesome-retext`][awesome-retext] · - [`retext-plugin` topic][topic-retext-plugin] +* [List of remark plugins][remark-plugins] · + [`remarkjs/awesome-remark`][awesome-remark] · + [`remark-plugin` topic][topic-remark-plugin] +* [List of rehype plugins][rehype-plugins] · + [`rehypejs/awesome-rehype`][awesome-rehype] · + [`rehype-plugin` topic][topic-rehype-plugin] +* [List of retext plugins][retext-plugins] · + [`retextjs/awesome-retext`][awesome-retext] · + [`retext-plugin` topic][topic-retext-plugin] There are also a few plugins that work in any ecosystem: -* [`unified-diff`](https://github.com/unifiedjs/unified-diff) - — ignore unrelated messages in GitHub Actions and Travis -* [`unified-infer-git-meta`](https://github.com/unifiedjs/unified-infer-git-meta) - — infer metadata of a document from Git -* [`unified-message-control`](https://github.com/unifiedjs/unified-message-control) - — enable, disable, and ignore messages from content +* [`unified-diff`](https://github.com/unifiedjs/unified-diff) + — ignore unrelated messages in GitHub Actions and Travis +* [`unified-infer-git-meta`](https://github.com/unifiedjs/unified-infer-git-meta) + — infer metadata of a document from Git +* [`unified-message-control`](https://github.com/unifiedjs/unified-message-control) + — enable, disable, and ignore messages from content ###### Configuration @@ -371,10 +371,10 @@ the origin tree. The following plugins lets you combine ecosystems: -* [`remark-retext`][remark-retext] — turn markdown into natural language -* [`remark-rehype`][remark-rehype] — turn markdown into HTML -* [`rehype-retext`][rehype-retext] — turn HTML into natural language -* [`rehype-remark`][rehype-remark] — turn HTML into markdown +* [`remark-retext`][remark-retext] — turn markdown into natural language +* [`remark-rehype`][remark-rehype] — turn markdown into HTML +* [`rehype-retext`][rehype-retext] — turn HTML into natural language +* [`rehype-remark`][rehype-remark] — turn HTML into markdown ## API @@ -433,16 +433,16 @@ during all [phases][overview]. ###### Signatures -* `processor = processor.data(key, value)` -* `processor = processor.data(dataset)` -* `value = processor.data(key)` -* `dataset = processor.data()` +* `processor = processor.data(key, value)` +* `processor = processor.data(dataset)` +* `value = processor.data(key)` +* `dataset = processor.data()` ###### Parameters -* `key` ([`keyof Data`][api-data], optional) — field to get -* `value` ([`Data[key]`][api-data]) — value to set -* `values` ([`Data`][api-data]) — values to set +* `key` ([`keyof Data`][api-data], optional) — field to get +* `value` ([`Data[key]`][api-data]) — value to set +* `values` ([`Data`][api-data]) — values to set ###### Returns @@ -550,8 +550,8 @@ Parse text to a syntax tree. ###### Parameters -* `file` ([`Compatible`][vfile-compatible]) — file to parse; typically - `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` +* `file` ([`Compatible`][vfile-compatible]) — file to parse; typically + `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` ###### Returns @@ -601,14 +601,14 @@ Process the given file as configured on the processor. ###### Signatures -* `processor.process(file, done)` -* `Promise = processor.process(file?)` +* `processor.process(file, done)` +* `Promise = processor.process(file?)` ###### Parameters -* `file` ([`Compatible`][vfile-compatible], optional) — file; typically - `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` -* `done` ([`ProcessCallback`][api-process-callback], optional) — callback +* `file` ([`Compatible`][vfile-compatible], optional) — file; typically + `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` +* `done` ([`ProcessCallback`][api-process-callback], optional) — callback ###### Returns @@ -683,8 +683,8 @@ An error is thrown if asynchronous transforms are configured. ###### Parameters -* `file` ([`Compatible`][vfile-compatible], optional) — file; typically - `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` +* `file` ([`Compatible`][vfile-compatible], optional) — file; typically + `string` or [`VFile`][vfile]; any value accepted as `x` in `new VFile(x)` ###### Returns @@ -754,16 +754,16 @@ Run *[transformers][api-transformer]* on a syntax tree. ###### Signatures -* `processor.run(tree, done)` -* `processor.run(tree, file, done)` -* `Promise = processor.run(tree, file?)` +* `processor.run(tree, done)` +* `processor.run(tree, file, done)` +* `Promise = processor.run(tree, file?)` ###### Parameters -* `tree` ([`Node`][node]) — tree to transform and inspect -* `file` ([`Compatible`][vfile-compatible], optional) — file associated - with `node`; any value accepted as `x` in `new VFile(x)` -* `done` ([`RunCallback`][api-run-callback], optional) — callback +* `tree` ([`Node`][node]) — tree to transform and inspect +* `file` ([`Compatible`][vfile-compatible], optional) — file associated + with `node`; any value accepted as `x` in `new VFile(x)` +* `done` ([`RunCallback`][api-run-callback], optional) — callback ###### Returns @@ -816,9 +816,9 @@ An error is thrown if asynchronous transforms are configured. ###### Parameters -* `tree` ([`Node`][node]) — tree to transform and inspect -* `file` ([`Compatible`][vfile-compatible], optional) — file associated - with `node`; any value accepted as `x` in `new VFile(x)` +* `tree` ([`Node`][node]) — tree to transform and inspect +* `file` ([`Compatible`][vfile-compatible], optional) — file associated + with `node`; any value accepted as `x` in `new VFile(x)` ###### Returns @@ -836,9 +836,9 @@ Compile a syntax tree. ###### Parameters -* `tree` ([`Node`][node]) — tree to compile -* `file` ([`Compatible`][vfile-compatible], optional) — file associated - with `node`; any value accepted as `x` in `new VFile(x)` +* `tree` ([`Node`][node]) — tree to compile +* `file` ([`Compatible`][vfile-compatible], optional) — file associated + with `node`; any value accepted as `x` in `new VFile(x)` ###### Returns @@ -866,9 +866,9 @@ import {unified} from 'unified' const tree = h('h1', 'Hello world!') -const doc = unified().use(rehypeStringify).stringify(tree) +const document = unified().use(rehypeStringify).stringify(tree) -console.log(doc) +console.log(document) ``` Yields: @@ -890,17 +890,17 @@ In other words, the plugin is not added a second time. ###### Signatures -* `processor.use(preset?)` -* `processor.use(list)` -* `processor.use(plugin[, ...parameters])` +* `processor.use(preset?)` +* `processor.use(list)` +* `processor.use(plugin[, ...parameters])` ###### Parameters -* `preset` ([`Preset`][api-preset]) — plugins and settings -* `list` ([`PluggableList`][api-pluggable-list]) — list of usable things -* `plugin` ([`Plugin`][api-plugin]) — plugin -* `parameters` (`Array`) — configuration for `plugin`, typically a - single options object +* `preset` ([`Preset`][api-preset]) — plugins and settings +* `list` ([`PluggableList`][api-pluggable-list]) — list of usable things +* `plugin` ([`Plugin`][api-plugin]) — plugin +* `parameters` (`Array`) — configuration for `plugin`, typically a + single options object ###### Returns @@ -1085,9 +1085,9 @@ Single plugin (TypeScript type). Plugins configure the processors they are applied on in the following ways: -* they change the processor, such as the parser, the compiler, or by - configuring data -* they specify how to handle trees and files +* they change the processor, such as the parser, the compiler, or by + configuring data +* they specify how to handle trees and files In practice, they are functions that can receive options and configure the processor (`this`). @@ -1219,10 +1219,10 @@ They can contain plugins and settings. ###### Fields -* `plugins` ([`PluggableList`][api-pluggable-list], optional) - — list of plugins and presets -* `settings` ([`Data`][api-data], optional) - — shared settings for parsers and compilers +* `plugins` ([`PluggableList`][api-pluggable-list], optional) + — list of plugins and presets +* `settings` ([`Data`][api-data], optional) + — shared settings for parsers and compilers ###### Example @@ -1313,10 +1313,10 @@ Called with either an error or a result. ###### Parameters -* `error` (`Error`, optional) - — fatal error -* `file` ([`VFile`][vfile], optional) - — processed file +* `error` (`Error`, optional) + — fatal error +* `file` ([`VFile`][vfile], optional) + — processed file ###### Returns @@ -1368,12 +1368,12 @@ Called with either an error or results. ###### Parameters -* `error` (`Error`, optional) - — fatal error -* `tree` ([`Node`][node], optional) - — transformed tree -* `file` ([`VFile`][vfile], optional) - — file +* `error` (`Error`, optional) + — fatal error +* `tree` ([`Node`][node], optional) + — transformed tree +* `file` ([`VFile`][vfile], optional) + — file ###### Returns @@ -1419,12 +1419,12 @@ may perform asynchronous operations, and must call it. ###### Parameters -* `error` (`Error`, optional) - — fatal error to stop the process -* `tree` ([`Node`][node], optional) - — new, changed, tree -* `file` ([`VFile`][vfile], optional) - — new, changed, file +* `error` (`Error`, optional) + — fatal error to stop the process +* `tree` ([`Node`][node], optional) + — new, changed, tree +* `file` ([`VFile`][vfile], optional) + — new, changed, file ###### Returns diff --git a/test/data.js b/test/data.js index 7d80ce1f..5dd49da5 100644 --- a/test/data.js +++ b/test/data.js @@ -41,12 +41,14 @@ test('`data`', async function (t) { }) await t.test('should support functions in data', async function () { - const fn = unified().data('fn', func)().data('fn') + const actual = unified() + .data('functionValue', value)() + .data('functionValue') - assert(typeof fn === 'function') - assert.equal(fn, func) + assert(typeof actual === 'function') + assert.equal(actual, value) - function func() { + function value() { return 'alpha' } }) diff --git a/test/parse.js b/test/parse.js index 9e969ad3..b3f2a326 100644 --- a/test/parse.js +++ b/test/parse.js @@ -19,8 +19,8 @@ test('`parse`', async function (t) { await t.test('should support a plain function', async function () { const processor = unified() - processor.parser = function (doc, file) { - assert.equal(typeof doc, 'string') + processor.parser = function (document, file) { + assert.equal(typeof document, 'string') assert.ok(file instanceof VFile) assert.equal(arguments.length, 2) return givenNode @@ -33,8 +33,8 @@ test('`parse`', async function (t) { const processor = unified() // Note: arrow function intended (which doesn’t have a prototype). - processor.parser = (doc, file) => { - assert.equal(typeof doc, 'string') + processor.parser = (document, file) => { + assert.equal(typeof document, 'string') assert.ok(file instanceof VFile) return givenNode } diff --git a/test/process.js b/test/process.js index ebae2b1d..b7eff95a 100644 --- a/test/process.js +++ b/test/process.js @@ -25,8 +25,8 @@ test('`process`', async function (t) { await t.test('should pass/yield expected values', async function () { const processor = unified() - processor.parser = function (doc, file) { - assert.equal(typeof doc, 'string') + processor.parser = function (document, file) { + assert.equal(typeof document, 'string') assert.equal(file, givenFile) assert.equal(arguments.length, 2) return givenNode diff --git a/test/types.d.ts b/test/types.d.ts index 03c3e6fd..449cfff3 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -3,7 +3,7 @@ declare module 'unified' { baz?: 'qux' | undefined foo?: 'bar' | undefined x?: boolean | undefined - fn?: Function | undefined + functionValue?: Function | undefined } interface Settings { diff --git a/test/use.js b/test/use.js index 77e00b54..243d0201 100644 --- a/test/use.js +++ b/test/use.js @@ -1299,8 +1299,8 @@ test('`use`', async function (t) { let calls = 0 unified() - .use(fn, givenOptions, givenOptions, givenOptions, undefined) - .use(fn, otherOptions, otherOptions, undefined, otherOptions) + .use(value, givenOptions, givenOptions, givenOptions, undefined) + .use(value, otherOptions, otherOptions, undefined, otherOptions) .freeze() assert.equal(calls, 1) @@ -1311,7 +1311,7 @@ test('`use`', async function (t) { * @param {unknown} c * @param {unknown} d */ - function fn(a, b, c, d) { + function value(a, b, c, d) { assert.equal(arguments.length, 4) assert.deepEqual(a, mergedOptions) assert.deepEqual(b, otherOptions) @@ -1325,14 +1325,14 @@ test('`use`', async function (t) { await t.test('should keep parameter length (#1)', async function () { let calls = 0 - unified().use(fn).use(fn).freeze() + unified().use(value).use(value).freeze() assert.equal(calls, 1) /** * @param {...unknown} parameters */ - function fn(...parameters) { + function value(...parameters) { assert.deepEqual(parameters, []) calls++ } @@ -1341,14 +1341,14 @@ test('`use`', async function (t) { await t.test('should keep parameter length (#2)', async function () { let calls = 0 - unified().use(fn, givenOptions).use(fn).freeze() + unified().use(value, givenOptions).use(value).freeze() assert.equal(calls, 1) /** * @param {...unknown} parameters */ - function fn(...parameters) { + function value(...parameters) { assert.deepEqual(parameters, [givenOptions]) calls++ } @@ -1357,14 +1357,14 @@ test('`use`', async function (t) { await t.test('should keep parameter length (#3)', async function () { let calls = 0 - unified().use(fn).use(fn, givenOptions).freeze() + unified().use(value).use(value, givenOptions).freeze() assert.equal(calls, 1) /** * @param {...unknown} parameters */ - function fn(...parameters) { + function value(...parameters) { assert.deepEqual(parameters, [givenOptions]) calls++ }