From 96e8c4f543a0b13d14470819b2a7278d11b4afe3 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 29 Nov 2021 19:36:39 +0100 Subject: [PATCH] Update dev-dependencies --- package.json | 4 +- packages/unified-lint-rule/index.d.ts | 2 +- script/util/presets.js | 7 +- test.js | 120 +++++++++++++------------- 4 files changed, 69 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 62f0e7a3..9939a453 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "typescript": "~4.4.0", "unist-builder": "^3.0.0", "unist-util-remove-position": "^4.0.0", - "xo": "^0.46.0" + "xo": "^0.47.0" }, "scripts": { "build-packages": "node script/build-presets && node script/build-rules", @@ -158,6 +158,8 @@ "xo": { "prettier": true, "rules": { + "capitalized-comments": "off", + "unicorn/prefer-code-point": "off", "unicorn/prefer-switch": "off" }, "overrides": [ diff --git a/packages/unified-lint-rule/index.d.ts b/packages/unified-lint-rule/index.d.ts index 35ddebbf..543953bb 100644 --- a/packages/unified-lint-rule/index.d.ts +++ b/packages/unified-lint-rule/index.d.ts @@ -31,4 +31,4 @@ export type Rule = ( settings: Settings ) => Promise | Tree | undefined | void -export type {Severity, Label} +export {Severity, Label} from './lib/index.js' diff --git a/script/util/presets.js b/script/util/presets.js index 8d71be62..64795492 100644 --- a/script/util/presets.js +++ b/script/util/presets.js @@ -12,16 +12,19 @@ import url from 'node:url' * @returns {Promise}>>} */ export async function presets(base) { - const files = (await fs.readdir(base)).filter((basename) => + const allFiles = await fs.readdir(base) + const files = allFiles.filter((basename) => /remark-preset-lint/.test(basename) ) return Promise.all( files.map(async (name) => { const href = url.pathToFileURL(path.join(base, name, 'index.js')).href + // type-coverage:ignore-next-line + const presetMod = await import(href) /** @type {Preset} */ // type-coverage:ignore-next-line - const preset = (await import(href)).default + const preset = presetMod.default const plugins = preset.plugins || [] /** @type {Record} */ const packages = {} diff --git a/test.js b/test.js index 2828eba5..bfb3622d 100644 --- a/test.js +++ b/test.js @@ -36,16 +36,14 @@ test('core', async (t) => { '# Another main heading.' ].join('\n') + let file = await remark() + .use(noHeadingPunctuation) + .use(noMultipleToplevelHeadings) + .use(lint) + .process(toVFile({path: 'virtual.md', value: doc})) + t.deepEqual( - asStrings( - ( - await remark() - .use(noHeadingPunctuation) - .use(noMultipleToplevelHeadings) - .use(lint) - .process(toVFile({path: 'virtual.md', value: doc})) - ).messages - ), + asStrings(file.messages), [ 'virtual.md:3:1-3:24: Don’t add a trailing `.` to headings', 'virtual.md:3:1-3:24: Don’t use multiple top level headings (1:1)' @@ -53,16 +51,14 @@ test('core', async (t) => { 'should support `remark-lint` last' ) + file = await remark() + .use(lint) + .use(noHeadingPunctuation) + .use(noMultipleToplevelHeadings) + .process(toVFile({path: 'virtual.md', value: doc})) + t.deepEqual( - asStrings( - ( - await remark() - .use(lint) - .use(noHeadingPunctuation) - .use(noMultipleToplevelHeadings) - .process(toVFile({path: 'virtual.md', value: doc})) - ).messages - ), + asStrings(file.messages), [ 'virtual.md:3:1-3:24: Don’t add a trailing `.` to headings', 'virtual.md:3:1-3:24: Don’t use multiple top level headings (1:1)' @@ -70,22 +66,18 @@ test('core', async (t) => { 'should support `remark-lint` first' ) - t.deepEqual( - asStrings((await remark().use(lint).process('.')).messages), - [], - 'should support no rules' - ) + file = await remark().use(lint).process('.') - t.deepEqual( - asStrings((await remark().use(finalNewline).process('')).messages), - [], - 'should support successful rules' - ) + t.deepEqual(asStrings(file.messages), [], 'should support no rules') + + file = await remark().use(finalNewline).process('') + + t.deepEqual(asStrings(file.messages), [], 'should support successful rules') + + file = await remark().use(finalNewline, [2]).process('.') t.deepEqual( - (await remark().use(finalNewline, [2]).process('.')).messages.map((d) => - JSON.parse(JSON.stringify(d)) - ), + file.messages.map((d) => JSON.parse(JSON.stringify(d))), [ { name: '1:1', @@ -106,36 +98,42 @@ test('core', async (t) => { 'should support a list with a severity' ) + file = await remark().use(finalNewline, true).process('.') + t.deepEqual( - asStrings((await remark().use(finalNewline, true).process('.')).messages), + asStrings(file.messages), ['1:1: Missing newline character at end of file'], 'should support a boolean (`true`)' ) + file = await remark().use(finalNewline, false).process('.') + t.deepEqual( - asStrings((await remark().use(finalNewline, false).process('.')).messages), + asStrings(file.messages), [], 'should support a boolean (`false`)' ) + file = await remark().use(finalNewline, [true]).process('.') + t.deepEqual( - asStrings((await remark().use(finalNewline, [true]).process('.')).messages), + asStrings(file.messages), ['1:1: Missing newline character at end of file'], 'should support a list with a boolean severity (true, for on)' ) + file = await remark().use(finalNewline, [false]).process('.') + t.deepEqual( - asStrings( - (await remark().use(finalNewline, [false]).process('.')).messages - ), + asStrings(file.messages), [], 'should support a list with boolean severity (false, for off)' ) + file = await remark().use(finalNewline, ['error']).process('.') + t.deepEqual( - (await remark().use(finalNewline, ['error']).process('.')).messages.map( - (d) => JSON.parse(JSON.stringify(d)) - ), + file.messages.map((d) => JSON.parse(JSON.stringify(d))), [ { name: '1:1', @@ -156,10 +154,10 @@ test('core', async (t) => { 'should support a list with string severity (`error`)' ) + file = await remark().use(finalNewline, ['on']).process('.') + t.deepEqual( - (await remark().use(finalNewline, ['on']).process('.')).messages.map((d) => - JSON.parse(JSON.stringify(d)) - ), + file.messages.map((d) => JSON.parse(JSON.stringify(d))), [ { name: '1:1', @@ -180,10 +178,10 @@ test('core', async (t) => { 'should support a list with string severity (`on`)' ) + file = await remark().use(finalNewline, ['warn']).process('.') + t.deepEqual( - (await remark().use(finalNewline, ['warn']).process('.')).messages.map( - (d) => JSON.parse(JSON.stringify(d)) - ), + file.messages.map((d) => JSON.parse(JSON.stringify(d))), [ { name: '1:1', @@ -204,10 +202,10 @@ test('core', async (t) => { 'should support a list with string severity (`warn`)' ) + file = await remark().use(finalNewline, ['off']).process('.') + t.deepEqual( - asStrings( - (await remark().use(finalNewline, ['off']).process('.')).messages - ), + asStrings(file.messages), [], 'should support a list with string severity (`off`)' ) @@ -228,17 +226,17 @@ test('core', async (t) => { 'should fail on incorrect severities (too low)' ) + file = await remark() + .use( + lintRule('test:rule', (tree, file) => { + file.message('Test message') + }), + ['warn'] + ) + .process('.') + t.deepEqual( - ( - await remark() - .use( - lintRule('test:rule', (tree, file) => { - file.message('Test message') - }), - ['warn'] - ) - .process('.') - ).messages.map((d) => JSON.parse(JSON.stringify(d))), + file.messages.map((d) => JSON.parse(JSON.stringify(d))), [ { name: '1:1', @@ -270,9 +268,11 @@ test('rules', async (t) => { const info = rule(base) const href = url.pathToFileURL(base).href + '/index.js' + // type-coverage:ignore-next-line + const pluginMod = await import(href) /** @type {Plugin} */ // type-coverage:ignore-next-line - const fn = (await import(href)).default + const fn = pluginMod.default if (Object.keys(info.tests).length === 0) { t.pass(info.ruleId + ': no tests')