-
Notifications
You must be signed in to change notification settings - Fork 85
fix: update TypeScript to v6 and tighten the return type of getParent
#637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
b3903ed
f28cd84
6329afa
714708f
33afd17
3d55d6e
2bc596c
7657b86
adf3c3d
846478f
6399827
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import { lineEndingPattern } from "../util.js"; | |
|
|
||
| /** | ||
| * @import { Position } from "unist"; | ||
| * @import { Root, Node, Html } from "mdast"; | ||
| * @import { Parent, Root, Node, Html } from "mdast"; | ||
| * @import { TraversalStep, FileProblem, DirectiveType, RulesConfig } from "@eslint/core"; | ||
| * @import { MarkdownLanguageOptions } from "../types.js"; | ||
| */ | ||
|
|
@@ -77,7 +77,7 @@ function extractInlineConfigCommentsFromHTML(node, sourceCode) { | |
| /** @type {Array<InlineConfigComment>} */ | ||
| const comments = []; | ||
|
|
||
| /** @type {RegExpExecArray} */ | ||
| /** @type {RegExpExecArray | null} */ | ||
| let match; | ||
|
|
||
| while ((match = htmlComment.exec(node.value))) { | ||
|
|
@@ -124,7 +124,7 @@ export class MarkdownSourceCode extends TextSourceCodeBase { | |
|
|
||
| /** | ||
| * Cache of parent nodes. | ||
| * @type {WeakMap<Node, Node>} | ||
| * @type {WeakMap<Node, Parent|undefined>} | ||
| */ | ||
| #parents = new WeakMap(); | ||
|
|
||
|
|
@@ -163,7 +163,7 @@ export class MarkdownSourceCode extends TextSourceCodeBase { | |
| /** | ||
| * Returns the parent of the given node. | ||
| * @param {Node} node The node to get the parent of. | ||
| * @returns {Node|undefined} The parent of the node. | ||
| * @returns {Parent|undefined} The parent of the node. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is why the PR is marked as If the value is not |
||
| */ | ||
| getParent(node) { | ||
| return this.#parents.get(node); | ||
|
|
@@ -303,6 +303,12 @@ export class MarkdownSourceCode extends TextSourceCodeBase { | |
| /** @type {Array<VisitNodeStep>} */ | ||
| const steps = (this.#steps = []); | ||
|
|
||
| /** | ||
| * Recursively visits a node and its children. | ||
| * @param {Node} node The node to visit. | ||
| * @param {Parent} [parent] The parent of the node. | ||
| * @returns {void} | ||
| */ | ||
| const visit = (node, parent) => { | ||
| // first set the parent | ||
| this.#parents.set(node, parent); | ||
|
|
@@ -318,13 +324,15 @@ export class MarkdownSourceCode extends TextSourceCodeBase { | |
|
|
||
| // save HTML nodes | ||
| if (node.type === "html") { | ||
| this.#htmlNodes.push(node); | ||
| this.#htmlNodes.push(/** @type {Html} */ (node)); | ||
| } | ||
|
|
||
| // then visit the children | ||
| if (node.children) { | ||
| node.children.forEach(child => { | ||
| visit(child, node); | ||
| if ("children" in node) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Markdown AST (Mdast), if a node has children they are always represented as an array (even when empty), so I think refactoring |
||
| const parentNode = /** @type {Parent} */ (node); | ||
|
|
||
| parentNode.children.forEach(child => { | ||
| visit(child, parentNode); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "emitDeclarationOnly": false, | ||
| "allowJs": false, | ||
| "checkJs": false, | ||
| "noEmit": true, | ||
| "rootDir": "../..", | ||
| "strict": true, | ||
| "exactOptionalPropertyTypes": true | ||
| "strictNullChecks": true, | ||
| "useUnknownInCatchVariables": true, | ||
| "exactOptionalPropertyTypes": true, | ||
| "verbatimModuleSyntax": true, | ||
| "erasableSyntaxOnly": true | ||
|
Comment on lines
+12
to
+13
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent the same issue as in eslint/json#88, I've also set the https://github.com/eslint/json/blob/main/tests/types/tsconfig.json#L12-L13 |
||
| }, | ||
| "files": [], | ||
| "include": ["**/*.test.ts", "**/*.test.cts", "../../dist"] | ||
| "include": [".", "../../dist"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "allowJs": false, | ||
| "checkJs": false, | ||
| "noEmit": true, | ||
| "rootDir": "../..", | ||
| "strict": true, | ||
| "strictNullChecks": true, | ||
| "useUnknownInCatchVariables": true, | ||
| "exactOptionalPropertyTypes": true, | ||
| "verbatimModuleSyntax": true | ||
| // "erasableSyntaxOnly" is not supported in TypeScript < 5.8. | ||
| }, | ||
| "files": [], | ||
| "include": [".", "../../dist"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,10 @@ | |
| "outDir": "dist", | ||
| "target": "ES2022", | ||
| "moduleResolution": "NodeNext", | ||
| "module": "NodeNext" | ||
| "module": "NodeNext", | ||
| "rootDir": "./src", | ||
| "strictNullChecks": false, | ||
| "useUnknownInCatchVariables": false, | ||
| "types": ["mdast", "unist"] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these types packages included globally?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for pointing that out. I misunderstood how the I've now realized how it works and updated it in 6399827. |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This addition prevents the warning that appears when I run
npm run lint:Reference:
markdown/eslint.config.js
Line 27 in e2396bb