Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Nov 24, 2024
1 parent 0a043bb commit 1814962
Show file tree
Hide file tree
Showing 50 changed files with 287 additions and 324 deletions.
2 changes: 1 addition & 1 deletion helpers/helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const micromark = require("./micromark-helpers.cjs");

const { newLineRe, nextLinesRe } = require("./shared.js");
const { newLineRe, nextLinesRe } = require("./shared.cjs");

module.exports.newLineRe = newLineRe;
module.exports.nextLinesRe = nextLinesRe;
Expand Down
2 changes: 1 addition & 1 deletion helpers/micromark-helpers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"use strict";

const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.js");
const { flatTokensSymbol, htmlFlowSymbol } = require("./shared.cjs");

/** @typedef {import("markdownlint-micromark").TokenType} TokenType */

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 23.1)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 22)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 23.1)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (macos-latest, 22)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 23.1)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 20)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.

Check failure on line 7 in helpers/micromark-helpers.cjs

View workflow job for this annotation

GitHub Actions / build (windows-latest, 22)

Cannot find module 'markdownlint-micromark' or its corresponding type declarations.
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} Token */
Expand Down
61 changes: 31 additions & 30 deletions helpers/micromark-parse.cjs → helpers/micromark-parse.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
// @ts-check

"use strict";
import { directive } from "micromark-extension-directive";
import { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
import { gfmFootnote } from "micromark-extension-gfm-footnote";
import { gfmTable } from "micromark-extension-gfm-table";
import { math } from "micromark-extension-math";
import { parse as micromarkParse, postprocess as micromarkPostprocess, preprocess as micromarkPreprocess } from "micromark";
// micromark-core-commonmark is not a dependency because this instance must match what's used by micromark
import { labelEnd } from "micromark-core-commonmark";
import { isHtmlFlowComment } from "./micromark-helpers.cjs";
import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "./shared.cjs";

const micromark = require("markdownlint-micromark");
const { isHtmlFlowComment } = require("./micromark-helpers.cjs");
const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");

/** @typedef {import("markdownlint-micromark").Construct} Construct */
/** @typedef {import("markdownlint-micromark").Event} Event */
/** @typedef {import("markdownlint-micromark").ParseOptions} MicromarkParseOptions */
/** @typedef {import("markdownlint-micromark").State} State */
/** @typedef {import("markdownlint-micromark").Token} Token */
/** @typedef {import("markdownlint-micromark").Tokenizer} Tokenizer */
/** @typedef {import("micromark-util-types").ParseOptions} MicromarkParseOptions */
/** @typedef {import("micromark-util-types").State} State */
/** @typedef {import("micromark-util-types").Token} Token */
/** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
/** @typedef {import("../lib/markdownlint.js").MicromarkToken} MicromarkToken */

// export declare interface TokenTypeMap {
// undefinedReference: 'undefinedReference'
// undefinedReferenceCollapsed: 'undefinedReferenceCollapsed'
// undefinedReferenceFull: 'undefinedReferenceFull'
// undefinedReferenceShortcut: 'undefinedReferenceShortcut'
// }

/**
* Parse options.
*
Expand All @@ -28,27 +38,23 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.js");
* @param {MicromarkParseOptions} [micromarkParseOptions] Options for micromark.
* @returns {Event[]} Micromark events.
*/
function getEvents(
export function getEvents(
markdown,
micromarkParseOptions = {}
) {
// Customize extensions list to add useful extensions
const extensions = [
micromark.directive(),
micromark.gfmAutolinkLiteral(),
micromark.gfmFootnote(),
micromark.gfmTable(),
micromark.math(),
directive(),
gfmAutolinkLiteral(),
gfmFootnote(),
gfmTable(),
math(),
...(micromarkParseOptions.extensions || [])
];

// // Shim labelEnd to identify undefined link labels
/** @type {Event[][]} */
const artificialEventLists = [];
/** @type {Construct} */
const labelEnd =
// @ts-ignore
micromark.labelEnd;
const tokenizeOriginal = labelEnd.tokenize;

/** @type {Tokenizer} */
Expand Down Expand Up @@ -162,9 +168,9 @@ function getEvents(
// Use micromark to parse document into Events
const encoding = undefined;
const eol = true;
const parseContext = micromark.parse({ ...micromarkParseOptions, extensions });
const chunks = micromark.preprocess()(markdown, encoding, eol);
const events = micromark.postprocess(parseContext.document().write(chunks));
const parseContext = micromarkParse({ ...micromarkParseOptions, extensions });
const chunks = micromarkPreprocess()(markdown, encoding, eol);
const events = micromarkPostprocess(parseContext.document().write(chunks));

// Append artificial events and return all events
// eslint-disable-next-line unicorn/prefer-spread
Expand Down Expand Up @@ -303,11 +309,6 @@ function parseInternal(
* @param {ParseOptions} [parseOptions] Options.
* @returns {MicromarkToken[]} Micromark tokens.
*/
function parse(markdown, parseOptions) {
export function parse(markdown, parseOptions) {
return parseInternal(markdown, parseOptions);
}

module.exports = {
getEvents,
parse
};
4 changes: 2 additions & 2 deletions lib/markdownlint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createRequire } from "node:module";
const dynamicRequire = createRequire(import.meta.url);
import path from "node:path";
import { promisify } from "node:util";
import micromark from "../helpers/micromark-parse.cjs";
import { parse as micromarkParse } from "../helpers/micromark-parse.mjs";
import { version } from "./constants.mjs";
import rules from "./rules.mjs";
import helpers from "../helpers/helpers.cjs";
Expand Down Expand Up @@ -492,7 +492,7 @@ function lintContent(
);
const customRulesPresent = (ruleList.length !== rules.length);
// Parse content into parser tokens
const micromarkTokens = micromark.parse(
const micromarkTokens = micromarkParse(
content,
{ "freezeTokens": customRulesPresent }
);
Expand Down
2 changes: 1 addition & 1 deletion lib/md004.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check

import { addErrorDetailIf } from "../helpers";
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getDescendantsByType, getParentOfType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

Expand Down
10 changes: 4 additions & 6 deletions lib/md007.js → lib/md007.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-check

"use strict";

const { addErrorDetailIf } = require("../helpers");
const { getParentOfType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getParentOfType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("markdownlint-micromark").TokenType[] */
Expand All @@ -17,7 +15,7 @@ const unorderedParentTypes =

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD007", "ul-indent" ],
"description": "Unordered list indentation",
"tags": [ "bullet", "ul", "indentation" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md009.js → lib/md009.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check

"use strict";

const { addError } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addError } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD009", "no-trailing-spaces" ],
"description": "Trailing spaces",
"tags": [ "whitespace" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md010.js → lib/md010.mjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// @ts-check

"use strict";

const { addError, hasOverlap } = require("../helpers");
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addError, hasOverlap } from "../helpers/helpers.cjs";
import { getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

const tabRe = /\t+/g;

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD010", "no-hard-tabs" ],
"description": "Hard tabs",
"tags": [ "whitespace", "hard_tab" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md011.js → lib/md011.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// @ts-check

"use strict";

const { addError, hasOverlap } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addError, hasOverlap } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

const reversedLinkRe =
/(^|[^\\])\(([^()]+)\)\[([^\]^][^\]]*)\](?!\()/g;

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD011", "no-reversed-links" ],
"description": "Reversed link syntax",
"tags": [ "links" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md012.js → lib/md012.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check

"use strict";

const { addErrorDetailIf } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD012", "no-multiple-blanks" ],
"description": "Multiple consecutive blank lines",
"tags": [ "whitespace", "blank_lines" ],
Expand Down
12 changes: 5 additions & 7 deletions lib/md013.js → lib/md013.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// @ts-check

"use strict";

const { addErrorDetailIf } = require("../helpers");
const { getReferenceLinkImageData } = require("./cache");
const { addRangeToSet, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorDetailIf } from "../helpers/helpers.cjs";
import { getReferenceLinkImageData } from "./cache.mjs";
import { addRangeToSet, getDescendantsByType } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

const longLineRePrefix = "^.{";
const longLineRePostfixRelaxed = "}.*\\s.*$";
Expand All @@ -14,7 +12,7 @@ const sternModeRe = /^(?:[#>\s]*\s)?\S*$/;

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD013", "line-length" ],
"description": "Line length",
"tags": [ "line_length" ],
Expand Down
8 changes: 3 additions & 5 deletions lib/md014.js → lib/md014.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// @ts-check

"use strict";

const { addErrorContext } = require("../helpers");
const { filterByTypesCached } = require("./cache");
import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

const dollarCommandRe = /^(\s*)(\$\s+)/;

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD014", "commands-show-output" ],
"description": "Dollar signs used before commands without showing output",
"tags": [ "code" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md018.js → lib/md018.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check

"use strict";

const { addErrorContext } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD018", "no-missing-space-atx" ],
"description": "No space after hash on atx style heading",
"tags": [ "headings", "atx", "spaces" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md020.js → lib/md020.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check

"use strict";

const { addErrorContext } = require("../helpers");
const { addRangeToSet } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorContext } from "../helpers/helpers.cjs";
import { addRangeToSet } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD020", "no-missing-space-closed-atx" ],
"description": "No space inside hashes on closed atx style heading",
"tags": [ "headings", "atx_closed", "spaces" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md022.js → lib/md022.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// @ts-check

"use strict";

const { addErrorDetailIf, isBlankLine } = require("../helpers");
const { getBlockQuotePrefixText, getHeadingLevel } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorDetailIf, isBlankLine } from "../helpers/helpers.cjs";
import { getBlockQuotePrefixText, getHeadingLevel } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

const defaultLines = 1;

Expand All @@ -23,7 +21,7 @@ const getLinesFunction = (linesParam) => {

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD022", "blanks-around-headings" ],
"description": "Headings should be surrounded by blank lines",
"tags": [ "headings", "blank_lines" ],
Expand Down
8 changes: 3 additions & 5 deletions lib/md023.js → lib/md023.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// @ts-check

"use strict";

const { addErrorContext } = require("../helpers");
const { filterByTypesCached } = require("./cache");
import { addErrorContext } from "../helpers/helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD023", "heading-start-left" ],
"description": "Headings must start at the beginning of the line",
"tags": [ "headings", "spaces" ],
Expand Down
10 changes: 4 additions & 6 deletions lib/md024.js → lib/md024.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// @ts-check

"use strict";

const { addErrorContext } = require("../helpers");
const { getHeadingLevel, getHeadingText } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
import { addErrorContext } from "../helpers/helpers.cjs";
import { getHeadingLevel, getHeadingText } from "../helpers/micromark-helpers.cjs";
import { filterByTypesCached } from "./cache.mjs";

// eslint-disable-next-line jsdoc/valid-types
/** @type import("./markdownlint").Rule */
module.exports = {
export default {
"names": [ "MD024", "no-duplicate-heading" ],
"description": "Multiple headings with the same content",
"tags": [ "headings" ],
Expand Down
Loading

0 comments on commit 1814962

Please sign in to comment.