Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Nov 21, 2024
1 parent a41ba34 commit 0335703
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
17 changes: 12 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export default [
]
},
{
"languageOptions": {
"sourceType": "commonjs"
},
"linterOptions": {
"reportUnusedDisableDirectives": true
},
Expand Down Expand Up @@ -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"
}
}
}
];
3 changes: 1 addition & 2 deletions export-markdownlint-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check

import helpers from "markdownlint/helpers";
export default helpers;
export { default } from "markdownlint/helpers";
3 changes: 1 addition & 2 deletions export-markdownlint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-check

import markdownlint from "markdownlint";
export default markdownlint;
export { default } from "markdownlint";
11 changes: 6 additions & 5 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down
6 changes: 3 additions & 3 deletions test/fs-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion test/import-with-type-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 3 additions & 4 deletions test/markdownlint-cli2-test-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand All @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions test/resolve-and-require-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0335703

Please sign in to comment.