-
-
Notifications
You must be signed in to change notification settings - Fork 757
/
Copy pathlint-javascript.cjs
36 lines (33 loc) · 1.07 KB
/
lint-javascript.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// @ts-check
"use strict";
const js = require("@eslint/js");
const eslint = require("eslint");
const linter = new eslint.Linter();
const languageJavaScript = /js|javascript/i;
/** @type {import("markdownlint").Rule} */
module.exports = {
"names": [ "lint-javascript" ],
"description": "Rule that lints JavaScript code",
"tags": [ "test", "lint", "javascript" ],
"parser": "markdownit",
"function": (params, onError) => {
const fences = params.parsers.markdownit.tokens
.filter((token) => token.type === "fence");
for (const fence of fences) {
if (languageJavaScript.test(fence.info)) {
const results = linter.verify(fence.content, js.configs.recommended);
for (const result of results) {
const lineNumber = fence.lineNumber + result.line;
onError({
"lineNumber": lineNumber,
"detail": result.message,
"context": params.lines[lineNumber - 1]
});
}
}
}
// Unsupported by this sample:
// "code_block": language unknown
// "code_inline": too brief
}
};