Skip to content

docs: add ast-spec, type-utils docs with docusaurus-plugin-typedoc #9293

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*

# Website
docs/packages/*/generated
packages/website/.docusaurus
packages/website/.cache-loader
packages/website/build
Expand Down
17 changes: 14 additions & 3 deletions docs/packages/Type_Utils.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
---
id: type-utils
sidebar_label: type-utils
toc_max_heading_level: 3
---

import GeneratedDocs from './type-utils/generated/index.md';

# `@typescript-eslint/type-utils`

<PackageLink packageName="type-utils" scope="@typescript-eslint" />

> Type utilities for working with TypeScript within ESLint rules.
> Type utilities for working with TypeScript types

This package contains public utilities for working with TypeScript types that ESLint rules often use.
This package contains public utilities for working with TypeScript types.
Rules declared in [`@typescript-eslint/eslint-plugin`](./ESLint_Plugin.mdx) use these utility functions.

The utilities in this package are both:

- More generally ESLint-focused than the broad TypeScript utilities in [`ts-api-utils`](https://npmjs.com/package/ts-api-utils)
- Separated from [`@typescript-eslint/utils`](./Utils.mdx) so that that package does not require a dependency on `typescript`

> See [Custom Rules](../developers/Custom_Rules.mdx) for documentation on creating your own custom ESLint rules for TypeScript code.
:::tip
See [Custom Rules](../developers/Custom_Rules.mdx) for documentation on creating your own custom ESLint rules for TypeScript code.
:::

---

The following documentation is auto-generated from source code.

<GeneratedDocs />
1 change: 1 addition & 0 deletions docs/packages/Utils.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
id: utils
sidebar_label: utils
toc_max_heading_level: 3
---

# `@typescript-eslint/utils`
Expand Down
13 changes: 13 additions & 0 deletions docs/packages/typescript-estree/AST_Spec.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
id: ast-spec
sidebar_label: AST Specification
toc_max_heading_level: 3
---

import GeneratedDocs from '../ast-spec/generated/index.md';

# AST Specification

The following auto-generated documentation describes the Abstract Syntax Tree (AST) generated by [`@typescript-eslint/typescript-estree`](../TypeScript_ESTree.mdx) for parsers such as [`@typescript-eslint/parser`](../Parser.mdx).

<GeneratedDocs />
3 changes: 3 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default {
'@generated/docusaurus.config',
'^@theme/.*',
'^@theme-original/.*',
'docusaurus-plugin-typedoc',
'typedoc',
'typedoc-plugin-markdown',
],
},
'packages/website-eslint': {
Expand Down
6 changes: 3 additions & 3 deletions packages/ast-spec/src/ast-node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export enum AST_NODE_TYPES {
WhileStatement = 'WhileStatement',
WithStatement = 'WithStatement',
YieldExpression = 'YieldExpression',
/**
* TS-prefixed nodes
*/

// TS_prefixed nodes
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /** ... */ JSDoc style comment was getting picked up as a comment on specifically TSAbstractAccessorProperty.

Screenshot of "TS-prefixed-nodes" as a TypeDoc-rendered comment on TSAbstractAccessorProperty


