Skip to content

Commit 9c98e2e

Browse files
authored
Fix markdownlint-github issues (#61)
Fixes issues with the markdownlint-github plugin that were causing runtime errors.
1 parent ad5f515 commit 9c98e2e

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

@types/markdownlint-github.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
declare module "@github/markdownlint-github" {
22
import {Configuration, Rule} from "markdownlint";
3-
const main: Rule[] & {
4-
init(overrides: Configuration): Configuration;
5-
};
6-
export default main;
3+
const rules: Rule[];
4+
export default rules;
5+
export function init(config: Configuration): Promise<Configuration>;
76
}

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"license": "MIT",
1515
"dependencies": {
16-
"@github/markdownlint-github": "^0.7.0",
16+
"@github/markdownlint-github": "^0.8.0",
1717
"@webcomponents/custom-elements": "^1.6.0",
1818
"dom-input-range": "^2.0.0",
1919
"markdownlint": "^0.37.4"

src/components/linted-markdown-editor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ export abstract class LintedMarkdownEditor extends Component {
168168
this.#tooltipAnnotations = [];
169169
}
170170

171-
#lint() {
171+
async #lint() {
172172
this.#clear();
173173

174174
// clear() will not hide the tooltip if the mouse is over it, but if the user is typing then they are not trying to copy content
175175
this.#tooltip.hide(true);
176176

177177
if (document.activeElement !== this.#editor) return;
178178

179-
const errors = lintMarkdown(this.value, this.markdownRenderTarget);
179+
const errors = await lintMarkdown(this.value, this.markdownRenderTarget);
180180

181181
this.#annotations = errors.map(
182182
(error) => new LintErrorAnnotation(error, this, this.#annotationsPortal)

src/utilities/lint-markdown.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import {lint} from "markdownlint/sync";
1+
import {lint} from "markdownlint/promise";
22
import {LintError as MarkdownLintError} from "markdownlint";
3-
import markdownlintGitHub from "@github/markdownlint-github";
3+
import githubRules, {
4+
init as initGitHubConfig,
5+
} from "@github/markdownlint-github";
46
import startHeadingLevel from "../rules/start-heading-level.js";
57

68
export interface LintError extends MarkdownLintError {
@@ -15,15 +17,15 @@ export type MarkdownRenderTarget = "github" | "document";
1517
* rendered? This affects which rules should be enabled as some only apply to
1618
* GitHub.com content.
1719
*/
18-
export const lintMarkdown = (
20+
export const lintMarkdown = async (
1921
markdown: string,
2022
renderTarget: MarkdownRenderTarget
21-
): LintError[] =>
22-
lint({
23+
): Promise<LintError[]> => {
24+
const result = await lint({
2325
strings: {
2426
content: markdown,
2527
},
26-
config: markdownlintGitHub.init({
28+
config: await initGitHubConfig({
2729
default: false,
2830
"no-reversed-links": true,
2931
"no-empty-links": true,
@@ -39,13 +41,18 @@ export const lintMarkdown = (
3941
},
4042
}),
4143
handleRuleFailures: true,
42-
customRules: [...markdownlintGitHub, startHeadingLevel],
43-
}).content?.map((error) => ({
44-
...error,
45-
justification: error.ruleNames
46-
.map((name) => ruleJustifications[name])
47-
.join(" "),
48-
})) ?? [];
44+
customRules: [...githubRules, startHeadingLevel],
45+
});
46+
47+
return (
48+
result.content?.map((error) => ({
49+
...error,
50+
justification: error.ruleNames
51+
.map((name) => ruleJustifications[name])
52+
.join(" "),
53+
})) ?? []
54+
);
55+
};
4956

5057
export const ruleJustifications: Partial<Record<string, string>> = {
5158
"heading-increment":

0 commit comments

Comments
 (0)