diff --git a/eslint.config.mjs b/eslint.config.mjs index 4255d5f..1389b9e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -26,9 +26,6 @@ export default [ ] }, { - "languageOptions": { - "sourceType": "commonjs" - }, "linterOptions": { "reportUnusedDisableDirectives": true }, @@ -68,10 +65,20 @@ export default [ }, { "files": [ - "**/*.mjs" + "**/*-formatter-*.js", + "webworker/*.js" + ], + "ignores": [ + "webworker/fs-virtual.js" ], "languageOptions": { - "sourceType": "module" + "sourceType": "commonjs", + "globals": { + "__dirname": "readonly", + "__filename": "readonly", + "module": "readonly", + "require": "readonly" + } } } ]; diff --git a/export-markdownlint-helpers.js b/export-markdownlint-helpers.js index 90d31e2..6598099 100644 --- a/export-markdownlint-helpers.js +++ b/export-markdownlint-helpers.js @@ -1,4 +1,3 @@ // @ts-check -import helpers from "markdownlint/helpers"; -export default helpers; +export { default } from "markdownlint/helpers"; diff --git a/export-markdownlint.js b/export-markdownlint.js index a1e0f6b..d14558b 100644 --- a/export-markdownlint.js +++ b/export-markdownlint.js @@ -1,4 +1,3 @@ // @ts-check -import markdownlint from "markdownlint"; -export default markdownlint; +export { default } from "markdownlint"; diff --git a/markdownlint-cli2.js b/markdownlint-cli2.js index 19e57d4..a4b7ba7 100755 --- a/markdownlint-cli2.js +++ b/markdownlint-cli2.js @@ -4,7 +4,7 @@ // Requires import fsx from "node:fs"; -import { createRequire } from 'node:module'; +import { createRequire } from "node:module"; const dynamicRequire = createRequire(import.meta.url); import os from "node:os"; import pathDefault from "node:path"; @@ -211,12 +211,12 @@ const readOptionsOrConfig = async (configPath, fs, noRequire) => { }; // Filter a list of files to ignore by glob -const removeIgnoredFiles = (dir, files, ignores) => { - return micromatch( +const removeIgnoredFiles = (dir, files, ignores) => ( + micromatch( files.map((file) => pathPosix.relative(dir, file)), ignores - ).map((file) => pathPosix.join(dir, file)); -}; + ).map((file) => pathPosix.join(dir, file)) +); // Process/normalize command-line arguments and return glob patterns const processArgv = (argv) => { @@ -886,6 +886,7 @@ const outputSummary = async ( const dirs = [ dir, ...modulePaths ]; const formattersAndParams = outputFormatters ? await importOrRequireIdsAndParams(dirs, outputFormatters, noRequire) + // eslint-disable-next-line unicorn/no-await-expression-member : [ [ (await import("markdownlint-cli2-formatter-default")).default ] ]; await Promise.all(formattersAndParams.map((formatterAndParams) => { const [ formatter, ...formatterParams ] = formatterAndParams; diff --git a/package.json b/package.json index 2834a7d..a3347ba 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "eslint-plugin-jsdoc": "50.5.0", "eslint-plugin-n": "17.13.2", "eslint-plugin-unicorn": "56.0.0", - "nano-spawn": "0.2.0", "markdown-it-emoji": "3.0.0", "markdown-it-for-inline": "2.0.1", "markdownlint-cli2-formatter-codequality": "0.0.5", @@ -106,6 +105,7 @@ "markdownlint-cli2-formatter-summarize": "0.0.7", "markdownlint-cli2-formatter-template": "0.0.2", "markdownlint-rule-extended-ascii": "0.1.0", + "nano-spawn": "0.2.0", "npm-run-all": "4.1.5" }, "keywords": [ diff --git a/test/fs-mock.js b/test/fs-mock.js index 7f9a0e5..655b5d8 100644 --- a/test/fs-mock.js +++ b/test/fs-mock.js @@ -3,9 +3,9 @@ import fs from "node:fs"; import nodePath from "node:path"; -const mapPath = (base, mockPath) => { - return nodePath.resolve(base, nodePath.relative("/mock", mockPath)); -}; +const mapPath = (base, mockPath) => ( + nodePath.resolve(base, nodePath.relative("/mock", mockPath)) +); class fsMock { constructor(base, symbolicLinks) { diff --git a/test/import-with-type-json.mjs b/test/import-with-type-json.mjs index 7b2cc92..60521e2 100644 --- a/test/import-with-type-json.mjs +++ b/test/import-with-type-json.mjs @@ -4,4 +4,9 @@ import fs from "node:fs/promises"; import path from "node:path"; // Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time" -export default async (file) => JSON.parse(await fs.readFile(path.resolve(import.meta.dirname, file), "utf8")); +const importWithTypeJson = async (file) => ( + // @ts-ignore + JSON.parse(await fs.readFile(path.resolve(import.meta.dirname, file))) +); + +export default importWithTypeJson; diff --git a/test/markdownlint-cli2-test-exports.js b/test/markdownlint-cli2-test-exports.js index 84f948f..74b7bbd 100644 --- a/test/markdownlint-cli2-test-exports.js +++ b/test/markdownlint-cli2-test-exports.js @@ -4,9 +4,6 @@ import test from "ava"; import importWithTypeJson from "./import-with-type-json.mjs"; const packageJson = await importWithTypeJson("../package.json"); -import { createRequire } from "node:module"; -const require = createRequire(import.meta.url); - const exportMappings = new Map([ [ ".", "../markdownlint-cli2.js" ], [ "./markdownlint", "markdownlint" ], @@ -23,9 +20,11 @@ test("exportMappings", (t) => { ); }); +const commonJsRe = /.js$/u; + for (const [ exportName, exportPath ] of exportMappings) { test(exportName, async (t) => { - const commonJs = !/.js$/.test(exportPath); + const commonJs = !commonJsRe.test(exportPath); const importExportName = await import(exportName.replace(/^\./u, packageJson.name)); const importExportPath = await import(exportPath); t.is( diff --git a/test/resolve-and-require-test.js b/test/resolve-and-require-test.js index b5f0bea..93f5019 100644 --- a/test/resolve-and-require-test.js +++ b/test/resolve-and-require-test.js @@ -7,8 +7,6 @@ import resolveAndRequire from "../resolve-and-require.js"; import { createRequire } from "node:module"; const require = createRequire(import.meta.url); -/* eslint-disable n/no-missing-require */ - test("built-in module", (t) => { t.plan(1); t.deepEqual(