⬅️ Back to Table of Contents
📄 RuleDocsPage.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
2 |
🧱 Classes |
1 |
📦 Imports |
4 |
📊 Variables & Constants |
1 |
📐 Interfaces |
1 |
📑 Type Aliases |
1 |
📚 Table of Contents
🛠️ File Location:
📂 packages/website/plugins/generated-rule-docs/RuleDocsPage.ts
📦 Imports
Name |
Source |
ESLintPluginRuleModule |
@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules |
fromMarkdown |
mdast-util-from-markdown |
VFileWithStem |
../utils/rules |
findHeadingIndex |
../utils/rules |
Variables & Constants
Name |
Type |
Kind |
Value |
Exported |
requiredHeadingNames |
readonly ["How to Use", "Options", "When Not To Use It", "Related To"] |
const |
`[ |
|
'How to Use', |
|
|
|
|
'Options', |
|
|
|
|
'When Not To Use It', |
|
|
|
|
'Related To', |
|
|
|
|
] as const` |
✓ |
|
|
|
Functions
Code
#recreateHeadingIndices(): RequiredHeadingIndices {
return {
howToUse: findHeadingIndex(this.#children, 2, requiredHeadingNames[0]),
options: findHeadingIndex(this.#children, 2, requiredHeadingNames[1]),
whenNotToUseIt: findHeadingIndex(
this.#children,
2,
requiredHeadingNames[2],
),
};
}
- Return Type:
RequiredHeadingIndices
- Calls:
findHeadingIndex (from ../utils/rules)
RuleDocsPage.spliceChildren(start: number, deleteCount: number, items: (string | unist.Node)[]): void
Code
spliceChildren(
start: number,
deleteCount: number,
...items: (string | unist.Node)[]
): void {
this.#children.splice(
start,
deleteCount,
...items.map(item =>
typeof item === 'string' ? fromMarkdown(item) : item,
),
);
this.#headingIndices = this.#recreateHeadingIndices();
}
- Parameters:
start: number
deleteCount: number
items: (string | unist.Node)[]
- Return Type:
void
- Calls:
this.#children.splice
items.map
fromMarkdown (from mdast-util-from-markdown)
this.#recreateHeadingIndices
Classes
RuleDocsPage
Class Code
export class RuleDocsPage {
#children: unist.Node[];
#file: Readonly<VFileWithStem>;
#headingIndices: RequiredHeadingIndices;
#rule: Readonly<ESLintPluginRuleModule>;
constructor(
children: unist.Node[],
file: Readonly<VFileWithStem>,
rule: Readonly<ESLintPluginRuleModule>,
) {
this.#children = children;
this.#file = file;
this.#headingIndices = this.#recreateHeadingIndices();
this.#rule = rule;
}
#recreateHeadingIndices(): RequiredHeadingIndices {
return {
howToUse: findHeadingIndex(this.#children, 2, requiredHeadingNames[0]),
options: findHeadingIndex(this.#children, 2, requiredHeadingNames[1]),
whenNotToUseIt: findHeadingIndex(
this.#children,
2,
requiredHeadingNames[2],
),
};
}
spliceChildren(
start: number,
deleteCount: number,
...items: (string | unist.Node)[]
): void {
this.#children.splice(
start,
deleteCount,
...items.map(item =>
typeof item === 'string' ? fromMarkdown(item) : item,
),
);
this.#headingIndices = this.#recreateHeadingIndices();
}
get children(): readonly unist.Node[] {
return this.#children;
}
get file(): Readonly<VFileWithStem> {
return this.#file;
}
get headingIndices(): Readonly<RequiredHeadingIndices> {
return this.#headingIndices;
}
get rule(): Readonly<ESLintPluginRuleModule> {
return this.#rule;
}
}
Methods
#recreateHeadingIndices(): RequiredHeadingIndices
Code
#recreateHeadingIndices(): RequiredHeadingIndices {
return {
howToUse: findHeadingIndex(this.#children, 2, requiredHeadingNames[0]),
options: findHeadingIndex(this.#children, 2, requiredHeadingNames[1]),
whenNotToUseIt: findHeadingIndex(
this.#children,
2,
requiredHeadingNames[2],
),
};
}
spliceChildren(start: number, deleteCount: number, items: (string | unist.Node)[]): void
Code
spliceChildren(
start: number,
deleteCount: number,
...items: (string | unist.Node)[]
): void {
this.#children.splice(
start,
deleteCount,
...items.map(item =>
typeof item === 'string' ? fromMarkdown(item) : item,
),
);
this.#headingIndices = this.#recreateHeadingIndices();
}
Interfaces
RequiredHeadingIndices
Interface Code
export interface RequiredHeadingIndices {
howToUse: number;
options: number;
whenNotToUseIt: number;
}
Properties
Name |
Type |
Optional |
Description |
howToUse |
number |
✗ |
|
options |
number |
✗ |
|
whenNotToUseIt |
number |
✗ |
|
Type Aliases
HeadingName
type HeadingName = (typeof requiredHeadingNames)[number];