From 80da99a61eb542a5d9e6f9dd3127a06cba19e9c8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 26 Sep 2025 08:59:41 -0400 Subject: [PATCH 1/6] feat(rule-schema-to-typescript-types): clean up and make public --- .github/workflows/ci.yml | 1 + docs/packages/RuleSchemaToTypeScriptTypes.mdx | 36 +++++ .../adjacent-overload-signatures.shot | 2 +- .../schema-snapshots/await-thenable.shot | 2 +- .../schema-snapshots/ban-tslint-comment.shot | 2 +- .../schema-snapshots/default-param-last.shot | 2 +- .../no-array-constructor.shot | 2 +- .../schema-snapshots/no-array-delete.shot | 2 +- .../no-confusing-non-null-assertion.shot | 2 +- .../no-dupe-class-members.shot | 2 +- .../no-duplicate-enum-values.shot | 2 +- .../schema-snapshots/no-dynamic-delete.shot | 2 +- .../no-extra-non-null-assertion.shot | 2 +- .../schema-snapshots/no-for-in-array.shot | 2 +- .../schema-snapshots/no-implied-eval.shot | 2 +- .../no-import-type-side-effects.shot | 2 +- .../tests/schema-snapshots/no-loop-func.shot | 2 +- .../no-loss-of-precision.shot | 2 +- .../schema-snapshots/no-misused-new.shot | 2 +- .../schema-snapshots/no-mixed-enums.shot | 2 +- ...-non-null-asserted-nullish-coalescing.shot | 2 +- .../no-non-null-asserted-optional-chain.shot | 2 +- .../no-non-null-assertion.shot | 2 +- .../no-redundant-type-constituents.shot | 2 +- ...cessary-parameter-property-assignment.shot | 2 +- .../no-unnecessary-qualifier.shot | 2 +- .../no-unnecessary-template-expression.shot | 2 +- .../no-unnecessary-type-arguments.shot | 2 +- .../no-unnecessary-type-constraint.shot | 2 +- .../no-unnecessary-type-conversion.shot | 2 +- .../no-unnecessary-type-parameters.shot | 2 +- .../schema-snapshots/no-unsafe-argument.shot | 2 +- .../no-unsafe-assignment.shot | 2 +- .../schema-snapshots/no-unsafe-call.shot | 2 +- .../no-unsafe-declaration-merging.shot | 2 +- .../no-unsafe-enum-comparison.shot | 2 +- .../no-unsafe-function-type.shot | 2 +- .../no-unsafe-member-access.shot | 2 +- .../schema-snapshots/no-unsafe-return.shot | 2 +- .../no-unsafe-type-assertion.shot | 2 +- .../no-unsafe-unary-minus.shot | 2 +- .../no-useless-constructor.shot | 2 +- .../no-useless-empty-export.shot | 2 +- .../no-wrapper-object-types.shot | 2 +- .../non-nullable-type-assertion-style.shot | 2 +- .../schema-snapshots/prefer-as-const.shot | 2 +- .../prefer-enum-initializers.shot | 2 +- .../tests/schema-snapshots/prefer-find.shot | 2 +- .../tests/schema-snapshots/prefer-for-of.shot | 2 +- .../prefer-function-type.shot | 2 +- .../schema-snapshots/prefer-includes.shot | 2 +- .../prefer-namespace-keyword.shot | 2 +- .../prefer-reduce-type-parameter.shot | 2 +- .../schema-snapshots/prefer-regexp-exec.shot | 2 +- .../prefer-return-this-type.shot | 2 +- .../prefer-ts-expect-error.shot | 2 +- .../related-getter-setter-pairs.shot | 2 +- .../tests/schema-snapshots/require-await.shot | 2 +- ...se-unknown-in-catch-callback-variable.shot | 2 +- packages/eslint-plugin/tests/schemas.test.ts | 8 +- .../package.json | 8 +- .../src/generateArrayType.ts | 8 +- .../src/generateObjectType.ts | 4 +- .../src/generateType.ts | 4 +- .../src/generateUnionType.ts | 6 +- .../src/index.ts | 51 +++---- .../src/optimizeAST.ts | 10 +- .../src/printAST.ts | 12 +- .../src/types.ts | 34 +++-- .../tests/index.test.ts | 134 ++++++++++++++++++ packages/website/docusaurus.config.mts | 54 +++---- .../insertions/insertNewRuleReferences.ts | 11 +- packages/website/sidebars/sidebar.base.js | 1 + yarn.lock | 1 - 74 files changed, 333 insertions(+), 164 deletions(-) create mode 100644 docs/packages/RuleSchemaToTypeScriptTypes.mdx create mode 100644 packages/rule-schema-to-typescript-types/tests/index.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 91e78e2a606a..0d0e3f81e81e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -195,6 +195,7 @@ jobs: 'eslint-plugin-internal', 'parser', 'project-service', + 'rule-schema-to-typescript-types', 'rule-tester', 'scope-manager', 'tsconfig-utils', diff --git a/docs/packages/RuleSchemaToTypeScriptTypes.mdx b/docs/packages/RuleSchemaToTypeScriptTypes.mdx new file mode 100644 index 000000000000..c684c357c5f6 --- /dev/null +++ b/docs/packages/RuleSchemaToTypeScriptTypes.mdx @@ -0,0 +1,36 @@ +--- +id: rule-schema-to-typescript-types +sidebar_label: rule-schema-to-typescript-types +toc_max_heading_level: 3 +--- + +import GeneratedDocs from './rule-schema-to-typescript-types/generated/index.md'; + +# `@typescript-eslint/rule-schema-to-typescript-types` + + + +> Converts ESLint rule schemas to equivalent TypeScript type strings ✨ + +```ts +import { schemaToTypes } from '@typescript-eslint/rule-schema-to-typescript-types'; + +// " +// type Options = [ +// /** My great option! */ +// string[] +// ]; +// " +schemaToTypes({ + description: 'My great option!', + items: { type: 'string' }, + type: 'array', +}); +``` + +The following documentation is auto-generated from source code. + + diff --git a/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot b/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot b/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot b/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot b/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot b/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-array-delete.shot b/packages/eslint-plugin/tests/schema-snapshots/no-array-delete.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-array-delete.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-array-delete.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot b/packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot b/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot b/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot b/packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot b/packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot b/packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot b/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot b/packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot b/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot b/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot b/packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-parameter-property-assignment.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-parameter-property-assignment.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-parameter-property-assignment.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-parameter-property-assignment.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-template-expression.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-template-expression.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-template-expression.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-template-expression.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-conversion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-conversion.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-conversion.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-conversion.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-parameters.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-parameters.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-parameters.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-parameters.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-function-type.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-function-type.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-function-type.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-function-type.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-type-assertion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-type-assertion.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-type-assertion.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-type-assertion.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-unary-minus.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-unary-minus.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-unary-minus.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-unary-minus.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot b/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot b/packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-wrapper-object-types.shot b/packages/eslint-plugin/tests/schema-snapshots/no-wrapper-object-types.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/no-wrapper-object-types.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/no-wrapper-object-types.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot b/packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-find.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-find.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-find.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-find.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/related-getter-setter-pairs.shot b/packages/eslint-plugin/tests/schema-snapshots/related-getter-setter-pairs.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/related-getter-setter-pairs.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/related-getter-setter-pairs.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/require-await.shot b/packages/eslint-plugin/tests/schema-snapshots/require-await.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/require-await.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/require-await.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schema-snapshots/use-unknown-in-catch-callback-variable.shot b/packages/eslint-plugin/tests/schema-snapshots/use-unknown-in-catch-callback-variable.shot index 42f81875ed94..cdd9f8375858 100644 --- a/packages/eslint-plugin/tests/schema-snapshots/use-unknown-in-catch-callback-variable.shot +++ b/packages/eslint-plugin/tests/schema-snapshots/use-unknown-in-catch-callback-variable.shot @@ -7,4 +7,4 @@ # TYPES: /** No options declared */ -type Options = []; \ No newline at end of file +type Options = []; diff --git a/packages/eslint-plugin/tests/schemas.test.ts b/packages/eslint-plugin/tests/schemas.test.ts index 14380218c9e8..4d4e5c9b2ac3 100644 --- a/packages/eslint-plugin/tests/schemas.test.ts +++ b/packages/eslint-plugin/tests/schemas.test.ts @@ -1,4 +1,4 @@ -import { compile } from '@typescript-eslint/rule-schema-to-typescript-types'; +import { schemaToTypes } from '@typescript-eslint/rule-schema-to-typescript-types'; import * as fs from 'node:fs/promises'; import * as path from 'node:path'; import prettier from 'prettier'; @@ -41,7 +41,7 @@ const ruleEntries = Object.entries(rules); describe('Rule schemas should be convertible to TS types for documentation purposes', async () => { const PRETTIER_CONFIG = { schema: await getPrettierConfig(SCHEMA_FILEPATH), - tsType: getPrettierConfig(TS_TYPE_FILEPATH), + tsType: await getPrettierConfig(TS_TYPE_FILEPATH), }; beforeAll(async () => { @@ -83,8 +83,8 @@ describe('Rule schemas should be convertible to TS types for documentation purpo ), PRETTIER_CONFIG.schema, ); - const compilationResult = await compile( - ruleDef.meta.schema, + const compilationResult = await prettier.format( + schemaToTypes(ruleDef.meta.schema), PRETTIER_CONFIG.tsType, ); diff --git a/packages/rule-schema-to-typescript-types/package.json b/packages/rule-schema-to-typescript-types/package.json index 8eee73cef414..8f403ca2aaea 100644 --- a/packages/rule-schema-to-typescript-types/package.json +++ b/packages/rule-schema-to-typescript-types/package.json @@ -1,7 +1,7 @@ { "name": "@typescript-eslint/rule-schema-to-typescript-types", "version": "8.44.1", - "private": true, + "description": "Converts ESLint rule schemas to equivalent TypeScript type strings.", "type": "commonjs", "exports": { ".": { @@ -34,8 +34,7 @@ "dependencies": { "@typescript-eslint/type-utils": "8.44.1", "@typescript-eslint/utils": "8.44.1", - "natural-compare": "^1.4.0", - "prettier": "3.6.2" + "natural-compare": "^1.4.0" }, "devDependencies": { "@vitest/coverage-v8": "^3.1.3", @@ -48,6 +47,9 @@ "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, + "publishConfig": { + "access": "public" + }, "nx": { "name": "rule-schema-to-typescript-types", "includedScripts": [ diff --git a/packages/rule-schema-to-typescript-types/src/generateArrayType.ts b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts index 54c1499f8a6c..975c0e4ccf0d 100644 --- a/packages/rule-schema-to-typescript-types/src/generateArrayType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts @@ -5,7 +5,7 @@ import type { import { TSUtils } from '@typescript-eslint/utils'; -import type { ArrayAST, AST, RefMap, TupleAST, UnionAST } from './types'; +import type { ArrayAST, SchemaAST, RefMap, TupleAST, UnionAST } from './types'; import { NotSupportedError, UnexpectedError } from './errors'; import { generateType } from './generateType'; @@ -95,7 +95,7 @@ export function generateArrayType( const b: B = ['a', undefined, 'c'] // TS error */ const cumulativeTypesList = itemTypes.slice(0, minItems); - const typesToUnion: AST[] = []; + const typesToUnion: SchemaAST[] = []; if (cumulativeTypesList.length > 0) { // actually has minItems, so add the initial state typesToUnion.push(createTupleType(cumulativeTypesList)); @@ -131,8 +131,8 @@ export function generateArrayType( } function createTupleType( - elements: AST[], - spreadType: AST | null = null, + elements: SchemaAST[], + spreadType: SchemaAST | null = null, ): TupleAST { return { type: 'tuple', diff --git a/packages/rule-schema-to-typescript-types/src/generateObjectType.ts b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts index 61a88a4f1e8c..d5bffdd54865 100644 --- a/packages/rule-schema-to-typescript-types/src/generateObjectType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts @@ -3,7 +3,7 @@ import type { JSONSchema4ObjectSchema } from '@typescript-eslint/utils/json-sche import { requiresQuoting } from '@typescript-eslint/type-utils'; import { TSUtils } from '@typescript-eslint/utils'; -import type { AST, ObjectAST, RefMap } from './types'; +import type { SchemaAST, ObjectAST, RefMap } from './types'; import { generateType } from './generateType'; import { getCommentLines } from './getCommentLines'; @@ -14,7 +14,7 @@ export function generateObjectType( ): ObjectAST { const commentLines = getCommentLines(schema); - let indexSignature: AST | null = null; + let indexSignature: SchemaAST | null = null; if ( schema.additionalProperties === true || // eslint-disable-next-line @typescript-eslint/internal/eqeq-nullish diff --git a/packages/rule-schema-to-typescript-types/src/generateType.ts b/packages/rule-schema-to-typescript-types/src/generateType.ts index 00d4e0d6e9c0..23e8e2e0560b 100644 --- a/packages/rule-schema-to-typescript-types/src/generateType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateType.ts @@ -2,7 +2,7 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import { TSUtils } from '@typescript-eslint/utils'; -import type { AST, RefMap } from './types'; +import type { SchemaAST, RefMap } from './types'; import { NotSupportedError, UnexpectedError } from './errors'; import { generateArrayType } from './generateArrayType'; @@ -22,7 +22,7 @@ const UNSUPPORTED_KEYWORDS = new Set([ 'patternProperties', ]); -export function generateType(schema: JSONSchema4, refMap: RefMap): AST { +export function generateType(schema: JSONSchema4, refMap: RefMap): SchemaAST { const unsupportedProps = Object.keys(schema).filter(key => UNSUPPORTED_KEYWORDS.has(key), ); diff --git a/packages/rule-schema-to-typescript-types/src/generateUnionType.ts b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts index ced5d9bf63aa..18759476e6d8 100644 --- a/packages/rule-schema-to-typescript-types/src/generateUnionType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts @@ -3,7 +3,7 @@ import type { JSONSchema4Type, } from '@typescript-eslint/utils/json-schema'; -import type { AST, RefMap, UnionAST } from './types'; +import type { SchemaAST, RefMap, UnionAST } from './types'; import { NotSupportedError } from './errors'; import { generateType } from './generateType'; @@ -12,11 +12,11 @@ export function generateUnionType( members: (JSONSchema4 | JSONSchema4Type)[], refMap: RefMap, ): UnionAST { - const elements: AST[] = []; + const elements: SchemaAST[] = []; for (const memberSchema of members) { elements.push( - ((): AST => { + ((): SchemaAST => { switch (typeof memberSchema) { case 'string': return { diff --git a/packages/rule-schema-to-typescript-types/src/index.ts b/packages/rule-schema-to-typescript-types/src/index.ts index e046d9ced2c6..f81efa88c3ba 100644 --- a/packages/rule-schema-to-typescript-types/src/index.ts +++ b/packages/rule-schema-to-typescript-types/src/index.ts @@ -1,39 +1,34 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import { TSUtils } from '@typescript-eslint/utils'; -import prettier from 'prettier'; -import type { AST } from './types'; +import type { SchemaAST } from './types'; import { generateType } from './generateType'; import { optimizeAST } from './optimizeAST'; import { printTypeAlias } from './printAST'; -export async function compile( - schemaIn: JSONSchema4 | readonly JSONSchema4[], - prettierConfig: Promise, -): Promise { - const { isArraySchema, schema } = (() => { - if (TSUtils.isArray(schemaIn)) { - return { - isArraySchema: true, - schema: schemaIn, - }; - } - return { - isArraySchema: false, - schema: [schemaIn], - }; - })(); +/** + * Converts rule options schema(s) to the equivalent TypeScript type string. + * + * @param schema Original rule schema(s) as declared in `meta.schema`. + * @returns Stringified TypeScript type(s) equivalent to the options schema(s). + */ +export function schemaToTypes( + schema: JSONSchema4 | readonly JSONSchema4[], +): string { + const [isArraySchema, schemaNormalized] = TSUtils.isArray(schema) + ? [true, schema] + : [false, [schema]]; - if (schema.length === 0) { + if (schemaNormalized.length === 0) { return ['/** No options declared */', 'type Options = [];'].join('\n'); } const refTypes: string[] = []; - const types: AST[] = []; - for (let i = 0; i < schema.length; i += 1) { - const result = compileSchema(schema[i], i); + const types: SchemaAST[] = []; + for (let i = 0; i < schemaNormalized.length; i += 1) { + const result = compileSchema(schemaNormalized[i], i); refTypes.push(...result.refTypes); types.push(result.type); } @@ -47,21 +42,13 @@ export async function compile( }) : printTypeAlias('Options', types[0]); - const unformattedCode = [...refTypes, optionsType].join('\n\n'); - try { - return await prettier.format(unformattedCode, await prettierConfig); - } catch (e) { - if (e instanceof Error) { - e.message += `\n\nUnformatted Code:\n${unformattedCode}`; - } - throw e; - } + return [...refTypes, optionsType].join('\n\n'); } function compileSchema( schema: JSONSchema4, index: number, -): { refTypes: string[]; type: AST } { +): { refTypes: string[]; type: SchemaAST } { const refTypes: string[] = []; const refMap = new Map(); diff --git a/packages/rule-schema-to-typescript-types/src/optimizeAST.ts b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts index 14a0fd1c778a..42a188f62391 100644 --- a/packages/rule-schema-to-typescript-types/src/optimizeAST.ts +++ b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts @@ -1,6 +1,6 @@ -import type { AST, UnionAST } from './types'; +import type { SchemaAST, UnionAST } from './types'; -export function optimizeAST(ast: AST | null): void { +export function optimizeAST(ast: SchemaAST | null): void { if (ast == null) { return; } @@ -40,7 +40,7 @@ export function optimizeAST(ast: AST | null): void { } // hacky way to deduplicate union members - const uniqueElementsMap = new Map(); + const uniqueElementsMap = new Map(); for (const element of elements) { uniqueElementsMap.set(JSON.stringify(element), element); } @@ -53,8 +53,8 @@ export function optimizeAST(ast: AST | null): void { } } -function unwrapUnions(union: UnionAST): AST[] { - const elements: AST[] = []; +function unwrapUnions(union: UnionAST): SchemaAST[] { + const elements: SchemaAST[] = []; for (const element of union.elements) { if (element.type === 'union') { elements.push(...unwrapUnions(element)); diff --git a/packages/rule-schema-to-typescript-types/src/printAST.ts b/packages/rule-schema-to-typescript-types/src/printAST.ts index 746d0b850b0c..2d3e86519527 100644 --- a/packages/rule-schema-to-typescript-types/src/printAST.ts +++ b/packages/rule-schema-to-typescript-types/src/printAST.ts @@ -1,12 +1,12 @@ import naturalCompare from 'natural-compare'; -import type { AST, TupleAST } from './types'; +import type { SchemaAST, TupleAST } from './types'; -export function printTypeAlias(aliasName: string, ast: AST): string { +export function printTypeAlias(aliasName: string, ast: SchemaAST): string { return `${printComment(ast)}type ${aliasName} = ${printAST(ast).code}`; } -export function printASTWithComment(ast: AST): string { +export function printASTWithComment(ast: SchemaAST): string { const result = printAST(ast); return `${printComment(result)}${result.code}`; } @@ -36,7 +36,7 @@ interface CodeWithComments { code: string; commentLines: string[]; } -function printAST(ast: AST): CodeWithComments { +function printAST(ast: SchemaAST): CodeWithComments { switch (ast.type) { case 'array': { const code = printAndMaybeParenthesise(ast.elementType); @@ -124,7 +124,7 @@ function printAST(ast: AST): CodeWithComments { interface Element { code: string; - element: AST; + element: SchemaAST; } function compareElements(a: Element, b: Element): number { if (a.element.type !== b.element.type) { @@ -153,7 +153,7 @@ function compareElements(a: Element, b: Element): number { } } -function printAndMaybeParenthesise(ast: AST): CodeWithComments { +function printAndMaybeParenthesise(ast: SchemaAST): CodeWithComments { const printed = printAST(ast); if (ast.type === 'union') { return { diff --git a/packages/rule-schema-to-typescript-types/src/types.ts b/packages/rule-schema-to-typescript-types/src/types.ts index 9edcbf0b404c..e2026a4e8917 100644 --- a/packages/rule-schema-to-typescript-types/src/types.ts +++ b/packages/rule-schema-to-typescript-types/src/types.ts @@ -1,3 +1,6 @@ +/** + * Maps ref paths to generated type names. + */ export type RefMap = ReadonlyMap< // ref path string, @@ -5,7 +8,10 @@ export type RefMap = ReadonlyMap< string >; -export type AST = +/** + * Minimal representation of the nodes in a schema being compiled to types. + */ +export type SchemaAST = | ArrayAST | LiteralAST | ObjectAST @@ -13,37 +19,37 @@ export type AST = | TypeReferenceAST | UnionAST; -interface BaseASTNode { +export interface BaseSchemaASTNode { readonly commentLines: string[]; } -export interface ArrayAST extends BaseASTNode { - readonly elementType: AST; +export interface ArrayAST extends BaseSchemaASTNode { + readonly elementType: SchemaAST; readonly type: 'array'; } -export interface LiteralAST extends BaseASTNode { +export interface LiteralAST extends BaseSchemaASTNode { readonly code: string; readonly type: 'literal'; } -export interface ObjectAST extends BaseASTNode { - readonly indexSignature: AST | null; +export interface ObjectAST extends BaseSchemaASTNode { + readonly indexSignature: SchemaAST | null; readonly properties: { readonly name: string; readonly optional: boolean; - readonly type: AST; + readonly type: SchemaAST; }[]; readonly type: 'object'; } -export interface TupleAST extends BaseASTNode { - readonly elements: AST[]; - readonly spreadType: AST | null; +export interface TupleAST extends BaseSchemaASTNode { + readonly elements: SchemaAST[]; + readonly spreadType: SchemaAST | null; readonly type: 'tuple'; } -export interface TypeReferenceAST extends BaseASTNode { +export interface TypeReferenceAST extends BaseSchemaASTNode { readonly type: 'type-reference'; readonly typeName: string; } -export interface UnionAST extends BaseASTNode { - readonly elements: AST[]; +export interface UnionAST extends BaseSchemaASTNode { + readonly elements: SchemaAST[]; readonly type: 'union'; } diff --git a/packages/rule-schema-to-typescript-types/tests/index.test.ts b/packages/rule-schema-to-typescript-types/tests/index.test.ts new file mode 100644 index 000000000000..5bd48e1bf347 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/tests/index.test.ts @@ -0,0 +1,134 @@ +import { schemaToTypes } from '../src/index'; + +describe(schemaToTypes, () => { + it('returns a [] type when the schema is an empty array', () => { + const actual = schemaToTypes([]); + + expect(actual).toMatchInlineSnapshot(` + "/** No options declared */ + type Options = [];" + `); + }); + + it('returns a single Options type when the schema is not an array', () => { + const actual = schemaToTypes({ type: 'string' }); + + expect(actual).toMatchInlineSnapshot(`"type Options = string"`); + }); + + it('returns an array Options type when the schema is an array', () => { + const actual = schemaToTypes([{ type: 'string' }]); + + expect(actual).toMatchInlineSnapshot(`"type Options = [string]"`); + }); + + it('returns a complex Options type when the schema is nested', () => { + const actual = schemaToTypes([ + { + description: 'My schema items.', + items: { type: 'string' }, + type: 'array', + }, + ]); + + expect(actual).toMatchInlineSnapshot(` + "type Options = [/** My schema items. */ + string[]]" + `); + }); + + it('factors in one $ref property when a $defs property exists at the top level', () => { + const actual = schemaToTypes([ + { + $defs: { + defOption: { + enum: ['a', 'b'], + type: 'string', + }, + }, + additionalProperties: false, + properties: { + one: { + $ref: '#/items/0/$defs/defOption', + }, + }, + type: 'object', + }, + ]); + + expect(actual).toMatchInlineSnapshot(` + "type DefOption = | 'a' + | 'b' + + type Options = [{ + one?: DefOption}]" + `); + }); + + it('factors in one $ref property when a definitions property exists at the top level', () => { + const actual = schemaToTypes([ + { + additionalProperties: false, + definitions: { + defOption: { + enum: ['a', 'b'], + type: 'string', + }, + }, + properties: { + one: { + $ref: '#/items/0/$defs/defOption', + }, + }, + type: 'object', + }, + ]); + + expect(actual).toMatchInlineSnapshot(` + "type DefOption = | 'a' + | 'b' + + type Options = [{ + one?: DefOption}]" + `); + }); + + it('factors in two $ref properties when two $defs properties exist at the top level', () => { + const actual = schemaToTypes([ + { + $defs: { + defOptionOne: { + enum: ['a', 'b'], + type: 'string', + }, + defOptionTwo: { + enum: ['c', 'd'], + type: 'string', + }, + }, + additionalProperties: false, + properties: { + one: { + $ref: '#/items/0/$defs/defOptionOne', + }, + two: { + $ref: '#/items/0/$defs/defOptionTwo', + }, + }, + type: 'object', + }, + ]); + + expect(actual).toMatchInlineSnapshot(` + "type DefOptionOne = | 'a' + | 'b' + + type DefOptionTwo = | 'c' + | 'd' + + type Options = [{ + one?: DefOptionOne; + two?: DefOptionTwo}]" + `); + }); +}); diff --git a/packages/website/docusaurus.config.mts b/packages/website/docusaurus.config.mts index 3e6ff8e252f4..9a51ea074f54 100644 --- a/packages/website/docusaurus.config.mts +++ b/packages/website/docusaurus.config.mts @@ -368,32 +368,34 @@ const config: Config = { organizationName: 'typescript-eslint', plugins: [ './plugins/recent-blog-posts/index.ts', - ...['ast-spec', 'project-service', 'tsconfig-utils', 'type-utils'].map( - packageName => [ - 'docusaurus-plugin-typedoc', - { - entryPoints: [`../${packageName}/src/index.ts`], - enumMembersFormat: 'table', - exclude: '**/*.d.ts', - excludeExternals: true, - groupOrder: ['Functions', 'Variables', '*'], - hidePageTitle: true, - id: `typedoc-generated-${packageName}`, - indexFormat: 'table', - out: `../../docs/packages/${packageName}/generated`, - outputFileStrategy: 'modules', - parametersFormat: 'table', - plugin: [ - require.resolve('./tools/typedoc-plugin-no-inherit-fork.mjs'), - ], - propertiesFormat: 'table', - readme: 'none', - tsconfig: `../${packageName}/tsconfig.json`, - typeDeclarationFormat: 'table', - useCodeBlocks: true, - }, - ], - ), + ...[ + 'ast-spec', + 'project-service', + 'rule-schema-to-typescript-types', + 'tsconfig-utils', + 'type-utils', + ].map(packageName => [ + 'docusaurus-plugin-typedoc', + { + entryPoints: [`../${packageName}/src/index.ts`], + enumMembersFormat: 'table', + exclude: '**/*.d.ts', + excludeExternals: true, + groupOrder: ['Functions', 'Variables', '*'], + hidePageTitle: true, + id: `typedoc-generated-${packageName}`, + indexFormat: 'table', + out: `../../docs/packages/${packageName}/generated`, + outputFileStrategy: 'modules', + parametersFormat: 'table', + plugin: [require.resolve('./tools/typedoc-plugin-no-inherit-fork.mjs')], + propertiesFormat: 'table', + readme: 'none', + tsconfig: `../${packageName}/tsconfig.json`, + typeDeclarationFormat: 'table', + useCodeBlocks: true, + }, + ]), require.resolve('./webpack.plugin'), ['@docusaurus/plugin-content-docs', pluginContentDocsOptions], ['@docusaurus/plugin-pwa', pluginPwaOptions], diff --git a/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts b/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts index 89230d62a2fb..2154ca000f61 100644 --- a/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts +++ b/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts @@ -2,7 +2,7 @@ import type { ESLintPluginDocs } from '@typescript-eslint/eslint-plugin/use-at-y import type * as mdast from 'mdast'; import type { MdxJsxFlowElement } from 'mdast-util-mdx'; -import { compile } from '@typescript-eslint/rule-schema-to-typescript-types'; +import { schemaToTypes } from '@typescript-eslint/rule-schema-to-typescript-types'; import { EOL } from 'node:os'; import * as path from 'node:path'; import prettier from 'prettier'; @@ -32,7 +32,7 @@ const PRETTIER_CONFIG_PATH = path.resolve( '..', '.prettierrc.json', ); -const prettierConfig = (async () => { +const lazyPrettierConfig = (async () => { const filepath = path.join(__dirname, 'file.ts'); const config = await prettier.resolveConfig(filepath, { config: PRETTIER_CONFIG_PATH, @@ -149,6 +149,7 @@ export async function insertNewRuleReferences( 'This rule is not configurable.', ); } else if (!COMPLICATED_RULE_OPTIONS.has(page.file.stem)) { + const prettierConfig = await lazyPrettierConfig; page.spliceChildren( page.headingIndices.options + 1, 0, @@ -159,11 +160,11 @@ export async function insertNewRuleReferences( lang: 'ts', type: 'code', value: [ - await compile(page.rule.meta.schema, prettierConfig), await prettier.format( - getRuleDefaultOptions(page), - await prettierConfig, + schemaToTypes(page.rule.meta.schema), + prettierConfig, ), + await prettier.format(getRuleDefaultOptions(page), prettierConfig), ] .join(EOL) .trim(), diff --git a/packages/website/sidebars/sidebar.base.js b/packages/website/sidebars/sidebar.base.js index 689a5bb14202..a6d6e196d9e0 100644 --- a/packages/website/sidebars/sidebar.base.js +++ b/packages/website/sidebars/sidebar.base.js @@ -104,6 +104,7 @@ module.exports = { 'packages/eslint-plugin-tslint', 'packages/parser', 'packages/project-service', + 'packages/rule-schema-to-typescript-types', 'packages/rule-tester', 'packages/scope-manager', 'packages/tsconfig-utils', diff --git a/yarn.lock b/yarn.lock index de33b432a111..f32a2be226ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5934,7 +5934,6 @@ __metadata: "@vitest/coverage-v8": ^3.1.3 eslint: "*" natural-compare: ^1.4.0 - prettier: 3.6.2 rimraf: "*" typescript: "*" vitest: ^3.1.3 From 8e4c15763aa5eb9d2eaf7f01aa7db994e2420f08 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 26 Sep 2025 09:07:44 -0400 Subject: [PATCH 2/6] pr-title-validation.yml scopes --- .github/workflows/pr-title-validation.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-title-validation.yml b/.github/workflows/pr-title-validation.yml index 175ce9457a5e..a2a5e5e47a8a 100644 --- a/.github/workflows/pr-title-validation.yml +++ b/.github/workflows/pr-title-validation.yml @@ -39,6 +39,7 @@ jobs: eslint-plugin-internal parser project-service + rule-schema-to-typescript-types rule-tester scope-manager tsconfig-utils From 113367a76ddf02bf6726690f544fadaed1b52795 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 26 Sep 2025 18:43:08 -0400 Subject: [PATCH 3/6] add to issue templates --- .github/ISSUE_TEMPLATE/06-bug-report-other.yaml | 1 + .github/ISSUE_TEMPLATE/07-enhancement-other.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/06-bug-report-other.yaml b/.github/ISSUE_TEMPLATE/06-bug-report-other.yaml index 69fc7d6ef7d7..d1d8b6fc4225 100644 --- a/.github/ISSUE_TEMPLATE/06-bug-report-other.yaml +++ b/.github/ISSUE_TEMPLATE/06-bug-report-other.yaml @@ -41,6 +41,7 @@ body: - eslint-plugin - parser - project-service + - rule-schema-to-typescript-types - rule-tester - scope-manager - tsconfig-utils diff --git a/.github/ISSUE_TEMPLATE/07-enhancement-other.yaml b/.github/ISSUE_TEMPLATE/07-enhancement-other.yaml index 7250ea66e0f3..de9f9324e4c0 100644 --- a/.github/ISSUE_TEMPLATE/07-enhancement-other.yaml +++ b/.github/ISSUE_TEMPLATE/07-enhancement-other.yaml @@ -27,6 +27,7 @@ body: - eslint-plugin - parser - project-service + - rule-schema-to-typescript-types - rule-tester - scope-manager - tsconfig-utils From 5377634bf93db0cd42cc1b50425ada0d52434d17 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 26 Sep 2025 18:43:44 -0400 Subject: [PATCH 4/6] add test --- .../tests/index.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/rule-schema-to-typescript-types/tests/index.test.ts b/packages/rule-schema-to-typescript-types/tests/index.test.ts index 5bd48e1bf347..62a7406ac677 100644 --- a/packages/rule-schema-to-typescript-types/tests/index.test.ts +++ b/packages/rule-schema-to-typescript-types/tests/index.test.ts @@ -22,6 +22,20 @@ describe(schemaToTypes, () => { expect(actual).toMatchInlineSnapshot(`"type Options = [string]"`); }); + it('returns a complex Options type when the schema contains an array of items', () => { + const actual = schemaToTypes([ + { + type: 'array', + items: [{ type: 'string' }], + }, + ]); + + expect(actual).toMatchInlineSnapshot(` + "type Options = [ | [] + | [string]]" + `); + }); + it('returns a complex Options type when the schema is nested', () => { const actual = schemaToTypes([ { From a0a1f71c0a50897009b07be4af9367dd31fd4c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Mon, 29 Sep 2025 07:50:33 -0400 Subject: [PATCH 5/6] Update packages/rule-schema-to-typescript-types/tests/index.test.ts Co-authored-by: Francesco Trotta --- packages/rule-schema-to-typescript-types/tests/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rule-schema-to-typescript-types/tests/index.test.ts b/packages/rule-schema-to-typescript-types/tests/index.test.ts index 62a7406ac677..23ec245f829c 100644 --- a/packages/rule-schema-to-typescript-types/tests/index.test.ts +++ b/packages/rule-schema-to-typescript-types/tests/index.test.ts @@ -25,8 +25,8 @@ describe(schemaToTypes, () => { it('returns a complex Options type when the schema contains an array of items', () => { const actual = schemaToTypes([ { - type: 'array', items: [{ type: 'string' }], + type: 'array', }, ]); From 0d45932be8323360b66929c2387ab6416358f45c Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 30 Sep 2025 09:46:09 -0400 Subject: [PATCH 6/6] Switch to module --- .../rule-schema-to-typescript-types/package.json | 2 +- .../src/generateArrayType.ts | 16 +++++++++++----- .../src/generateObjectType.ts | 6 +++--- .../src/generateType.ts | 12 ++++++------ .../src/generateUnionType.ts | 6 +++--- .../rule-schema-to-typescript-types/src/index.ts | 8 ++++---- .../src/optimizeAST.ts | 2 +- .../src/printAST.ts | 2 +- .../tests/index.test.ts | 2 +- 9 files changed, 31 insertions(+), 25 deletions(-) diff --git a/packages/rule-schema-to-typescript-types/package.json b/packages/rule-schema-to-typescript-types/package.json index 8f403ca2aaea..05534c45b5f1 100644 --- a/packages/rule-schema-to-typescript-types/package.json +++ b/packages/rule-schema-to-typescript-types/package.json @@ -2,7 +2,7 @@ "name": "@typescript-eslint/rule-schema-to-typescript-types", "version": "8.44.1", "description": "Converts ESLint rule schemas to equivalent TypeScript type strings.", - "type": "commonjs", + "type": "module", "exports": { ".": { "types": "./index.d.ts", diff --git a/packages/rule-schema-to-typescript-types/src/generateArrayType.ts b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts index 975c0e4ccf0d..e86e51f72dce 100644 --- a/packages/rule-schema-to-typescript-types/src/generateArrayType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts @@ -5,11 +5,17 @@ import type { import { TSUtils } from '@typescript-eslint/utils'; -import type { ArrayAST, SchemaAST, RefMap, TupleAST, UnionAST } from './types'; - -import { NotSupportedError, UnexpectedError } from './errors'; -import { generateType } from './generateType'; -import { getCommentLines } from './getCommentLines'; +import type { + ArrayAST, + SchemaAST, + RefMap, + TupleAST, + UnionAST, +} from './types.js'; + +import { NotSupportedError, UnexpectedError } from './errors.js'; +import { generateType } from './generateType.js'; +import { getCommentLines } from './getCommentLines.js'; /** * If there are more than 20 tuple items then we will not make it a tuple type diff --git a/packages/rule-schema-to-typescript-types/src/generateObjectType.ts b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts index d5bffdd54865..1d2592f62aff 100644 --- a/packages/rule-schema-to-typescript-types/src/generateObjectType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts @@ -3,10 +3,10 @@ import type { JSONSchema4ObjectSchema } from '@typescript-eslint/utils/json-sche import { requiresQuoting } from '@typescript-eslint/type-utils'; import { TSUtils } from '@typescript-eslint/utils'; -import type { SchemaAST, ObjectAST, RefMap } from './types'; +import type { SchemaAST, ObjectAST, RefMap } from './types.js'; -import { generateType } from './generateType'; -import { getCommentLines } from './getCommentLines'; +import { generateType } from './generateType.js'; +import { getCommentLines } from './getCommentLines.js'; export function generateObjectType( schema: JSONSchema4ObjectSchema, diff --git a/packages/rule-schema-to-typescript-types/src/generateType.ts b/packages/rule-schema-to-typescript-types/src/generateType.ts index 23e8e2e0560b..f5ef138ce3a0 100644 --- a/packages/rule-schema-to-typescript-types/src/generateType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateType.ts @@ -2,13 +2,13 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import { TSUtils } from '@typescript-eslint/utils'; -import type { SchemaAST, RefMap } from './types'; +import type { SchemaAST, RefMap } from './types.js'; -import { NotSupportedError, UnexpectedError } from './errors'; -import { generateArrayType } from './generateArrayType'; -import { generateObjectType } from './generateObjectType'; -import { generateUnionType } from './generateUnionType'; -import { getCommentLines } from './getCommentLines'; +import { NotSupportedError, UnexpectedError } from './errors.js'; +import { generateArrayType } from './generateArrayType.js'; +import { generateObjectType } from './generateObjectType.js'; +import { generateUnionType } from './generateUnionType.js'; +import { getCommentLines } from './getCommentLines.js'; // keywords we probably should support but currently do not support const UNSUPPORTED_KEYWORDS = new Set([ diff --git a/packages/rule-schema-to-typescript-types/src/generateUnionType.ts b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts index 18759476e6d8..6370abf3a8e1 100644 --- a/packages/rule-schema-to-typescript-types/src/generateUnionType.ts +++ b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts @@ -3,10 +3,10 @@ import type { JSONSchema4Type, } from '@typescript-eslint/utils/json-schema'; -import type { SchemaAST, RefMap, UnionAST } from './types'; +import type { SchemaAST, RefMap, UnionAST } from './types.js'; -import { NotSupportedError } from './errors'; -import { generateType } from './generateType'; +import { NotSupportedError } from './errors.js'; +import { generateType } from './generateType.js'; export function generateUnionType( members: (JSONSchema4 | JSONSchema4Type)[], diff --git a/packages/rule-schema-to-typescript-types/src/index.ts b/packages/rule-schema-to-typescript-types/src/index.ts index f81efa88c3ba..d61da632a371 100644 --- a/packages/rule-schema-to-typescript-types/src/index.ts +++ b/packages/rule-schema-to-typescript-types/src/index.ts @@ -2,11 +2,11 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import { TSUtils } from '@typescript-eslint/utils'; -import type { SchemaAST } from './types'; +import type { SchemaAST } from './types.js'; -import { generateType } from './generateType'; -import { optimizeAST } from './optimizeAST'; -import { printTypeAlias } from './printAST'; +import { generateType } from './generateType.js'; +import { optimizeAST } from './optimizeAST.js'; +import { printTypeAlias } from './printAST.js'; /** * Converts rule options schema(s) to the equivalent TypeScript type string. diff --git a/packages/rule-schema-to-typescript-types/src/optimizeAST.ts b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts index 42a188f62391..0ec3626a46cd 100644 --- a/packages/rule-schema-to-typescript-types/src/optimizeAST.ts +++ b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts @@ -1,4 +1,4 @@ -import type { SchemaAST, UnionAST } from './types'; +import type { SchemaAST, UnionAST } from './types.js'; export function optimizeAST(ast: SchemaAST | null): void { if (ast == null) { diff --git a/packages/rule-schema-to-typescript-types/src/printAST.ts b/packages/rule-schema-to-typescript-types/src/printAST.ts index 2d3e86519527..a618b903a5d0 100644 --- a/packages/rule-schema-to-typescript-types/src/printAST.ts +++ b/packages/rule-schema-to-typescript-types/src/printAST.ts @@ -1,6 +1,6 @@ import naturalCompare from 'natural-compare'; -import type { SchemaAST, TupleAST } from './types'; +import type { SchemaAST, TupleAST } from './types.js'; export function printTypeAlias(aliasName: string, ast: SchemaAST): string { return `${printComment(ast)}type ${aliasName} = ${printAST(ast).code}`; diff --git a/packages/rule-schema-to-typescript-types/tests/index.test.ts b/packages/rule-schema-to-typescript-types/tests/index.test.ts index 23ec245f829c..49db40f209f7 100644 --- a/packages/rule-schema-to-typescript-types/tests/index.test.ts +++ b/packages/rule-schema-to-typescript-types/tests/index.test.ts @@ -1,4 +1,4 @@ -import { schemaToTypes } from '../src/index'; +import { schemaToTypes } from '../src/index.js'; describe(schemaToTypes, () => { it('returns a [] type when the schema is an empty array', () => {