🌐 AI搜索 & 代理 主页
Skip to content

Commit 5405939

Browse files
authored
docs: show red underlines in TypeScript examples in rules docs (#19547)
1 parent 48b53d6 commit 5405939

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

docs/.eleventy.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const markdownIt = require("markdown-it");
1919
const markdownItRuleExample = require("./tools/markdown-it-rule-example");
2020
const prismESLintHook = require("./tools/prism-eslint-hook");
2121
const preWrapperPlugin = require("./src/_plugins/pre-wrapper.js");
22+
const typescriptESLintParser = require("@typescript-eslint/parser");
2223

2324
module.exports = function (eleventyConfig) {
2425
/*
@@ -206,22 +207,23 @@ module.exports = function (eleventyConfig) {
206207
// markdown-it plugin options for playground-linked code blocks in rule examples.
207208
const ruleExampleOptions = markdownItRuleExample({
208209
open({ type, code, languageOptions, env, codeBlockToken }) {
209-
/*
210-
* TypeScript isn't yet supported on the playground:
211-
* https://github.com/eslint/eslint.org/issues/709
212-
*/
213-
if (codeBlockToken.info === "ts") {
214-
return `<div class="${type}">`;
215-
}
210+
const isTypeScriptCode =
211+
codeBlockToken.info === "ts" || codeBlockToken.info === "tsx";
216212

217213
prismESLintHook.addContentMustBeMarked(
218214
codeBlockToken.content,
219-
languageOptions,
215+
isTypeScriptCode
216+
? { ...languageOptions, parser: typescriptESLintParser }
217+
: languageOptions,
220218
);
221219

222220
const isRuleRemoved = !Object.hasOwn(env.rules_meta, env.title);
223221

224-
if (isRuleRemoved) {
222+
/*
223+
* TypeScript isn't yet supported on the playground:
224+
* https://github.com/eslint/eslint.org/issues/709
225+
*/
226+
if (isRuleRemoved || isTypeScriptCode) {
225227
return `<div class="${type}">`;
226228
}
227229

docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@11ty/eleventy-plugin-syntaxhighlight": "^5.0.0",
3232
"@munter/tap-render": "^0.2.0",
3333
"@types/markdown-it": "^12.2.3",
34+
"@typescript-eslint/parser": "^8.27.0",
3435
"algoliasearch": "^4.12.1",
3536
"autoprefixer": "^10.4.13",
3637
"cross-env": "^7.0.3",

0 commit comments

Comments
 (0)