Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Dec 11, 2024
1 parent 0225d29 commit f36d456
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 16 deletions.
1 change: 0 additions & 1 deletion markdownlint-cli2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ const lintFiles = (fs, dirInfos, fileContents) => {
"handleRuleFailures": true,
"markdownItPlugins": markdownlintOptions.markdownItPlugins,
"noInlineConfig": Boolean(markdownlintOptions.noInlineConfig),
"resultVersion": 3,
fs
};
// Invoke markdownlint
Expand Down
2 changes: 1 addition & 1 deletion test/config-relative-commonjs/config/any-blockquote.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down
2 changes: 1 addition & 1 deletion test/config-relative-module/config/any-blockquote.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
const rule = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down
2 changes: 1 addition & 1 deletion test/customRules-pre-imported/rules/any-blockquote.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down
2 changes: 1 addition & 1 deletion test/customRules/rules/any-blockquote.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down
26 changes: 21 additions & 5 deletions test/esm-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";

// Shims import.meta.filename on Node 18
/**
* Gets the file name of the current module.
* Shims import.meta.filename for Node 18.
* @param {object} meta ESM import.meta object.
* @returns {string} File name.
*/
// eslint-disable-next-line no-underscore-dangle
export const __filename = (meta) => fileURLToPath(meta.url);

// Shims import.meta.dirname on Node 18
/**
* Gets the directory name of the current module.
* Shims import.meta.dirname for Node 18.
* @param {object} meta ESM import.meta object.
* @returns {string} Directory name.
*/
// eslint-disable-next-line no-underscore-dangle
export const __dirname = (meta) => path.dirname(__filename(meta));

// Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time"
export const importWithTypeJson = async (file) => (
/**
* Imports a file as JSON.
* Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time".
* @param {object} meta ESM import.meta object.
* @param {string} file JSON file to import.
* @returns {Promise<object>} JSON object.
*/
export const importWithTypeJson = async (meta, file) => (
// @ts-ignore
JSON.parse(await fs.readFile(path.resolve(__dirname(import.meta), file)))
JSON.parse(await fs.readFile(path.resolve(__dirname(meta), file)))
);
2 changes: 1 addition & 1 deletion test/markdownlint-cli2-test-exports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import test from "ava";
import { importWithTypeJson } from "./esm-helpers.mjs";
const packageJson = await importWithTypeJson("../package.json");
const packageJson = await importWithTypeJson(import.meta, "../package.json");

const exportMappings = new Map([
[ ".", "../markdownlint-cli2.mjs" ],
Expand Down
6 changes: 3 additions & 3 deletions test/markdownlint-cli2-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Ajv from "ajv";
import test from "ava";
import { globby } from "globby";
import { __dirname, importWithTypeJson } from "./esm-helpers.mjs";
const packageJson = await importWithTypeJson("../package.json");
const packageJson = await importWithTypeJson(import.meta, "../package.json");
import { "main" as markdownlintCli2 } from "../markdownlint-cli2.mjs";
import jsoncParse from "../parsers/jsonc-parse.mjs";
import yamlParse from "../parsers/yaml-parse.mjs";
Expand All @@ -16,8 +16,8 @@ import FsVirtual from "../webworker/fs-virtual.cjs";
import firstLine from "./customRules/rules/first-line.cjs";

const schemaIdVersionRe = /^.*v(?<version>\d+\.\d+\.\d+).*$/u;
const markdownlintConfigSchemaDefinition = await importWithTypeJson("../schema/markdownlint-config-schema.json");
const markdownlintCli2ConfigSchemaDefinition = await importWithTypeJson("../schema/markdownlint-cli2-config-schema.json");
const markdownlintConfigSchemaDefinition = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
const markdownlintCli2ConfigSchemaDefinition = await importWithTypeJson(import.meta, "../schema/markdownlint-cli2-config-schema.json");

const outputFormatterLengthIs = (t, length) => (options) => {
const { results } = options;
Expand Down
2 changes: 1 addition & 1 deletion test/tilde-paths-commonjs/scripts/any-blockquote.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down
2 changes: 1 addition & 1 deletion test/tilde-paths-module/scripts/any-blockquote.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

/** @type import("markdownlint").Rule */
/** @type {import("markdownlint").Rule} */
const rule = {
"names": [ "any-blockquote" ],
"description": "Rule that reports an error for any blockquote",
Expand Down

0 comments on commit f36d456

Please sign in to comment.