Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: use mdast-util-from-markdown's fromMarkdown in website#9931

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionspackages/website/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@
"cross-fetch": "*",
"history": "^4.9.0",
"make-dir": "*",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-mdx": "^3.0.0",
"monaco-editor": "~0.50.0",
"raw-loader": "^4.0.2",
Expand Down
11 changes: 9 additions & 2 deletionspackages/website/plugins/generated-rule-docs/RuleDocsPage.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
import type { ESLintPluginRuleModule } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';
import { fromMarkdown } from 'mdast-util-from-markdown';
import type * as unist from 'unist';

import type { VFileWithStem } from '../utils/rules';
Expand DownExpand Up@@ -57,9 +58,15 @@ export class RuleDocsPage {
spliceChildren(
start: number,
deleteCount: number,
...items: unist.Node[]
...items:(string |unist.Node)[]
): void {
this.#children.splice(start, deleteCount, ...items);
this.#children.splice(
start,
deleteCount,
...items.map(item =>
typeof item === 'string' ? fromMarkdown(item) : item,
),
);
this.#headingIndices = this.#recreateHeadingIndices();
}

Expand Down
2 changes: 0 additions & 2 deletionspackages/website/plugins/generated-rule-docs/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,6 @@ import { isESLintPluginRuleModule, isVFileWithStem } from '../utils/rules';
import { addESLintHashToCodeBlocksMeta } from './addESLintHashToCodeBlocksMeta';
import { createRuleDocsPage } from './createRuleDocsPage';
import { insertBaseRuleReferences } from './insertions/insertBaseRuleReferences';
import { insertFormattingNotice } from './insertions/insertFormattingNotice';
import { insertNewRuleReferences } from './insertions/insertNewRuleReferences';
import { insertResources } from './insertions/insertResources';
import { insertRuleDescription } from './insertions/insertRuleDescription';
Expand All@@ -28,7 +27,6 @@ export const generatedRuleDocs: Plugin = () => {

removeSourceCodeNotice(page);
insertRuleDescription(page);
insertFormattingNotice(page);

const eslintrc = rule.meta.docs.extendsBaseRule
? insertBaseRuleReferences(page)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,33 +10,11 @@ export function insertBaseRuleReferences(page: RuleDocsPage): string {
? page.rule.meta.docs.extendsBaseRule
: page.file.stem;

page.spliceChildren(page.headingIndices.options + 1, 0, {
children: [
{
value: 'See ',
type: 'text',
},
{
children: [
{
type: 'inlineCode',
value: `eslint/${extendsBaseRuleName}`,
},
{
type: 'text',
value: ' options',
},
],
type: 'link',
url: `https://eslint.org/docs/rules/${extendsBaseRuleName}#options`,
},
{
type: 'text',
value: '.',
},
],
type: 'paragraph',
} as mdast.Paragraph);
page.spliceChildren(
page.headingIndices.options + 1,
0,
`See [\`eslint/${extendsBaseRuleName}\`'s options](https://eslint.org/docs/rules/${extendsBaseRuleName}#options).`,
);

const eslintrc = getEslintrcString(
extendsBaseRuleName,
Expand Down
View file
Open in desktop

This file was deleted.

View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import { EOL } from 'node:os';
import * as path from 'node:path';

import type { ESLintPluginDocs } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';
import { compile } from '@typescript-eslint/rule-schema-to-typescript-types';
import type * as mdast from 'mdast';
import type { MdxJsxFlowElement } from 'mdast-util-mdx';
Expand DownExpand Up@@ -62,12 +63,9 @@ export async function insertNewRuleReferences(
page.spliceChildren(
firstH2Index,
0,
{
lang: 'js',
type: 'code',
meta: 'title=".eslintrc.cjs"',
value: `module.exports = ${eslintrc};`,
} as mdast.Code,
`\`\`\`js title=".eslintrc.cjs"
module.exports = ${eslintrc};
\`\`\``,
{
attributes: [
{
Expand DownExpand Up@@ -97,46 +95,18 @@ export async function insertNewRuleReferences(
: Object.keys(page.rule.meta.schema).length === 0;

if (hasNoConfig) {
page.spliceChildren(page.headingIndices.options + 1, 0, {
children: [
{
type: 'text',
value: 'This rule is not configurable.',
},
],
type: 'paragraph',
} as mdast.Paragraph);
page.spliceChildren(
page.headingIndices.options + 1,
0,
'This rule is not configurable.',
);
} else if (!COMPLICATED_RULE_OPTIONS.has(page.file.stem)) {
page.spliceChildren(
page.headingIndices.options + 1,
0,
{
children:
typeof page.rule.meta.docs.recommended === 'object'
? [
{
type: 'text',
value:
'This rule accepts the following options, and has more strict settings in the ',
} as mdast.Text,
...linkToConfigs(
page.rule.meta.docs.requiresTypeChecking
? ['strict', 'strict-type-checked']
: ['strict'],
),
{
type: 'text',
value: ` config${page.rule.meta.docs.requiresTypeChecking ? 's' : ''}.`,
} as mdast.Text,
]
: [
{
type: 'text',
value: 'This rule accepts the following options:',
} as mdast.Text,
],
type: 'paragraph',
} as mdast.Paragraph,
typeof page.rule.meta.docs.recommended === 'object'
? linkToConfigsForObject(page.rule.meta.docs)
: 'This rule accepts the following options:',
{
lang: 'ts',
type: 'code',
Expand All@@ -156,30 +126,14 @@ export async function insertNewRuleReferences(
return eslintrc;
}

function linkToConfigs(configs: string[]): mdast.Node[] {
const links = configs.map(
(config): mdast.Link => ({
children: [
{
type: 'inlineCode',
value: config,
} as mdast.InlineCode,
],
type: 'link',
url: `/users/configs#${config}`,
}),
);

return links.length === 1
? links
: [
links[0],
{
type: 'text',
value: ' and ',
} as mdast.Text,
links[1],
];
function linkToConfigsForObject(docs: ESLintPluginDocs): string {
return [
'This rule accepts the following options, and has more strict settings in the',
(docs.requiresTypeChecking ? ['strict', 'strict-type-checked'] : ['strict'])
.map(config => `[${config}](/users/configs#${config})`)
.join(' and '),
`config${docs.requiresTypeChecking ? 's' : ''}.`,
].join(' ');
}

function getRuleDefaultOptions(page: RuleDocsPage): string {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
import type * as mdast from 'mdast';
import type { MdxJsxFlowElement } from 'mdast-util-mdx';

import { getUrlForRuleTest, sourceUrlPrefix } from '../../utils/rules';
Expand All@@ -9,61 +8,11 @@ export function insertResources(page: RuleDocsPage): void {
page.spliceChildren(
page.children.length,
0,
{
children: [
{
type: 'text',
value: 'Resources',
},
],
depth: 2,
type: 'heading',
} as mdast.Heading,
{
children: [
{
children: [
{
children: [
{
type: 'link',
url: `${sourceUrlPrefix}src/rules/${page.file.stem}.ts`,
children: [
{
type: 'text',
value: 'Rule source',
},
],
},
],
type: 'paragraph',
},
],
type: 'listItem',
},
{
children: [
{
children: [
{
type: 'link',
url: getUrlForRuleTest(page.file.stem),
children: [
{
type: 'text',
value: 'Test source',
},
],
},
],
type: 'paragraph',
},
],
type: 'listItem',
},
],
type: 'list',
} as mdast.List,
`## Resources

- [Rule source](${sourceUrlPrefix}src/rules/${page.file.stem}.ts)
- [Test source](${getUrlForRuleTest(page.file.stem)})
`,
);

// Also add a notice about coming from ESLint core for extension rules
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp