Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ jobs:

test_types:
name: Test Types
strategy:
matrix:
eslint: [9.39.0, 9.x, 10.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Expand All @@ -85,6 +88,8 @@ jobs:
node-version: "lts/*"
- name: Install dependencies
run: npm install
- name: Install ESLint@${{ matrix.eslint }}
run: npm install -D eslint@${{ matrix.eslint }} @eslint/js@${{ matrix.eslint }}
- name: Check Types
run: npm run test:types
- name: Check Types (TypeScript 5.3)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Lint Markdown with ESLint, as well JS, JSX, TypeScript, and more inside Markdown

### Installing

Install the plugin alongside ESLint v9.15.0 or greater.
Install the plugin alongside ESLint v9.15.0 or greater. Type compatibility is guaranteed with ESLint v9.39.0 or greater.

For Node.js and compatible runtimes:

Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import rules from "./build/rules.js";
//-----------------------------------------------------------------------------

/**
* @import { Linter } from "eslint";
* @import { ConfigObject, RulesConfig } from "@eslint/core";
*/

//-----------------------------------------------------------------------------
// Exports
//-----------------------------------------------------------------------------

/** @satisfies {Linter.RulesRecord} */
/** @satisfies {RulesConfig} */
const processorRulesConfig = {
// The Markdown parser automatically trims trailing
// newlines from code blocks.
Expand Down Expand Up @@ -97,7 +97,7 @@ const plugin = {
rules: recommendedRules,
},
],
processor: /** @type {Linter.Config[]} */ ([
processor: /** @type {ConfigObject[]} */ ([
{
name: "markdown/recommended/plugin",
plugins: (processorPlugins = {}),
Expand Down
25 changes: 11 additions & 14 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ import { fromMarkdown } from "mdast-util-from-markdown";
//-----------------------------------------------------------------------------

/**
* @import { LintMessage, RuleTextEdit, SourceRange } from "@eslint/core";
* @import { Node, Parent, Code, Html } from "mdast";
* @import { Linter, Rule, AST } from "eslint";
* @import { Block, RangeMap } from "./types.js";
* @typedef {Linter.LintMessage} Message
* @typedef {Rule.Fix} Fix
* @typedef {AST.Range} Range
*/

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -356,12 +353,12 @@ function preprocess(sourceText, filename) {
/**
* Adjusts a fix in a code block.
* @param {Block} block A code block.
* @param {Fix} fix A fix to adjust.
* @returns {Fix} The fix with adjusted ranges.
* @param {RuleTextEdit} fix A fix to adjust.
* @returns {RuleTextEdit} The fix with adjusted ranges.
*/
function adjustFix(block, fix) {
return {
range: /** @type {Range} */ (
range: /** @type {SourceRange} */ (
fix.range.map(range => {
// Advance through the block's range map to find the last
// matching range by finding the first range too far and
Expand All @@ -386,7 +383,7 @@ function adjustFix(block, fix) {
/**
* Creates a map function that adjusts messages in a code block.
* @param {Block} block A code block.
* @returns {(message: Message) => Message} A function that adjusts messages in a code block.
* @returns {(message: LintMessage) => LintMessage | null} A function that adjusts messages in a code block.
*/
Comment thread
lumirlumir marked this conversation as resolved.
function adjustBlock(block) {
const leadingCommentLines = block.comments.reduce(
Expand All @@ -398,8 +395,8 @@ function adjustBlock(block) {

/**
* Adjusts ESLint messages to point to the correct location in the Markdown.
* @param {Message} message A message from ESLint.
* @returns {Message} The same message, but adjusted to the correct location.
* @param {LintMessage} message A message from ESLint.
* @returns {LintMessage} The same message, but adjusted to the correct location.
*/
return function adjustMessage(message) {
if (!Number.isInteger(message.line)) {
Expand All @@ -416,7 +413,7 @@ function adjustBlock(block) {
return null;
}

/** @type {Pick<Message, "line" | "column" | "endLine" | "suggestions">} */
/** @type {Pick<LintMessage, "line" | "column" | "endLine" | "suggestions">} */
const out = {
line: lineInCode + blockStart,
column: message.column + block.rangeMap[lineInCode].indent,
Expand Down Expand Up @@ -445,7 +442,7 @@ function adjustBlock(block) {

/**
* Excludes unsatisfiable rules from the list of messages.
* @param {Message} message A message from the linter.
* @param {LintMessage} message A message from the linter.
* @returns {boolean} True if the message should be included in output.
*/
function excludeUnsatisfiableRules(message) {
Expand All @@ -454,10 +451,10 @@ function excludeUnsatisfiableRules(message) {

/**
* Transforms generated messages for output.
* @param {Array<Message[]>} messages An array containing one array of messages
* @param {Array<LintMessage[]>} messages An array containing one array of messages
* for each code block returned from `preprocess`.
* @param {string} filename The filename of the file
* @returns {Message[]} A flattened array of messages with mapped locations.
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
*/
function postprocess(messages, filename) {
const blocks = blocksCache.get(filename);
Expand Down
5 changes: 2 additions & 3 deletions src/rules/fenced-code-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const fencedCodeCharacters = new Set(["`", "~"]);
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {FencedCodeLanguageRuleDefinition} */
export default {
export default /** @satisfies {FencedCodeLanguageRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -135,4 +134,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/fenced-code-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {FencedCodeMetaRuleDefinition} */
export default {
export default /** @satisfies {FencedCodeMetaRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -99,4 +98,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/heading-increment.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { frontmatterHasTitle } from "../util.js";
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {HeadingIncrementRuleDefinition} */
export default {
export default /** @satisfies {HeadingIncrementRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -101,4 +100,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-bare-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ function parseHtmlTag(tagText) {
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoBareUrlsRuleDefinition} */
export default {
export default /** @satisfies {NoBareUrlsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -177,4 +176,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-duplicate-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { normalizeIdentifier } from "micromark-util-normalize-identifier";
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoDuplicateDefinitionsRuleDefinition} */
export default {
export default /** @satisfies {NoDuplicateDefinitionsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -151,4 +150,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-duplicate-headings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoDuplicateHeadingsRuleDefinition} */
export default {
export default /** @satisfies {NoDuplicateHeadingsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -118,4 +117,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-empty-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ function isOnlyComments(value) {
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoEmptyDefinitionsRuleDefinition} */
export default {
export default /** @satisfies {NoEmptyDefinitionsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -146,4 +145,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-empty-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoEmptyImagesRuleDefinition} */
export default {
export default /** @satisfies {NoEmptyImagesRuleDefinition} */ ({
meta: {
type: "problem",

Expand All @@ -46,4 +45,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-empty-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoEmptyLinksRuleDefinition} */
export default {
export default /** @satisfies {NoEmptyLinksRuleDefinition} */ ({
meta: {
type: "problem",

Expand All @@ -45,4 +44,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const htmlTagPattern =
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoHtmlRuleDefinition} */
export default {
export default /** @satisfies {NoHtmlRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -124,4 +123,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-invalid-label-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ function findInvalidLabelReferences(node, sourceCode) {
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoInvalidLabelRefsRuleDefinition} */
export default {
export default /** @satisfies {NoInvalidLabelRefsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -144,4 +143,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-missing-atx-heading-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const trailingAtxHeadingHashPattern =
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoMissingAtxHeadingSpaceRuleDefinition} */
export default {
export default /** @satisfies {NoMissingAtxHeadingSpaceRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -135,4 +134,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-missing-label-refs.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ function findMissingReferences(node, sourceCode) {
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoMissingLabelRefsRuleDefinition} */
export default {
export default /** @satisfies {NoMissingLabelRefsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -179,4 +178,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-missing-link-fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ const htmlTagPattern =
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoMissingLinkFragmentsRuleDefinition} */
export default {
export default /** @satisfies {NoMissingLinkFragmentsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -182,4 +181,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-multiple-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const h1TagPattern = /<h1[^>]*>[\s\S]*?<\/h1\s*>/giu;
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoMultipleH1RuleDefinition} */
export default {
export default /** @satisfies {NoMultipleH1RuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -117,4 +116,4 @@ export default {
},
};
},
};
});
5 changes: 2 additions & 3 deletions src/rules/no-reference-like-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const linkOrImagePattern =
// Rule Definition
//-----------------------------------------------------------------------------

/** @type {NoReferenceLikeUrlsRuleDefinition} */
export default {
export default /** @satisfies {NoReferenceLikeUrlsRuleDefinition} */ ({
meta: {
type: "problem",

Expand Down Expand Up @@ -107,4 +106,4 @@ export default {
},
};
},
};
});
Loading
Loading