Skip to content

Commit 3986839

Browse files
lumirlumirfasttime
andauthored
fix: type compatibility issue between Markdown v8 and ESLint v9.39.x (#648)
* fix: resolve type compatibility issue between `@eslint/markdown` v8 and `eslint` v9 * wip * wip * wip * wip * wip: turn on a workaround * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Apply suggestion from @fasttime Co-authored-by: Francesco Trotta <[email protected]> --------- Co-authored-by: Francesco Trotta <[email protected]>
1 parent 133ddaa commit 3986839

27 files changed

Lines changed: 76 additions & 84 deletions

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ jobs:
7979

8080
test_types:
8181
name: Test Types
82+
strategy:
83+
matrix:
84+
eslint: [9.39.0, 9.x, 10.x]
8285
runs-on: ubuntu-latest
8386
steps:
8487
- uses: actions/checkout@v6
@@ -88,6 +91,8 @@ jobs:
8891
node-version: "lts/*"
8992
- name: Install dependencies
9093
run: npm install
94+
- name: Install ESLint v${{ matrix.eslint }}
95+
run: npm install -D eslint@${{ matrix.eslint }} @eslint/js@${{ matrix.eslint }}
9196
- name: Check Types
9297
run: npm run test:types
9398
- name: Check Types (TypeScript 5.3)

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Lint Markdown with ESLint, as well JS, JSX, TypeScript, and more inside Markdown
1717

1818
### Installing
1919

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

2222
For Node.js and compatible runtimes:
2323

‎src/index.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import rules from "./build/rules.js";
1818
//-----------------------------------------------------------------------------
1919

2020
/**
21-
* @import { Linter } from "eslint";
21+
* @import { ConfigObject, RulesConfig } from "@eslint/core";
2222
*/
2323

2424
//-----------------------------------------------------------------------------
2525
// Exports
2626
//-----------------------------------------------------------------------------
2727

28-
/** @satisfies {Linter.RulesRecord} */
28+
/** @satisfies {RulesConfig} */
2929
const processorRulesConfig = {
3030
// The Markdown parser automatically trims trailing
3131
// newlines from code blocks.
@@ -97,7 +97,7 @@ const plugin = {
9797
rules: recommendedRules,
9898
},
9999
],
100-
processor: /** @type {Linter.Config[]} */ ([
100+
processor: /** @type {ConfigObject[]} */ ([
101101
{
102102
name: "markdown/recommended/plugin",
103103
plugins: (processorPlugins = {}),

‎src/processor.js‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ import { fromMarkdown } from "mdast-util-from-markdown";
1414
//-----------------------------------------------------------------------------
1515

1616
/**
17+
* @import { LintMessage, RuleTextEdit, SourceRange } from "@eslint/core";
1718
* @import { Node, Parent, Code, Html } from "mdast";
18-
* @import { Linter, Rule, AST } from "eslint";
1919
* @import { Block, RangeMap } from "./types.js";
20-
* @typedef {Linter.LintMessage} Message
21-
* @typedef {Rule.Fix} Fix
22-
* @typedef {AST.Range} Range
2320
*/
2421

2522
//-----------------------------------------------------------------------------
@@ -356,12 +353,12 @@ function preprocess(sourceText, filename) {
356353
/**
357354
* Adjusts a fix in a code block.
358355
* @param {Block} block A code block.
359-
* @param {Fix} fix A fix to adjust.
360-
* @returns {Fix} The fix with adjusted ranges.
356+
* @param {RuleTextEdit} fix A fix to adjust.
357+
* @returns {RuleTextEdit} The fix with adjusted ranges.
361358
*/
362359
function adjustFix(block, fix) {
363360
return {
364-
range: /** @type {Range} */ (
361+
range: /** @type {SourceRange} */ (
365362
fix.range.map(range => {
366363
// Advance through the block's range map to find the last
367364
// matching range by finding the first range too far and
@@ -386,7 +383,7 @@ function adjustFix(block, fix) {
386383
/**
387384
* Creates a map function that adjusts messages in a code block.
388385
* @param {Block} block A code block.
389-
* @returns {(message: Message) => Message} A function that adjusts messages in a code block.
386+
* @returns {(message: LintMessage) => LintMessage | null} A function that adjusts messages in a code block.
390387
*/
391388
function adjustBlock(block) {
392389
const leadingCommentLines = block.comments.reduce(
@@ -398,8 +395,8 @@ function adjustBlock(block) {
398395

399396
/**
400397
* Adjusts ESLint messages to point to the correct location in the Markdown.
401-
* @param {Message} message A message from ESLint.
402-
* @returns {Message} The same message, but adjusted to the correct location.
398+
* @param {LintMessage} message A message from ESLint.
399+
* @returns {LintMessage} The same message, but adjusted to the correct location.
403400
*/
404401
return function adjustMessage(message) {
405402
if (!Number.isInteger(message.line)) {
@@ -416,7 +413,7 @@ function adjustBlock(block) {
416413
return null;
417414
}
418415

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

446443
/**
447444
* Excludes unsatisfiable rules from the list of messages.
448-
* @param {Message} message A message from the linter.
445+
* @param {LintMessage} message A message from the linter.
449446
* @returns {boolean} True if the message should be included in output.
450447
*/
451448
function excludeUnsatisfiableRules(message) {
@@ -454,10 +451,10 @@ function excludeUnsatisfiableRules(message) {
454451

455452
/**
456453
* Transforms generated messages for output.
457-
* @param {Array<Message[]>} messages An array containing one array of messages
454+
* @param {Array<LintMessage[]>} messages An array containing one array of messages
458455
* for each code block returned from `preprocess`.
459456
* @param {string} filename The filename of the file
460-
* @returns {Message[]} A flattened array of messages with mapped locations.
457+
* @returns {LintMessage[]} A flattened array of messages with mapped locations.
461458
*/
462459
function postprocess(messages, filename) {
463460
const blocks = blocksCache.get(filename);

‎src/rules/fenced-code-language.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ const fencedCodeCharacters = new Set(["`", "~"]);
2424
// Rule Definition
2525
//-----------------------------------------------------------------------------
2626

27-
/** @type {FencedCodeLanguageRuleDefinition} */
28-
export default {
27+
export default /** @satisfies {FencedCodeLanguageRuleDefinition} */ ({
2928
meta: {
3029
type: "problem",
3130

@@ -135,4 +134,4 @@ export default {
135134
},
136135
};
137136
},
138-
};
137+
});

‎src/rules/fenced-code-meta.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
// Rule Definition
1919
//-----------------------------------------------------------------------------
2020

21-
/** @type {FencedCodeMetaRuleDefinition} */
22-
export default {
21+
export default /** @satisfies {FencedCodeMetaRuleDefinition} */ ({
2322
meta: {
2423
type: "problem",
2524

@@ -99,4 +98,4 @@ export default {
9998
},
10099
};
101100
},
102-
};
101+
});

‎src/rules/heading-increment.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import { frontmatterHasTitle } from "../util.js";
2424
// Rule Definition
2525
//-----------------------------------------------------------------------------
2626

27-
/** @type {HeadingIncrementRuleDefinition} */
28-
export default {
27+
export default /** @satisfies {HeadingIncrementRuleDefinition} */ ({
2928
meta: {
3029
type: "problem",
3130

@@ -101,4 +100,4 @@ export default {
101100
},
102101
};
103102
},
104-
};
103+
});

‎src/rules/no-bare-urls.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ function parseHtmlTag(tagText) {
6666
// Rule Definition
6767
//-----------------------------------------------------------------------------
6868

69-
/** @type {NoBareUrlsRuleDefinition} */
70-
export default {
69+
export default /** @satisfies {NoBareUrlsRuleDefinition} */ ({
7170
meta: {
7271
type: "problem",
7372

@@ -177,4 +176,4 @@ export default {
177176
},
178177
};
179178
},
180-
};
179+
});

‎src/rules/no-duplicate-definitions.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import { normalizeIdentifier } from "micromark-util-normalize-identifier";
2525
// Rule Definition
2626
//-----------------------------------------------------------------------------
2727

28-
/** @type {NoDuplicateDefinitionsRuleDefinition} */
29-
export default {
28+
export default /** @satisfies {NoDuplicateDefinitionsRuleDefinition} */ ({
3029
meta: {
3130
type: "problem",
3231

@@ -151,4 +150,4 @@ export default {
151150
},
152151
};
153152
},
154-
};
153+
});

‎src/rules/no-duplicate-headings.js‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
// Rule Definition
1919
//-----------------------------------------------------------------------------
2020

21-
/** @type {NoDuplicateHeadingsRuleDefinition} */
22-
export default {
21+
export default /** @satisfies {NoDuplicateHeadingsRuleDefinition} */ ({
2322
meta: {
2423
type: "problem",
2524

@@ -118,4 +117,4 @@ export default {
118117
},
119118
};
120119
},
121-
};
120+
});

0 commit comments

Comments
 (0)