From 3d504623341ccd9cea19bc2a14c0cf2b28254088 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 21 Jul 2021 09:50:34 +0200 Subject: [PATCH] Update `xo` --- package.json | 2 +- test/async-function.js | 30 ++-- test/freeze.js | 2 +- test/process.js | 28 +-- test/run.js | 378 ++++++++++++++++++++++------------------- test/use.js | 15 +- 6 files changed, 243 insertions(+), 212 deletions(-) diff --git a/package.json b/package.json index 8f41ac14..b2d1bdb3 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "tsd": "^0.17.0", "type-coverage": "^2.0.0", "typescript": "^4.0.0", - "xo": "^0.39.0" + "xo": "^0.42.0" }, "scripts": { "build": "rimraf \"test/**/*.d.ts\" && tsc && tsd && type-coverage", diff --git a/test/async-function.js b/test/async-function.js index fc52bcf0..cc6d2060 100644 --- a/test/async-function.js +++ b/test/async-function.js @@ -10,21 +10,21 @@ test('async function transformer () {}', (t) => { t.plan(5) unified() - .use(() => { - return async function () {} - }) - .use(() => { - return async function () { - return undefined - } - }) - .use(() => { - return async function (tree, file) { - t.equal(tree, givenNode, 'passes correct tree to an async function') - t.equal(file, givenFile, 'passes correct file to an async function') - return modifiedNode - } - }) + .use(() => async function () {}) + .use( + () => + async function () { + return undefined + } + ) + .use( + () => + async function (tree, file) { + t.equal(tree, givenNode, 'passes correct tree to an async function') + t.equal(file, givenFile, 'passes correct file to an async function') + return modifiedNode + } + ) .run(givenNode, givenFile, (error, tree, file) => { t.error(error, 'should’t fail') t.equal(tree, modifiedNode, 'passes given tree to `done`') diff --git a/test/freeze.js b/test/freeze.js index e3269fa5..afcb4bf3 100644 --- a/test/freeze.js +++ b/test/freeze.js @@ -3,8 +3,8 @@ */ import test from 'tape' -import {SimpleCompiler, SimpleParser} from './util/simple.js' import {unified} from '../index.js' +import {SimpleCompiler, SimpleParser} from './util/simple.js' test('freeze()', (t) => { const frozen = unified() diff --git a/test/process.js b/test/process.js index 7416af69..79dd1a55 100644 --- a/test/process.js +++ b/test/process.js @@ -7,8 +7,8 @@ import test from 'tape' import {VFile} from 'vfile' -import {SimpleCompiler, SimpleParser} from './util/simple.js' import {unified} from '../index.js' +import {SimpleCompiler, SimpleParser} from './util/simple.js' test('process(file, done)', (t) => { const givenFile = new VFile('alpha') @@ -45,12 +45,13 @@ test('process(file, done)', (t) => { } }) }) - .use(() => { - return function (tree, file) { - t.equal(tree, givenNode, 'should pass `tree` to transformers') - t.equal(file, givenFile, 'should pass `file` to transformers') - } - }) + .use( + () => + function (tree, file) { + t.equal(tree, givenNode, 'should pass `tree` to transformers') + t.equal(file, givenFile, 'should pass `file` to transformers') + } + ) .use(function () { Object.assign(this, { /** @type {Compiler} */ @@ -99,12 +100,13 @@ test('process(file)', (t) => { } }) }) - .use(() => { - return function (tree, file) { - t.equal(tree, givenNode, 'should pass `tree` to transformers') - t.equal(file, givenFile, 'should pass `file` to transformers') - } - }) + .use( + () => + function (tree, file) { + t.equal(tree, givenNode, 'should pass `tree` to transformers') + t.equal(file, givenFile, 'should pass `file` to transformers') + } + ) .use(function () { Object.assign(this, { /** @type {Compiler} */ diff --git a/test/run.js b/test/run.js index ab3ac95c..7ca0e300 100644 --- a/test/run.js +++ b/test/run.js @@ -26,11 +26,12 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function () { - return new Error('charlie') - } - }) + .use( + () => + function () { + return new Error('charlie') + } + ) .run(givenNode, (error) => { t.equal( String(error), @@ -52,11 +53,12 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - next(new Error('delta')) - } - }) + .use( + () => + function (_, _1, next) { + next(new Error('delta')) + } + ) .run(givenNode, (error) => { t.equal( String(error), @@ -66,12 +68,13 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - next() - next(new Error('delta')) - } - }) + .use( + () => + function (_, _1, next) { + next() + next(new Error('delta')) + } + ) .run(givenNode, (error) => { t.error( error, @@ -80,11 +83,12 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - next(null, otherNode) - } - }) + .use( + () => + function (_, _1, next) { + next(null, otherNode) + } + ) .run(givenNode, (error, tree) => { t.error(error, 'should’t fail') @@ -96,13 +100,14 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function () { - return new Promise((_, reject) => { - reject(new Error('delta')) - }) - } - }) + .use( + () => + function () { + return new Promise((_, reject) => { + reject(new Error('delta')) + }) + } + ) .run(givenNode, (error) => { t.equal( String(error), @@ -112,13 +117,14 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function () { - return new Promise((resolve) => { - resolve(otherNode) - }) - } - }) + .use( + () => + function () { + return new Promise((resolve) => { + resolve(otherNode) + }) + } + ) .run(givenNode, (error, tree) => { t.error(error, 'should’t fail') @@ -130,14 +136,15 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(tick) - function tick() { - next(null, otherNode) + .use( + () => + function (_, _1, next) { + setImmediate(tick) + function tick() { + next(null, otherNode) + } } - } - }) + ) .run(givenNode, (error, tree) => { t.error(error, 'should’t fail') @@ -149,14 +156,15 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(tick) - function tick() { - next(new Error('echo')) + .use( + () => + function (_, _1, next) { + setImmediate(tick) + function tick() { + next(new Error('echo')) + } } - } - }) + ) .run(givenNode, (error) => { t.equal( String(error), @@ -166,15 +174,16 @@ test('run(node[, file], done)', (t) => { }) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(tick) - function tick() { - next() - next(new Error('echo')) + .use( + () => + function (_, _1, next) { + setImmediate(tick) + function tick() { + next() + next(new Error('echo')) + } } - } - }) + ) .run(givenNode, (error) => { t.error( error, @@ -224,11 +233,12 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function () { - return new Error('charlie') - } - }) + .use( + () => + function () { + return new Error('charlie') + } + ) .run(givenNode) .then( () => { @@ -246,11 +256,12 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function () { - return otherNode - } - }) + .use( + () => + function () { + return otherNode + } + ) .run(givenNode) .then( (tree) => { @@ -268,11 +279,12 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - next(new Error('delta')) - } - }) + .use( + () => + function (_, _1, next) { + next(new Error('delta')) + } + ) .run(givenNode) .then( () => { @@ -290,12 +302,13 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - next() - next(new Error('delta')) - } - }) + .use( + () => + function (_, _1, next) { + next() + next(new Error('delta')) + } + ) .run(givenNode) .then( () => { @@ -311,11 +324,12 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - next(null, otherNode) - } - }) + .use( + () => + function (_, _1, next) { + next(null, otherNode) + } + ) .run(givenNode) .then( (tree) => { @@ -333,13 +347,14 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function () { - return new Promise((_, reject) => { - reject(new Error('delta')) - }) - } - }) + .use( + () => + function () { + return new Promise((_, reject) => { + reject(new Error('delta')) + }) + } + ) .run(givenNode) .then( () => { @@ -355,13 +370,14 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function () { - return new Promise((resolve) => { - resolve(otherNode) - }) - } - }) + .use( + () => + function () { + return new Promise((resolve) => { + resolve(otherNode) + }) + } + ) .run(givenNode) .then( () => { @@ -377,13 +393,14 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(() => { - next(null, otherNode) - }) - } - }) + .use( + () => + function (_, _1, next) { + setImmediate(() => { + next(null, otherNode) + }) + } + ) .run(givenNode) .then( () => { @@ -399,13 +416,14 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(() => { - next(new Error('echo')) - }) - } - }) + .use( + () => + function (_, _1, next) { + setImmediate(() => { + next(new Error('echo')) + }) + } + ) .run(givenNode) .then( () => { @@ -421,14 +439,15 @@ test('run(node[, file])', (t) => { ) unified() - .use(() => { - return function (_, _1, next) { - setImmediate(() => { - next() - next(new Error('echo')) - }) - } - }) + .use( + () => + function (_, _1, next) { + setImmediate(() => { + next() + next(new Error('echo')) + }) + } + ) .run(givenNode) .then( () => { @@ -461,34 +480,37 @@ test('runSync(node[, file])', (t) => { ) unified() - .use(() => { - return function (tree, file) { - t.equal(tree, givenNode, 'passes given tree to transformers') - t.equal(file, givenFile, 'passes given file to transformers') - } - }) + .use( + () => + function (tree, file) { + t.equal(tree, givenNode, 'passes given tree to transformers') + t.equal(file, givenFile, 'passes given file to transformers') + } + ) .runSync(givenNode, givenFile) unified() - .use(() => { - return function (_, file) { - t.equal( - file.toString(), - '', - 'passes files to transformers if not given' - ) - } - }) + .use( + () => + function (_, file) { + t.equal( + file.toString(), + '', + 'passes files to transformers if not given' + ) + } + ) .runSync(givenNode) t.throws( () => { unified() - .use(() => { - return function () { - return new Error('charlie') - } - }) + .use( + () => + function () { + return new Error('charlie') + } + ) .runSync(givenNode) }, /charlie/, @@ -497,11 +519,12 @@ test('runSync(node[, file])', (t) => { t.equal( unified() - .use(() => { - return function () { - return otherNode - } - }) + .use( + () => + function () { + return otherNode + } + ) .runSync(givenNode), otherNode, 'should return a new tree when returned from a sync transformer' @@ -510,11 +533,12 @@ test('runSync(node[, file])', (t) => { t.throws( () => { unified() - .use(() => { - return function (_, _1, next) { - next(new Error('delta')) - } - }) + .use( + () => + function (_, _1, next) { + next(new Error('delta')) + } + ) .runSync(givenNode) }, /delta/, @@ -523,11 +547,12 @@ test('runSync(node[, file])', (t) => { t.equal( unified() - .use(() => { - return function (_, _1, next) { - next(null, otherNode) - } - }) + .use( + () => + function (_, _1, next) { + next(null, otherNode) + } + ) .runSync(givenNode), otherNode, 'should return a new tree if given to a sync transformer’s `next`' @@ -536,13 +561,14 @@ test('runSync(node[, file])', (t) => { t.throws( () => { unified() - .use(() => { - return function () { - return new Promise((_, reject) => { - reject(new Error('delta')) - }) - } - }) + .use( + () => + function () { + return new Promise((_, reject) => { + reject(new Error('delta')) + }) + } + ) .runSync(givenNode) }, /`runSync` finished async. Use `run` instead/, @@ -552,13 +578,14 @@ test('runSync(node[, file])', (t) => { t.throws( () => { unified() - .use(() => { - return function () { - return new Promise((resolve) => { - resolve(otherNode) - }) - } - }) + .use( + () => + function () { + return new Promise((resolve) => { + resolve(otherNode) + }) + } + ) .runSync(givenNode) }, /`runSync` finished async. Use `run` instead/, @@ -574,13 +601,14 @@ test('runSync(node[, file])', (t) => { t.throws( () => { unified() - .use(() => { - return function (_, _1, next) { - setImmediate(() => { - next(null, otherNode) - }) - } - }) + .use( + () => + function (_, _1, next) { + setImmediate(() => { + next(null, otherNode) + }) + } + ) .runSync(givenNode) }, /`runSync` finished async. Use `run` instead/, diff --git a/test/use.js b/test/use.js index a0861317..43911c02 100644 --- a/test/use.js +++ b/test/use.js @@ -266,14 +266,15 @@ test('use(plugin[, options])', (t) => { t.plan(3) processor - .use(() => { - return function (node, file) { - t.equal(node, givenNode, 'should attach a transformer (#1)') - t.ok('message' in file, 'should attach a transformer (#2)') + .use( + () => + function (node, file) { + t.equal(node, givenNode, 'should attach a transformer (#1)') + t.ok('message' in file, 'should attach a transformer (#2)') - throw new Error('Alpha bravo charlie') - } - }) + throw new Error('Alpha bravo charlie') + } + ) .freeze() t.throws(