TSAbstractAccessorProperty = 'TSAbstractAccessorProperty',
TSAbstractKeyword = 'TSAbstractKeyword',
TSAbstractMethodDefinition = 'TSAbstractMethodDefinition',
Expand Down
15 changes: 9 additions & 6 deletions packages/ast-spec/src/base/ClassBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import type { BaseNode } from './BaseNode';
export interface ClassBase extends BaseNode {
/**
* Whether the class is an abstract class.
* ```
* abstract class Foo {...}
* @example
* ```ts
* abstract class Foo {}
* ```
*/
abstract: boolean;
Expand All @@ -21,16 +22,18 @@ export interface ClassBase extends BaseNode {
body: ClassBody;
/**
* Whether the class has been `declare`d:
* ```
* declare class Foo {...}
* @example
* ```ts
* declare class Foo {}
* ```
*/
declare: boolean;
/**
* The decorators declared for the class.
* ```
* @example
* ```ts
* @deco
* class Foo {...}
* class Foo {}
* ```
*/
decorators: Decorator[];
Expand Down
12 changes: 6 additions & 6 deletions packages/ast-spec/src/base/FunctionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export interface FunctionBase extends BaseNode {
/**
* Whether the function is async:
* ```
* async function foo(...) {...}
* const x = async function (...) {...}
* const x = async (...) => {...}
* async function foo() {}
* const x = async function () {}
* const x = async () => {}
* ```
*/
async: boolean;
Expand All @@ -27,7 +27,7 @@ export interface FunctionBase extends BaseNode {
/**
* This is only `true` if and only if the node is a `TSDeclareFunction` and it has `declare`:
* ```
* declare function foo(...) {...}
* declare function foo() {}
* ```
*/
declare: boolean;
Expand All @@ -42,8 +42,8 @@ export interface FunctionBase extends BaseNode {
/**
* Whether the function is a generator function:
* ```
* function *foo(...) {...}
* const x = function *(...) {...}
* function *foo() {}
* const x = function *() {}
* ```
* This is always `false` for arrow functions as they cannot be generators.
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/ast-spec/src/base/NodeOrTokenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ export interface NodeOrTokenData {
* The source location information of the node.
*
* The loc property is defined as nullable by ESTree, but ESLint requires this property.
*
* @see {SourceLocation}
*/
loc: SourceLocation;

/**
* @see {Range}
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These @sees just restate the type. No useful info added.

range: Range;

type: string;
Expand Down
10 changes: 6 additions & 4 deletions packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ export interface ExportAllDeclaration extends BaseNode {
type: AST_NODE_TYPES.ExportAllDeclaration;
/**
* The assertions declared for the export.
* ```
* export * from 'mod' assert { type: 'json' };
* @example
* ```ts
* export * from 'mod' assert \{ type: 'json' \};
* ```
* @deprecated Replaced with {@link `attributes`}.
*/
assertions: ImportAttribute[];
/**
* The attributes declared for the export.
* ```
* export * from 'mod' with { type: 'json' };
* @example
* ```ts
* export * from 'mod' with \{ type: 'json' \};
* ```
*/
attributes: ImportAttribute[];
Expand Down
16 changes: 10 additions & 6 deletions packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ interface ExportNamedDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.ExportNamedDeclaration;
/**
* The assertions declared for the export.
* ```
* export { foo } from 'mod' assert { type: 'json' };
* @example
* ```ts
* export { foo } from 'mod' assert \{ type: 'json' \};
* ```
* This will be an empty array if `source` is `null`
* @deprecated Replaced with {@link `attributes`}.
*/
assertions: ImportAttribute[];
/**
* The attributes declared for the export.
* ```
* export { foo } from 'mod' with { type: 'json' };
* @example
* ```ts
* export { foo } from 'mod' with \{ type: 'json' \};
* ```
* This will be an empty array if `source` is `null`
*/
attributes: ImportAttribute[];
/**
* The exported declaration.
* ```
* @example
* ```ts
* export const x = 1;
* ```
* This will be `null` if `source` is not `null`, or if there are `specifiers`
Expand All @@ -43,7 +46,8 @@ interface ExportNamedDeclarationBase extends BaseNode {
source: StringLiteral | null;
/**
* The specifiers being exported.
* ```
* @example
* ```ts
* export { a, b };
* ```
* This will be an empty array if `declaration` is not `null`
Expand Down
10 changes: 6 additions & 4 deletions packages/ast-spec/src/declaration/ImportDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ export interface ImportDeclaration extends BaseNode {
type: AST_NODE_TYPES.ImportDeclaration;
/**
* The assertions declared for the export.
* ```
* import * from 'mod' assert { type: 'json' };
* @example
* ```ts
* import * from 'mod' assert \{ type: 'json' \};
* ```
* @deprecated Replaced with {@link `attributes`}.
*/
assertions: ImportAttribute[];
/**
* The attributes declared for the export.
* ```
* import * from 'mod' with { type: 'json' };
* @example
* ```ts
* import * from 'mod' with \{ type: 'json' \};
* ```
*/
attributes: ImportAttribute[];
Expand Down
10 changes: 6 additions & 4 deletions packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ export interface TSEnumDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSEnumDeclaration;
/**
* Whether this is a `const` enum.
* ```
* const enum Foo {...}
* @example
* ```ts
* const enum Foo {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid TS syntax in ```s -with or without @example or the `ts` block- causes a parse error in the generated `index.md`:

Error: MDX compilation failed for file "/Users/josh/repos/typescript-eslint/docs/packages/ast-spec/generated/index.md"
Cause: Could not parse expression with acorn
Details:
{
  "cause": {
    "pos": 65758,
    "loc": {
      "line": 2505,
      "column": 102
    },
    "raisedAt": 3
  },
  "column": 103,
  "message": "Could not parse expression with acorn",
  "line": 2505,
  "name": "2505:103",
  "place": {
    "line": 2505,
    "column": 103,
    "offset": 65758
  },
  "reason": "Could not parse expression with acorn",
  "ruleId": "acorn",
  "source": "micromark-extension-mdx-expression",
  "url": "https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#could-not-parse-expression-with-acorn"
}

The Markdown in question:

#### Properties

| Property | Type | Description | Overrides |
| :------ | :------ | :------ | :------ |
| `const` | `boolean` | <p>Whether this is a `const` enum.</p><p>**Example**</p><code>const enum Foo {...}</code> | - |
| `declare` | `boolean` | <p>Whether this is a `declare`d enum.</p><p>**Example**</p><code>declare enum Foo {...}</code> | - |
| `id` | [`Identifier`](index.md#identifier) | The enum name. | - |
| `members` | [`TSEnumMember`](index.md#tsenummember)[] | The enum members. | - |
| `type` | `TSEnumDeclaration` | - | [`BaseNode`](index.md#basenode).`type` |

***

...where the issue is on the <code> in the first tbody row.

* ```
*/
const: boolean;
/**
* Whether this is a `declare`d enum.
* ```
* declare enum Foo {...}
* @example
* ```ts
* declare enum Foo {}
* ```
*/
declare: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ interface TSImportEqualsDeclarationBase extends BaseNode {
id: Identifier;
/**
* The value being aliased.
* ```
* @example
* ```ts
* import F1 = A;
* import F2 = A.B.C;
* import F3 = require('mod');
Expand Down
10 changes: 8 additions & 2 deletions packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ interface TSModuleDeclarationBase extends BaseNode {
body?: TSModuleBlock;
/**
* Whether this is a global declaration
* @example
* ```ts
* declare global {}
* ```
*
* @deprecated Use {@link kind} instead
*/
// TODO - remove this in the next major (we have `.kind` now)
global: boolean;
/**
* Whether the module is `declare`d
* ```
* @example
* ```ts
* declare namespace F {}
* ```
*/
declare: boolean;

/**
* The keyword used to define this module declaration
* ```
* @example
* ```ts
* namespace Foo {}
* ^^^^^^^^^
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export interface TSTypeAliasDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
/**
* Whether the type was `declare`d.
* ```
* @example
* ```ts
* declare type T = 1;
* ```
*/
Expand Down
Loading
Loading