From acc1a43e02a403ff74a54c28c2c495f00d0be038 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Thu, 20 Apr 2023 11:27:07 +0930 Subject: [PATCH] feat: improve rule schemas, add test to validate schemas, add tooling to generate schema types (#6899) --- .github/workflows/ci.yml | 1 + docs/linting/Troubleshooting.mdx | 36 + package.json | 1 + packages/eslint-plugin/package.json | 4 +- .../eslint-plugin/src/rules/array-type.ts | 39 +- .../eslint-plugin/src/rules/ban-ts-comment.ts | 66 +- packages/eslint-plugin/src/rules/ban-types.ts | 69 +- .../rules/explicit-member-accessibility.ts | 89 +- .../src/rules/lines-around-comment.ts | 159 +- .../src/rules/lines-between-class-members.ts | 23 +- .../src/rules/member-delimiter-style.ts | 68 +- .../src/rules/member-ordering.ts | 120 +- .../rules/naming-convention-utils/schema.ts | 78 +- .../src/rules/no-restricted-imports.ts | 115 +- .../eslint-plugin/src/rules/no-type-alias.ts | 37 +- .../rules/padding-line-between-statements.ts | 3 +- .../src/rules/parameter-properties.ts | 57 +- .../src/rules/prefer-readonly.ts | 2 +- .../src/rules/type-annotation-spacing.ts | 31 +- .../tests/rules/ban-types.test.ts | 21 + .../adjacent-overload-signatures.shot | 14 + .../tests/schema-snapshots/array-type.shot | 42 + .../schema-snapshots/await-thenable.shot | 14 + .../schema-snapshots/ban-ts-comment.shot | 73 + .../schema-snapshots/ban-tslint-comment.shot | 14 + .../tests/schema-snapshots/ban-types.shot | 101 + .../tests/schema-snapshots/block-spacing.shot | 18 + .../tests/schema-snapshots/brace-style.shot | 33 + .../class-literal-property-style.shot | 18 + .../tests/schema-snapshots/comma-dangle.shot | 93 + .../tests/schema-snapshots/comma-spacing.shot | 34 + .../consistent-generic-constructors.shot | 18 + .../consistent-indexed-object-style.shot | 18 + .../consistent-type-assertions.shot | 50 + .../consistent-type-definitions.shot | 18 + .../consistent-type-exports.shot | 28 + .../consistent-type-imports.shot | 36 + .../schema-snapshots/default-param-last.shot | 14 + .../tests/schema-snapshots/dot-notation.shot | 49 + .../explicit-function-return-type.shot | 75 + .../explicit-member-accessibility.shot | 89 + .../explicit-module-boundary-types.shot | 63 + .../schema-snapshots/func-call-spacing.shot | 55 + .../schema-snapshots/init-declarations.shot | 55 + .../tests/schema-snapshots/key-spacing.shot | 228 ++ .../schema-snapshots/keyword-spacing.shot | 1146 ++++++++++ .../lines-around-comment.shot | 118 + .../lines-between-class-members.shot | 38 + .../member-delimiter-style.shot | 129 ++ .../schema-snapshots/member-ordering.shot | 495 ++++ .../method-signature-style.shot | 18 + .../schema-snapshots/naming-convention.shot | 1992 +++++++++++++++++ .../no-array-constructor.shot | 14 + .../schema-snapshots/no-base-to-string.shot | 31 + .../no-confusing-non-null-assertion.shot | 14 + .../no-confusing-void-expression.shot | 32 + .../no-dupe-class-members.shot | 14 + .../no-duplicate-enum-values.shot | 14 + .../no-duplicate-type-constituents.shot | 32 + .../schema-snapshots/no-dynamic-delete.shot | 14 + .../schema-snapshots/no-empty-function.shot | 62 + .../schema-snapshots/no-empty-interface.shot | 28 + .../schema-snapshots/no-explicit-any.shot | 36 + .../no-extra-non-null-assertion.shot | 14 + .../schema-snapshots/no-extra-parens.shot | 87 + .../tests/schema-snapshots/no-extra-semi.shot | 14 + .../schema-snapshots/no-extraneous-class.shot | 48 + .../no-floating-promises.shot | 36 + .../schema-snapshots/no-for-in-array.shot | 14 + .../schema-snapshots/no-implied-eval.shot | 14 + .../no-import-type-side-effects.shot | 14 + .../schema-snapshots/no-inferrable-types.shot | 32 + .../schema-snapshots/no-invalid-this.shot | 29 + .../no-invalid-void-type.shot | 43 + .../tests/schema-snapshots/no-loop-func.shot | 14 + .../no-loss-of-precision.shot | 14 + .../schema-snapshots/no-magic-numbers.shot | 81 + .../no-meaningless-void-operator.shot | 29 + .../schema-snapshots/no-misused-new.shot | 14 + .../schema-snapshots/no-misused-promises.shot | 68 + .../schema-snapshots/no-mixed-enums.shot | 14 + .../tests/schema-snapshots/no-namespace.shot | 36 + ...-non-null-asserted-nullish-coalescing.shot | 14 + .../no-non-null-asserted-optional-chain.shot | 14 + .../no-non-null-assertion.shot | 14 + .../tests/schema-snapshots/no-redeclare.shot | 32 + .../no-redundant-type-constituents.shot | 14 + .../schema-snapshots/no-require-imports.shot | 14 + .../no-restricted-imports.shot | 183 ++ .../tests/schema-snapshots/no-shadow.shot | 51 + .../tests/schema-snapshots/no-this-alias.shot | 39 + .../schema-snapshots/no-throw-literal.shot | 32 + .../tests/schema-snapshots/no-type-alias.shot | 95 + ...o-unnecessary-boolean-literal-compare.shot | 36 + .../no-unnecessary-condition.shot | 36 + .../no-unnecessary-qualifier.shot | 14 + .../no-unnecessary-type-arguments.shot | 14 + .../no-unnecessary-type-assertion.shot | 32 + .../no-unnecessary-type-constraint.shot | 14 + .../schema-snapshots/no-unsafe-argument.shot | 14 + .../no-unsafe-assignment.shot | 14 + .../schema-snapshots/no-unsafe-call.shot | 14 + .../no-unsafe-declaration-merging.shot | 14 + .../no-unsafe-enum-comparison.shot | 14 + .../no-unsafe-member-access.shot | 14 + .../schema-snapshots/no-unsafe-return.shot | 14 + .../no-unused-expressions.shot | 44 + .../schema-snapshots/no-unused-vars.shot | 65 + .../no-use-before-define.shot | 60 + .../no-useless-constructor.shot | 14 + .../no-useless-empty-export.shot | 14 + .../schema-snapshots/no-var-requires.shot | 14 + .../non-nullable-type-assertion-style.shot | 14 + .../object-curly-spacing.shot | 36 + .../padding-line-between-statements.shot | 270 +++ .../parameter-properties.shot | 58 + .../schema-snapshots/prefer-as-const.shot | 14 + .../prefer-enum-initializers.shot | 14 + .../tests/schema-snapshots/prefer-for-of.shot | 14 + .../prefer-function-type.shot | 14 + .../schema-snapshots/prefer-includes.shot | 14 + .../prefer-literal-enum-member.shot | 28 + .../prefer-namespace-keyword.shot | 14 + .../prefer-nullish-coalescing.shot | 40 + .../prefer-optional-chain.shot | 14 + .../prefer-readonly-parameter-types.shot | 147 ++ .../schema-snapshots/prefer-readonly.shot | 28 + .../prefer-reduce-type-parameter.shot | 14 + .../schema-snapshots/prefer-regexp-exec.shot | 14 + .../prefer-return-this-type.shot | 14 + .../prefer-string-starts-ends-with.shot | 14 + .../prefer-ts-expect-error.shot | 14 + .../promise-function-async.shot | 55 + .../tests/schema-snapshots/quotes.shot | 46 + .../require-array-sort-compare.shot | 29 + .../tests/schema-snapshots/require-await.shot | 14 + .../restrict-plus-operands.shot | 36 + .../restrict-template-expressions.shot | 59 + .../tests/schema-snapshots/return-await.shot | 18 + .../tests/schema-snapshots/semi.shot | 70 + .../sort-type-constituents.shot | 71 + .../schema-snapshots/space-before-blocks.shot | 45 + .../space-before-function-paren.shot | 45 + .../schema-snapshots/space-infix-ops.shot | 29 + .../strict-boolean-expressions.shot | 60 + .../switch-exhaustiveness-check.shot | 14 + .../triple-slash-reference.shot | 36 + .../type-annotation-spacing.shot | 83 + .../tests/schema-snapshots/typedef.shot | 55 + .../schema-snapshots/unbound-method.shot | 30 + .../schema-snapshots/unified-signatures.shot | 30 + packages/eslint-plugin/tests/schemas.test.ts | 155 ++ packages/eslint-plugin/tsconfig.json | 1 + packages/repo-tools/package.json | 1 + packages/repo-tools/tsconfig.build.json | 6 +- packages/repo-tools/tsconfig.json | 2 +- .../rule-schema-to-typescript-types/README.md | 9 + .../jest.config.js | 8 + .../package.json | 48 + .../project.json | 18 + .../src/errors.ts | 17 + .../src/generateArrayType.ts | 153 ++ .../src/generateObjectType.ts | 50 + .../src/generateType.ts | 124 + .../src/generateUnionType.ts | 53 + .../src/getCommentLines.ts | 9 + .../src/index.ts | 98 + .../src/isArray.ts | 4 + .../src/optimizeAST.ts | 72 + .../src/printAST.ts | 168 ++ .../src/types.ts | 49 + .../tsconfig.build.json | 11 + .../tsconfig.json | 9 + .../type-utils/src/TypeOrValueSpecifier.ts | 9 +- packages/type-utils/src/isTypeReadonly.ts | 3 +- packages/website/package.json | 2 +- .../website/plugins/generated-rule-docs.ts | 74 +- .../website/src/components/lib/jsonSchema.ts | 27 +- .../src/components/linter/createLinter.ts | 2 +- patches/@types+json-schema+7.0.11.patch | 35 + yarn.lock | 224 +- 181 files changed, 10410 insertions(+), 713 deletions(-) create mode 100644 packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/array-type.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/ban-ts-comment.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/ban-types.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/block-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/brace-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/class-literal-property-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/comma-dangle.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/comma-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-generic-constructors.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-indexed-object-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-type-assertions.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-type-definitions.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-type-exports.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/consistent-type-imports.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/dot-notation.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/explicit-function-return-type.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/explicit-member-accessibility.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/explicit-module-boundary-types.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/func-call-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/init-declarations.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/key-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/keyword-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/lines-around-comment.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/lines-between-class-members.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/member-delimiter-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/member-ordering.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/method-signature-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/naming-convention.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-base-to-string.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-confusing-void-expression.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-duplicate-type-constituents.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-empty-function.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-empty-interface.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-explicit-any.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-extra-parens.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-extra-semi.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-extraneous-class.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-floating-promises.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-inferrable-types.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-invalid-this.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-invalid-void-type.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-magic-numbers.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-meaningless-void-operator.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-misused-promises.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-namespace.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-redeclare.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-require-imports.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-restricted-imports.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-shadow.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-this-alias.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-throw-literal.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-type-alias.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-boolean-literal-compare.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-condition.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-assertion.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unused-expressions.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-unused-vars.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-use-before-define.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/no-var-requires.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/object-curly-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/padding-line-between-statements.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/parameter-properties.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-literal-enum-member.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-nullish-coalescing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-optional-chain.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-readonly-parameter-types.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-readonly.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-string-starts-ends-with.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/promise-function-async.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/quotes.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/require-array-sort-compare.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/require-await.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/restrict-plus-operands.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/restrict-template-expressions.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/return-await.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/semi.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/sort-type-constituents.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/space-before-blocks.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/space-before-function-paren.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/space-infix-ops.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/strict-boolean-expressions.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/switch-exhaustiveness-check.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/triple-slash-reference.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/type-annotation-spacing.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/typedef.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/unbound-method.shot create mode 100644 packages/eslint-plugin/tests/schema-snapshots/unified-signatures.shot create mode 100644 packages/eslint-plugin/tests/schemas.test.ts create mode 100644 packages/rule-schema-to-typescript-types/README.md create mode 100644 packages/rule-schema-to-typescript-types/jest.config.js create mode 100644 packages/rule-schema-to-typescript-types/package.json create mode 100644 packages/rule-schema-to-typescript-types/project.json create mode 100644 packages/rule-schema-to-typescript-types/src/errors.ts create mode 100644 packages/rule-schema-to-typescript-types/src/generateArrayType.ts create mode 100644 packages/rule-schema-to-typescript-types/src/generateObjectType.ts create mode 100644 packages/rule-schema-to-typescript-types/src/generateType.ts create mode 100644 packages/rule-schema-to-typescript-types/src/generateUnionType.ts create mode 100644 packages/rule-schema-to-typescript-types/src/getCommentLines.ts create mode 100644 packages/rule-schema-to-typescript-types/src/index.ts create mode 100644 packages/rule-schema-to-typescript-types/src/isArray.ts create mode 100644 packages/rule-schema-to-typescript-types/src/optimizeAST.ts create mode 100644 packages/rule-schema-to-typescript-types/src/printAST.ts create mode 100644 packages/rule-schema-to-typescript-types/src/types.ts create mode 100644 packages/rule-schema-to-typescript-types/tsconfig.build.json create mode 100644 packages/rule-schema-to-typescript-types/tsconfig.json create mode 100644 patches/@types+json-schema+7.0.11.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6536fe37b7a..b5bebd18b49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -145,6 +145,7 @@ jobs: 'eslint-plugin-tslint', 'parser', 'repo-tools', + 'rule-schema-to-typescript-types', 'scope-manager', 'type-utils', 'typescript-estree', diff --git a/docs/linting/Troubleshooting.mdx b/docs/linting/Troubleshooting.mdx index 56179707d73..0754416c615 100644 --- a/docs/linting/Troubleshooting.mdx +++ b/docs/linting/Troubleshooting.mdx @@ -71,6 +71,42 @@ See our docs on [type aware linting](./Typed_Linting.mdx) for more information. You're using an outdated version of `@typescript-eslint/parser`. Update to the latest version to see a more informative version of this error message, explained [above](#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file 'backlink to I get errors telling me ESLint was configured to run ...'). +## How do I turn on a `@typescript-eslint` rule? + +First make sure you've read the docs and understand ESLint configuration files: + +- [Read our getting started guide](../Getting_Started.mdx) to ensure your config is properly setup to start configuring our rules. +- [Checkout ESLint's documentation on configuring rules](https://eslint.org/docs/latest/use/configure/rules) to ensure you understand how to configure rules. + +Our [rule docs](/rules) detail the options each rule supports under the "Options" heading. +We use TypeScript types to describe an `Options` tuple type for the rule which you can use to configure the a rule. +In your config file the keys of the `rules` object are the names of the rules you wish to configure and the values follow the following form: + +```ts +type Severity = 'off' | 'warn' | 'error'; +type RuleConfig = + | Severity + | [Severity] + | [ + Severiy, + // Options is the tuple type from the rule docs + ...Options, + ]; +``` + +Some examples + +```js title=".eslintrc.js" +module.exports = { + rules: { + // turns a rule on with no configuration (i.e. uses the default configuration) + '@typescript-eslint/array-type': 'error', + // turns on a rule with configuration + '@typescript-eslint/no-explicit-any': ['warn', { ignoreRestArgs: true }], + }, +}; +``` + ## I use a framework (like Vue) that requires custom file extensions, and I get errors like "You should add `parserOptions.extraFileExtensions` to your config" You can use `parserOptions.extraFileExtensions` to specify an array of non-TypeScript extensions to allow, for example: diff --git a/package.json b/package.json index 59cfdbed493..9ae7ddbd1e9 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "@types/jest": "^29.0.2", "@types/jest-specific-snapshot": "^0.5.5", "@types/marked": "^4.0.3", + "@types/natural-compare": "^1.4.0", "@types/node": "^18.11.9", "@types/prettier": "^2.6.0", "@types/rimraf": "^3.0.2", diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 2730031fd1e..3b0e219f74f 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -69,9 +69,11 @@ "@types/debug": "*", "@types/json-schema": "*", "@types/marked": "*", - "@types/natural-compare": "^1.4.0", + "@types/natural-compare": "*", "@types/prettier": "*", + "@typescript-eslint/rule-schema-to-typescript-types": "5.59.0", "cross-fetch": "*", + "jest-specific-snapshot": "*", "json-schema": "*", "markdown-table": "^3.0.2", "marked": "^4.0.15", diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index f30aebae1ef..e6e78b6e0f4 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -105,30 +105,27 @@ export default util.createRule({ errorStringGenericSimple: "Array type using '{{readonlyPrefix}}{{type}}[]' is forbidden for non-simple types. Use '{{className}}<{{type}}>' instead.", }, - schema: { - $defs: { - arrayOption: { - enum: ['array', 'generic', 'array-simple'], + schema: [ + { + $defs: { + arrayOption: { + enum: ['array', 'generic', 'array-simple'], + }, }, - }, - prefixItems: [ - { - properties: { - default: { - $ref: '#/$defs/arrayOption', - description: 'The array type expected for mutable cases...', - }, - readonly: { - $ref: '#/$defs/arrayOption', - description: - 'The array type expected for readonly cases. If omitted, the value for `default` will be used.', - }, + properties: { + default: { + $ref: '#/items/0/$defs/arrayOption', + description: 'The array type expected for mutable cases.', + }, + readonly: { + $ref: '#/items/0/$defs/arrayOption', + description: + 'The array type expected for readonly cases. If omitted, the value for `default` will be used.', }, - type: 'object', }, - ], - type: 'array', - }, + type: 'object', + }, + ], }, defaultOptions: [ { diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 818c23968eb..2c2e6885505 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -39,45 +39,41 @@ export default util.createRule<[Options], MessageIds>({ tsDirectiveCommentDescriptionNotMatchPattern: 'The description for the "@ts-{{directive}}" directive must match the {{format}} format.', }, - schema: { - $defs: { - directiveConfigSchema: { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - { - type: 'object', - properties: { - descriptionFormat: { type: 'string' }, + schema: [ + { + $defs: { + directiveConfigSchema: { + oneOf: [ + { + type: 'boolean', + default: true, }, - }, - ], + { + enum: ['allow-with-description'], + }, + { + type: 'object', + properties: { + descriptionFormat: { type: 'string' }, + }, + }, + ], + }, }, - }, - prefixItems: [ - { - properties: { - 'ts-expect-error': { - $ref: '#/$defs/directiveConfigSchema', - }, - 'ts-ignore': { $ref: '#/$defs/directiveConfigSchema' }, - 'ts-nocheck': { $ref: '#/$defs/directiveConfigSchema' }, - 'ts-check': { $ref: '#/$defs/directiveConfigSchema' }, - minimumDescriptionLength: { - type: 'number', - default: defaultMinimumDescriptionLength, - }, + properties: { + 'ts-expect-error': { $ref: '#/items/0/$defs/directiveConfigSchema' }, + 'ts-ignore': { $ref: '#/items/0/$defs/directiveConfigSchema' }, + 'ts-nocheck': { $ref: '#/items/0/$defs/directiveConfigSchema' }, + 'ts-check': { $ref: '#/items/0/$defs/directiveConfigSchema' }, + minimumDescriptionLength: { + type: 'number', + default: defaultMinimumDescriptionLength, }, - additionalProperties: false, }, - ], - type: 'array', - }, + type: 'object', + additionalProperties: false, + }, + ], }, defaultOptions: [ { diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 9259b0c1382..688164c5f6c 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -6,7 +6,7 @@ import * as util from '../util'; type Types = Record< string, | null - | false + | boolean | string | { message: string; @@ -35,9 +35,9 @@ function stringifyNode( } function getCustomMessage( - bannedType: null | string | { message?: string; fixWith?: string }, + bannedType: null | true | string | { message?: string; fixWith?: string }, ): string { - if (bannedType == null) { + if (bannedType == null || bannedType === true) { return ''; } @@ -140,28 +140,57 @@ export default util.createRule({ }, schema: [ { + $defs: { + banConfig: { + oneOf: [ + { + type: 'null', + description: 'Bans the type with the default message', + }, + { + enum: [false], + description: + 'Un-bans the type (useful when paired with `extendDefaults`)', + }, + { + enum: [true], + description: 'Bans the type with the default message', + }, + { + type: 'string', + description: 'Bans the type with a custom message', + }, + { + type: 'object', + description: 'Bans a type', + properties: { + message: { + type: 'string', + description: 'Custom error message', + }, + fixWith: { + type: 'string', + description: + 'Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.', + }, + suggest: { + type: 'array', + items: { type: 'string' }, + description: 'Types to suggest replacing with.', + additionalItems: false, + }, + }, + additionalProperties: false, + }, + ], + }, + }, type: 'object', properties: { types: { type: 'object', additionalProperties: { - oneOf: [ - { type: 'null' }, - { type: 'boolean' }, - { type: 'string' }, - { - type: 'object', - properties: { - message: { type: 'string' }, - fixWith: { type: 'string' }, - suggest: { - type: 'array', - items: { type: 'string' }, - }, - }, - additionalProperties: false, - }, - ], + $ref: '#/items/0/$defs/banConfig', }, }, extendDefaults: { diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index efaece677b1..71a85b4e701 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -27,23 +27,6 @@ type MessageIds = | 'missingAccessibility' | 'addExplicitAccessibility'; -const accessibilityLevel = { - oneOf: [ - { - const: 'explicit', - description: 'Always require an accessor.', - }, - { - const: 'no-public', - description: 'Require an accessor except when public.', - }, - { - const: 'off', - description: 'Never check whether there is an accessor.', - }, - ], -}; - export default util.createRule({ name: 'explicit-member-accessibility', meta: { @@ -62,41 +45,53 @@ export default util.createRule({ 'Public accessibility modifier on {{type}} {{name}}.', addExplicitAccessibility: "Add '{{ type }}' accessibility modifier", }, - schema: { - $defs: { - accessibilityLevel, - }, - prefixItems: [ - { - type: 'object', - properties: { - accessibility: { $ref: '#/$defs/accessibilityLevel' }, - overrides: { - type: 'object', - properties: { - accessors: { $ref: '#/$defs/accessibilityLevel' }, - constructors: { $ref: '#/$defs/accessibilityLevel' }, - methods: { $ref: '#/$defs/accessibilityLevel' }, - properties: { $ref: '#/$defs/accessibilityLevel' }, - parameterProperties: { - $ref: '#/$defs/accessibilityLevel', - }, + schema: [ + { + $defs: { + accessibilityLevel: { + oneOf: [ + { + enum: ['explicit'], + description: 'Always require an accessor.', }, - - additionalProperties: false, - }, - ignoredMethodNames: { - type: 'array', - items: { - type: 'string', + { + enum: ['no-public'], + description: 'Require an accessor except when public.', + }, + { + enum: ['off'], + description: 'Never check whether there is an accessor.', }, + ], + }, + }, + type: 'object', + properties: { + accessibility: { $ref: '#/items/0/$defs/accessibilityLevel' }, + overrides: { + type: 'object', + properties: { + accessors: { $ref: '#/items/0/$defs/accessibilityLevel' }, + constructors: { $ref: '#/items/0/$defs/accessibilityLevel' }, + methods: { $ref: '#/items/0/$defs/accessibilityLevel' }, + properties: { $ref: '#/items/0/$defs/accessibilityLevel' }, + parameterProperties: { + $ref: '#/items/0/$defs/accessibilityLevel', + }, + }, + + additionalProperties: false, + }, + ignoredMethodNames: { + type: 'array', + items: { + type: 'string', }, }, - additionalProperties: false, }, - ], - type: 'array', - }, + additionalProperties: false, + }, + ], }, defaultOptions: [{ accessibility: 'explicit' }], create(context, [option]) { diff --git a/packages/eslint-plugin/src/rules/lines-around-comment.ts b/packages/eslint-plugin/src/rules/lines-around-comment.ts index fa09177865f..f7cdef33b2e 100644 --- a/packages/eslint-plugin/src/rules/lines-around-comment.ts +++ b/packages/eslint-plugin/src/rules/lines-around-comment.ts @@ -50,89 +50,86 @@ export default util.createRule({ description: 'Require empty lines around comments', extendsBaseRule: true, }, - schema: { - type: 'array', - items: [ - { - type: 'object', - properties: { - beforeBlockComment: { - type: 'boolean', - default: true, - }, - afterBlockComment: { - type: 'boolean', - default: false, - }, - beforeLineComment: { - type: 'boolean', - default: false, - }, - afterLineComment: { - type: 'boolean', - default: false, - }, - allowBlockStart: { - type: 'boolean', - default: false, - }, - allowBlockEnd: { - type: 'boolean', - default: false, - }, - allowClassStart: { - type: 'boolean', - }, - allowClassEnd: { - type: 'boolean', - }, - allowObjectStart: { - type: 'boolean', - }, - allowObjectEnd: { - type: 'boolean', - }, - allowArrayStart: { - type: 'boolean', - }, - allowArrayEnd: { - type: 'boolean', - }, - allowInterfaceStart: { - type: 'boolean', - }, - allowInterfaceEnd: { - type: 'boolean', - }, - allowTypeStart: { - type: 'boolean', - }, - allowTypeEnd: { - type: 'boolean', - }, - allowEnumStart: { - type: 'boolean', - }, - allowEnumEnd: { - type: 'boolean', - }, - allowModuleStart: { - type: 'boolean', - }, - allowModuleEnd: { - type: 'boolean', - }, - ignorePattern: { - type: 'string', - }, - applyDefaultIgnorePatterns: { - type: 'boolean', - }, + schema: [ + { + type: 'object', + properties: { + beforeBlockComment: { + type: 'boolean', + default: true, + }, + afterBlockComment: { + type: 'boolean', + default: false, + }, + beforeLineComment: { + type: 'boolean', + default: false, + }, + afterLineComment: { + type: 'boolean', + default: false, + }, + allowBlockStart: { + type: 'boolean', + default: false, + }, + allowBlockEnd: { + type: 'boolean', + default: false, + }, + allowClassStart: { + type: 'boolean', + }, + allowClassEnd: { + type: 'boolean', + }, + allowObjectStart: { + type: 'boolean', + }, + allowObjectEnd: { + type: 'boolean', + }, + allowArrayStart: { + type: 'boolean', + }, + allowArrayEnd: { + type: 'boolean', + }, + allowInterfaceStart: { + type: 'boolean', + }, + allowInterfaceEnd: { + type: 'boolean', + }, + allowTypeStart: { + type: 'boolean', + }, + allowTypeEnd: { + type: 'boolean', + }, + allowEnumStart: { + type: 'boolean', + }, + allowEnumEnd: { + type: 'boolean', + }, + allowModuleStart: { + type: 'boolean', + }, + allowModuleEnd: { + type: 'boolean', + }, + ignorePattern: { + type: 'string', + }, + applyDefaultIgnorePatterns: { + type: 'boolean', }, - additionalProperties: false, }, - ], - }, + additionalProperties: false, + }, + ], fixable: baseRule.meta.fixable, hasSuggestions: baseRule.meta.hasSuggestions, messages: baseRule.meta.messages, diff --git a/packages/eslint-plugin/src/rules/lines-between-class-members.ts b/packages/eslint-plugin/src/rules/lines-between-class-members.ts index 6a8cd735862..e88e42d477a 100644 --- a/packages/eslint-plugin/src/rules/lines-between-class-members.ts +++ b/packages/eslint-plugin/src/rules/lines-between-class-members.ts @@ -1,5 +1,6 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import * as util from '../util'; import { getESLintCoreRule } from '../util/getESLintCoreRule'; @@ -9,17 +10,21 @@ const baseRule = getESLintCoreRule('lines-between-class-members'); type Options = util.InferOptionsTypeFromRule; type MessageIds = util.InferMessageIdsTypeFromRule; -const schema = util.deepMerge( - { ...baseRule.meta.schema }, - { - 1: { - exceptAfterOverload: { - type: 'boolean', - default: true, +const schema = Object.values( + util.deepMerge( + { ...baseRule.meta.schema }, + { + 1: { + properties: { + exceptAfterOverload: { + type: 'boolean', + default: true, + }, + }, }, }, - }, -); + ), +) as JSONSchema4[]; export default util.createRule({ name: 'lines-between-class-members', diff --git a/packages/eslint-plugin/src/rules/member-delimiter-style.ts b/packages/eslint-plugin/src/rules/member-delimiter-style.ts index 62fe1cd9079..fb14ad32910 100644 --- a/packages/eslint-plugin/src/rules/member-delimiter-style.ts +++ b/packages/eslint-plugin/src/rules/member-delimiter-style.ts @@ -1,5 +1,6 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import * as util from '../util'; @@ -47,30 +48,6 @@ type MakeFixFunctionReturnType = | ((fixer: TSESLint.RuleFixer) => TSESLint.RuleFix) | null; -const definition = { - type: 'object', - properties: { - multiline: { - type: 'object', - properties: { - delimiter: { enum: ['none', 'semi', 'comma'] }, - requireLast: { type: 'boolean' }, - }, - additionalProperties: false, - }, - singleline: { - type: 'object', - properties: { - // note can't have "none" for single line delimiter as it's invalid syntax - delimiter: { enum: ['semi', 'comma'] }, - requireLast: { type: 'boolean' }, - }, - additionalProperties: false, - }, - }, - additionalProperties: false, -}; - const isLastTokenEndOfLine = (token: LastTokenType, line: string): boolean => { const positionInLine = token.loc.start.column; @@ -132,6 +109,29 @@ const makeFixFunction = ({ }; }; +const BASE_SCHEMA: JSONSchema4 = { + type: 'object', + properties: { + multiline: { + type: 'object', + properties: { + delimiter: { $ref: '#/items/0/$defs/multiLineOption' }, + requireLast: { type: 'boolean' }, + }, + additionalProperties: false, + }, + singleline: { + type: 'object', + properties: { + delimiter: { $ref: '#/items/0/$defs/singleLineOption' }, + requireLast: { type: 'boolean' }, + }, + additionalProperties: false, + }, + }, + additionalProperties: false, +}; + export default util.createRule({ name: 'member-delimiter-style', meta: { @@ -149,20 +149,32 @@ export default util.createRule({ }, schema: [ { + $defs: { + multiLineOption: { enum: ['none', 'semi', 'comma'] }, + // note can't have "none" for single line delimiter as it's invalid syntax + singleLineOption: { enum: ['semi', 'comma'] }, + // note - need to define this last as it references the enums + delimiterConfig: BASE_SCHEMA, + }, type: 'object', - properties: Object.assign({}, definition.properties, { + properties: { + ...BASE_SCHEMA.properties, overrides: { type: 'object', properties: { - interface: definition, - typeLiteral: definition, + interface: { + $ref: '#/items/0/$defs/delimiterConfig', + }, + typeLiteral: { + $ref: '#/items/0/$defs/delimiterConfig', + }, }, additionalProperties: false, }, multilineDetection: { enum: ['brackets', 'last-member'], }, - }), + }, additionalProperties: false, }, ], diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index 122d32a0080..97a5bd24c8d 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -85,42 +85,34 @@ const neverConfig: JSONSchema.JSONSchema4 = { enum: ['never'], }; -const arrayConfig = (memberTypes: MemberType[]): JSONSchema.JSONSchema4 => ({ +const arrayConfig = (memberTypes: string): JSONSchema.JSONSchema4 => ({ type: 'array', items: { oneOf: [ { - enum: memberTypes, + $ref: memberTypes, }, { type: 'array', items: { - enum: memberTypes, + $ref: memberTypes, }, }, ], }, }); -const objectConfig = (memberTypes: MemberType[]): JSONSchema.JSONSchema4 => ({ +const objectConfig = (memberTypes: string): JSONSchema.JSONSchema4 => ({ type: 'object', properties: { memberTypes: { oneOf: [arrayConfig(memberTypes), neverConfig], }, order: { - type: 'string', - enum: [ - 'alphabetically', - 'alphabetically-case-insensitive', - 'as-written', - 'natural', - 'natural-case-insensitive', - ], + $ref: '#/items/0/$defs/orderOptions', }, optionalityOrder: { - type: 'string', - enum: ['optional-first', 'required-first'], + $ref: '#/items/0/$defs/optionalityOrderOptions', }, }, additionalProperties: false, @@ -635,70 +627,68 @@ export default util.createRule({ }, schema: [ { - type: 'object', - properties: { - default: { - oneOf: [ - neverConfig, - arrayConfig(allMemberTypes), - objectConfig(allMemberTypes), + $defs: { + orderOptions: { + type: 'string', + enum: [ + 'alphabetically', + 'alphabetically-case-insensitive', + 'as-written', + 'natural', + 'natural-case-insensitive', ], }, - classes: { - oneOf: [ - neverConfig, - arrayConfig(allMemberTypes), - objectConfig(allMemberTypes), + optionalityOrderOptions: { + type: 'string', + enum: ['optional-first', 'required-first'], + }, + allItems: { + type: 'string', + enum: allMemberTypes, + }, + typeItems: { + type: 'string', + enum: [ + 'readonly-signature', + 'signature', + 'readonly-field', + 'field', + 'method', + 'constructor', ], }, - classExpressions: { + + baseConfig: { oneOf: [ neverConfig, - arrayConfig(allMemberTypes), - objectConfig(allMemberTypes), + arrayConfig('#/items/0/$defs/allItems'), + objectConfig('#/items/0/$defs/allItems'), ], }, - interfaces: { + typesConfig: { oneOf: [ neverConfig, - arrayConfig([ - 'readonly-signature', - 'signature', - 'readonly-field', - 'field', - 'method', - 'constructor', - ]), - objectConfig([ - 'readonly-signature', - 'signature', - 'readonly-field', - 'field', - 'method', - 'constructor', - ]), + arrayConfig('#/items/0/$defs/typeItems'), + objectConfig('#/items/0/$defs/typeItems'), ], }, + }, + type: 'object', + properties: { + default: { + $ref: '#/items/0/$defs/baseConfig', + }, + classes: { + $ref: '#/items/0/$defs/baseConfig', + }, + classExpressions: { + $ref: '#/items/0/$defs/baseConfig', + }, + interfaces: { + $ref: '#/items/0/$defs/typesConfig', + }, typeLiterals: { - oneOf: [ - neverConfig, - arrayConfig([ - 'readonly-signature', - 'signature', - 'readonly-field', - 'field', - 'method', - 'constructor', - ]), - objectConfig([ - 'readonly-signature', - 'signature', - 'readonly-field', - 'field', - 'method', - 'constructor', - ]), - ], + $ref: '#/items/0/$defs/typesConfig', }, }, additionalProperties: false, diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/schema.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/schema.ts index ff91d2e156d..0d092ea871d 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/schema.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/schema.ts @@ -14,35 +14,44 @@ import { UnderscoreOptions, } from './enums'; -const UNDERSCORE_SCHEMA: JSONSchema.JSONSchema4 = { - type: 'string', - enum: util.getEnumNames(UnderscoreOptions), -}; -const PREFIX_SUFFIX_SCHEMA: JSONSchema.JSONSchema4 = { - type: 'array', - items: { +const $DEFS: Record = { + // enums + underscoreOptions: { type: 'string', - minLength: 1, + enum: util.getEnumNames(UnderscoreOptions), }, - additionalItems: false, -}; -const MATCH_REGEX_SCHEMA: JSONSchema.JSONSchema4 = { - type: 'object', - properties: { - match: { type: 'boolean' }, - regex: { type: 'string' }, + predefinedFormats: { + type: 'string', + enum: util.getEnumNames(PredefinedFormats), }, - required: ['match', 'regex'], -}; -type JSONSchemaProperties = Record; -const FORMAT_OPTIONS_PROPERTIES: JSONSchemaProperties = { - format: { + typeModifiers: { + type: 'string', + enum: util.getEnumNames(TypeModifiers), + }, + + // repeated types + prefixSuffixConfig: { + type: 'array', + items: { + type: 'string', + minLength: 1, + }, + additionalItems: false, + }, + matchRegexConfig: { + type: 'object', + properties: { + match: { type: 'boolean' }, + regex: { type: 'string' }, + }, + required: ['match', 'regex'], + }, + formatOptionsConfig: { oneOf: [ { type: 'array', items: { - type: 'string', - enum: util.getEnumNames(PredefinedFormats), + $ref: '#/$defs/predefinedFormats', }, additionalItems: false, }, @@ -51,6 +60,22 @@ const FORMAT_OPTIONS_PROPERTIES: JSONSchemaProperties = { }, ], }, +}; + +const UNDERSCORE_SCHEMA: JSONSchema.JSONSchema4 = { + $ref: '#/$defs/underscoreOptions', +}; +const PREFIX_SUFFIX_SCHEMA: JSONSchema.JSONSchema4 = { + $ref: '#/$defs/prefixSuffixConfig', +}; +const MATCH_REGEX_SCHEMA: JSONSchema.JSONSchema4 = { + $ref: '#/$defs/matchRegexConfig', +}; +type JSONSchemaProperties = Record; +const FORMAT_OPTIONS_PROPERTIES: JSONSchemaProperties = { + format: { + $ref: '#/$defs/formatOptionsConfig', + }, custom: MATCH_REGEX_SCHEMA, leadingUnderscore: UNDERSCORE_SCHEMA, trailingUnderscore: UNDERSCORE_SCHEMA, @@ -94,8 +119,7 @@ function selectorSchema( selector.types = { type: 'array', items: { - type: 'string', - enum: util.getEnumNames(TypeModifiers), + $ref: '#/$defs/typeModifiers', }, additionalItems: false, }; @@ -104,6 +128,7 @@ function selectorSchema( return [ { type: 'object', + description: `Selector '${selectorString}'`, properties: { ...FORMAT_OPTIONS_PROPERTIES, ...selector, @@ -117,6 +142,7 @@ function selectorSchema( function selectorsSchema(): JSONSchema.JSONSchema4 { return { type: 'object', + description: 'Multiple selectors in one config', properties: { ...FORMAT_OPTIONS_PROPERTIES, ...{ @@ -151,8 +177,7 @@ function selectorsSchema(): JSONSchema.JSONSchema4 { types: { type: 'array', items: { - type: 'string', - enum: util.getEnumNames(TypeModifiers), + $ref: '#/$defs/typeModifiers', }, additionalItems: false, }, @@ -164,6 +189,7 @@ function selectorsSchema(): JSONSchema.JSONSchema4 { } const SCHEMA: JSONSchema.JSONSchema4 = { + $defs: $DEFS, type: 'array', items: { oneOf: [ diff --git a/packages/eslint-plugin/src/rules/no-restricted-imports.ts b/packages/eslint-plugin/src/rules/no-restricted-imports.ts index 48bf8f55c2d..17e93f7feba 100644 --- a/packages/eslint-plugin/src/rules/no-restricted-imports.ts +++ b/packages/eslint-plugin/src/rules/no-restricted-imports.ts @@ -1,4 +1,5 @@ import type { TSESTree } from '@typescript-eslint/utils'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import type { ArrayOfStringOrObject, ArrayOfStringOrObjectPatterns, @@ -10,7 +11,7 @@ import type { InferMessageIdsTypeFromRule, InferOptionsTypeFromRule, } from '../util'; -import { createRule, deepMerge } from '../util'; +import { createRule } from '../util'; import { getESLintCoreRule } from '../util/getESLintCoreRule'; const baseRule = getESLintCoreRule('no-restricted-imports'); @@ -18,48 +19,86 @@ const baseRule = getESLintCoreRule('no-restricted-imports'); export type Options = InferOptionsTypeFromRule; export type MessageIds = InferMessageIdsTypeFromRule; -const allowTypeImportsOptionSchema = { - allowTypeImports: { - type: 'boolean', - default: false, - }, -}; -const schemaForMergeArrayOfStringsOrObjects = { +const arrayOfStringsOrObjects: JSONSchema4 = { + type: 'array', items: { anyOf: [ - {}, + { type: 'string' }, { - properties: allowTypeImportsOptionSchema, + type: 'object', + properties: { + name: { type: 'string' }, + message: { + type: 'string', + minLength: 1, + }, + importNames: { + type: 'array', + items: { + type: 'string', + }, + }, + allowTypeImports: { + type: 'boolean', + description: 'Disallow value imports, but allow type-only imports.', + }, + }, + additionalProperties: false, + required: ['name'], }, ], }, + uniqueItems: true, }; -const schemaForMergeArrayOfStringsOrObjectPatterns = { +const arrayOfStringsOrObjectPatterns: JSONSchema4 = { anyOf: [ - {}, { + type: 'array', items: { - properties: allowTypeImportsOptionSchema, + type: 'string', }, + uniqueItems: true, }, - ], -}; -const schema = deepMerge( - { ...baseRule.meta.schema }, - { - anyOf: [ - schemaForMergeArrayOfStringsOrObjects, - { - items: { - properties: { - paths: schemaForMergeArrayOfStringsOrObjects, - patterns: schemaForMergeArrayOfStringsOrObjectPatterns, + { + type: 'array', + items: { + type: 'object', + properties: { + importNames: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, + group: { + type: 'array', + items: { + type: 'string', + }, + minItems: 1, + uniqueItems: true, + }, + message: { + type: 'string', + minLength: 1, + }, + caseSensitive: { + type: 'boolean', + }, + allowTypeImports: { + type: 'boolean', + description: 'Disallow value imports, but allow type-only imports.', }, }, + additionalProperties: false, + required: ['group'], }, - ], - }, -); + uniqueItems: true, + }, + ], +}; function isObjectOfPaths( obj: unknown, @@ -114,7 +153,25 @@ export default createRule({ }, messages: baseRule.meta.messages, fixable: baseRule.meta.fixable, - schema, + schema: { + anyOf: [ + arrayOfStringsOrObjects, + { + type: 'array', + items: [ + { + type: 'object', + properties: { + paths: arrayOfStringsOrObjects, + patterns: arrayOfStringsOrObjectPatterns, + }, + additionalProperties: false, + }, + ], + additionalItems: false, + }, + ], + }, }, defaultOptions: [], create(context) { diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index 16f811dc118..7356f00fbc5 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -9,13 +9,6 @@ type Values = | 'in-unions' | 'in-intersections' | 'in-unions-and-intersections'; -const enumValues: Values[] = [ - 'always', - 'never', - 'in-unions', - 'in-intersections', - 'in-unions-and-intersections', -]; type Options = [ { @@ -55,40 +48,54 @@ export default util.createRule({ }, schema: [ { + $defs: { + expandedOptions: { + enum: [ + 'always', + 'never', + 'in-unions', + 'in-intersections', + 'in-unions-and-intersections', + ] satisfies Values[], + }, + simpleOptions: { + enum: ['always', 'never'], + }, + }, type: 'object', properties: { allowAliases: { description: 'Whether to allow direct one-to-one type aliases.', - enum: enumValues, + $ref: '#/items/0/$defs/expandedOptions', }, allowCallbacks: { description: 'Whether to allow type aliases for callbacks.', - enum: ['always', 'never'], + $ref: '#/items/0/$defs/simpleOptions', }, allowConditionalTypes: { description: 'Whether to allow type aliases for conditional types.', - enum: ['always', 'never'], + $ref: '#/items/0/$defs/simpleOptions', }, allowConstructors: { description: 'Whether to allow type aliases with constructors.', - enum: ['always', 'never'], + $ref: '#/items/0/$defs/simpleOptions', }, allowLiterals: { description: 'Whether to allow type aliases with object literal types.', - enum: enumValues, + $ref: '#/items/0/$defs/expandedOptions', }, allowMappedTypes: { description: 'Whether to allow type aliases with mapped types.', - enum: enumValues, + $ref: '#/items/0/$defs/expandedOptions', }, allowTupleTypes: { description: 'Whether to allow type aliases with tuple types.', - enum: enumValues, + $ref: '#/items/0/$defs/expandedOptions', }, allowGenerics: { description: 'Whether to allow type aliases with generic types.', - enum: ['always', 'never'], + $ref: '#/items/0/$defs/simpleOptions', }, }, additionalProperties: false, diff --git a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts index d92eb197ad1..b1e974e1b86 100644 --- a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts +++ b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts @@ -594,6 +594,7 @@ export default util.createRule({ }, fixable: 'whitespace', hasSuggestions: false, + // This is intentionally an array schema as you can pass 0..n config objects schema: { $defs: { paddingType: { @@ -613,6 +614,7 @@ export default util.createRule({ }, }, type: 'array', + additionalItems: false, items: { type: 'object', properties: { @@ -623,7 +625,6 @@ export default util.createRule({ additionalProperties: false, required: ['blankLine', 'prev', 'next'], }, - additionalItems: false, }, messages: { unexpectedBlankLine: 'Unexpected blank line before this statement.', diff --git a/packages/eslint-plugin/src/rules/parameter-properties.ts b/packages/eslint-plugin/src/rules/parameter-properties.ts index 2d75a9c7b6e..10c15b06177 100644 --- a/packages/eslint-plugin/src/rules/parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/parameter-properties.ts @@ -37,40 +37,37 @@ export default util.createRule({ preferParameterProperty: 'Property {{parameter}} should be declared as a parameter property.', }, - schema: { - $defs: { - modifier: { - enum: [ - 'readonly', - 'private', - 'protected', - 'public', - 'private readonly', - 'protected readonly', - 'public readonly', - ], + schema: [ + { + $defs: { + modifier: { + enum: [ + 'readonly', + 'private', + 'protected', + 'public', + 'private readonly', + 'protected readonly', + 'public readonly', + ], + }, }, - }, - prefixItems: [ - { - type: 'object', - properties: { - allow: { - type: 'array', - items: { - $ref: '#/$defs/modifier', - }, - minItems: 1, - }, - prefer: { - enum: ['class-property', 'parameter-property'], + type: 'object', + properties: { + allow: { + type: 'array', + items: { + $ref: '#/items/0/$defs/modifier', }, + minItems: 1, + }, + prefer: { + enum: ['class-property', 'parameter-property'], }, - additionalProperties: false, }, - ], - type: 'array', - }, + additionalProperties: false, + }, + ], }, defaultOptions: [ { diff --git a/packages/eslint-plugin/src/rules/prefer-readonly.ts b/packages/eslint-plugin/src/rules/prefer-readonly.ts index 0f83d598d29..1f177251dbc 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly.ts @@ -35,7 +35,7 @@ export default util.createRule({ }, schema: [ { - allowAdditionalProperties: false, + additionalProperties: false, properties: { onlyInlineLambdas: { type: 'boolean', diff --git a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts index 37d7b18d635..f3ad45e9dc5 100644 --- a/packages/eslint-plugin/src/rules/type-annotation-spacing.ts +++ b/packages/eslint-plugin/src/rules/type-annotation-spacing.ts @@ -39,15 +39,6 @@ type MessageIds = | 'unexpectedSpaceBefore' | 'unexpectedSpaceBetween'; -const definition = { - type: 'object', - properties: { - before: { type: 'boolean' }, - after: { type: 'boolean' }, - }, - additionalProperties: false, -}; - function createRules(options?: Config): WhitespaceRules { const globals = { ...(options?.before !== undefined ? { before: options.before } : {}), @@ -127,6 +118,16 @@ export default util.createRule({ }, schema: [ { + $defs: { + spacingConfig: { + type: 'object', + properties: { + before: { type: 'boolean' }, + after: { type: 'boolean' }, + }, + additionalProperties: false, + }, + }, type: 'object', properties: { before: { type: 'boolean' }, @@ -134,12 +135,12 @@ export default util.createRule({ overrides: { type: 'object', properties: { - colon: definition, - arrow: definition, - variable: definition, - parameter: definition, - property: definition, - returnType: definition, + colon: { $ref: '#/items/0/$defs/spacingConfig' }, + arrow: { $ref: '#/items/0/$defs/spacingConfig' }, + variable: { $ref: '#/items/0/$defs/spacingConfig' }, + parameter: { $ref: '#/items/0/$defs/spacingConfig' }, + property: { $ref: '#/items/0/$defs/spacingConfig' }, + returnType: { $ref: '#/items/0/$defs/spacingConfig' }, }, additionalProperties: false, }, diff --git a/packages/eslint-plugin/tests/rules/ban-types.test.ts b/packages/eslint-plugin/tests/rules/ban-types.test.ts index 831d17a59a1..440142c1044 100644 --- a/packages/eslint-plugin/tests/rules/ban-types.test.ts +++ b/packages/eslint-plugin/tests/rules/ban-types.test.ts @@ -657,6 +657,27 @@ let baz: object = {}; }, ], }, + { + code: 'let a: Foo;', + errors: [ + { + messageId: 'bannedTypeMessage', + data: { + name: 'Foo', + customMessage: '', + }, + line: 1, + column: 8, + }, + ], + options: [ + { + types: { + Foo: true, + }, + }, + ], + }, ...objectReduceKey( TYPE_KEYWORDS, (acc: TSESLint.InvalidTestCase[], key) => { diff --git a/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot b/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot new file mode 100644 index 00000000000..ee8e4edeee5 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/adjacent-overload-signatures.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes adjacent-overload-signatures 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/array-type.shot b/packages/eslint-plugin/tests/schema-snapshots/array-type.shot new file mode 100644 index 00000000000..da76d7036a8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/array-type.shot @@ -0,0 +1,42 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes array-type 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "arrayOption": { + "enum": ["array", "array-simple", "generic"] + } + }, + "properties": { + "default": { + "$ref": "#/items/0/$defs/arrayOption", + "description": "The array type expected for mutable cases." + }, + "readonly": { + "$ref": "#/items/0/$defs/arrayOption", + "description": "The array type expected for readonly cases. If omitted, the value for \`default\` will be used." + } + }, + "type": "object" + } +] + + +# TYPES: + +type ArrayOption = 'array' | 'array-simple' | 'generic'; + +type Options = [ + { + /** The array type expected for mutable cases. */ + default?: ArrayOption; + /** The array type expected for readonly cases. If omitted, the value for \`default\` will be used. */ + readonly?: ArrayOption; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot b/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot new file mode 100644 index 00000000000..ac87bfd93ca --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/await-thenable.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes await-thenable 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/ban-ts-comment.shot b/packages/eslint-plugin/tests/schema-snapshots/ban-ts-comment.shot new file mode 100644 index 00000000000..e754ff98ae5 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/ban-ts-comment.shot @@ -0,0 +1,73 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes ban-ts-comment 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "directiveConfigSchema": { + "oneOf": [ + { + "default": true, + "type": "boolean" + }, + { + "enum": ["allow-with-description"] + }, + { + "properties": { + "descriptionFormat": { + "type": "string" + } + }, + "type": "object" + } + ] + } + }, + "additionalProperties": false, + "properties": { + "minimumDescriptionLength": { + "default": 3, + "type": "number" + }, + "ts-check": { + "$ref": "#/items/0/$defs/directiveConfigSchema" + }, + "ts-expect-error": { + "$ref": "#/items/0/$defs/directiveConfigSchema" + }, + "ts-ignore": { + "$ref": "#/items/0/$defs/directiveConfigSchema" + }, + "ts-nocheck": { + "$ref": "#/items/0/$defs/directiveConfigSchema" + } + }, + "type": "object" + } +] + + +# TYPES: + +type DirectiveConfigSchema = + | 'allow-with-description' + | { + descriptionFormat?: string; + } + | boolean; + +type Options = [ + { + 'ts-check'?: DirectiveConfigSchema; + 'ts-expect-error'?: DirectiveConfigSchema; + 'ts-ignore'?: DirectiveConfigSchema; + 'ts-nocheck'?: DirectiveConfigSchema; + minimumDescriptionLength?: number; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot b/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot new file mode 100644 index 00000000000..2a45126d783 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/ban-tslint-comment.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes ban-tslint-comment 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/ban-types.shot b/packages/eslint-plugin/tests/schema-snapshots/ban-types.shot new file mode 100644 index 00000000000..68f35c203ee --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/ban-types.shot @@ -0,0 +1,101 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes ban-types 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "banConfig": { + "oneOf": [ + { + "description": "Bans the type with the default message", + "type": "null" + }, + { + "description": "Un-bans the type (useful when paired with \`extendDefaults\`)", + "enum": [false] + }, + { + "description": "Bans the type with the default message", + "enum": [true] + }, + { + "description": "Bans the type with a custom message", + "type": "string" + }, + { + "additionalProperties": false, + "description": "Bans a type", + "properties": { + "fixWith": { + "description": "Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option.", + "type": "string" + }, + "message": { + "description": "Custom error message", + "type": "string" + }, + "suggest": { + "additionalItems": false, + "description": "Types to suggest replacing with.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } + ] + } + }, + "additionalProperties": false, + "properties": { + "extendDefaults": { + "type": "boolean" + }, + "types": { + "additionalProperties": { + "$ref": "#/items/0/$defs/banConfig" + }, + "type": "object" + } + }, + "type": "object" + } +] + + +# TYPES: + +type BanConfig = + /** Bans a type */ + | { + /** Type to autofix replace with. Note that autofixers can be applied automatically - so you need to be careful with this option. */ + fixWith?: string; + /** Custom error message */ + message?: string; + /** Types to suggest replacing with. */ + suggest?: string[]; + } + /** Bans the type with a custom message */ + | string + /** Bans the type with the default message */ + | null + /** Bans the type with the default message */ + | true + /** Un-bans the type (useful when paired with \`extendDefaults\`) */ + | false; + +type Options = [ + { + extendDefaults?: boolean; + types?: { + [k: string]: BanConfig; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/block-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/block-spacing.shot new file mode 100644 index 00000000000..f36ea49fa82 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/block-spacing.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes block-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["always", "never"] + } +] + + +# TYPES: + +type Options = ['always' | 'never']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/brace-style.shot b/packages/eslint-plugin/tests/schema-snapshots/brace-style.shot new file mode 100644 index 00000000000..1418bafb13e --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/brace-style.shot @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes brace-style 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["1tbs", "allman", "stroustrup"] + }, + { + "additionalProperties": false, + "properties": { + "allowSingleLine": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + '1tbs' | 'allman' | 'stroustrup', + { + allowSingleLine?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/class-literal-property-style.shot b/packages/eslint-plugin/tests/schema-snapshots/class-literal-property-style.shot new file mode 100644 index 00000000000..1bf67927f61 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/class-literal-property-style.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes class-literal-property-style 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["fields", "getters"] + } +] + + +# TYPES: + +type Options = ['fields' | 'getters']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/comma-dangle.shot b/packages/eslint-plugin/tests/schema-snapshots/comma-dangle.shot new file mode 100644 index 00000000000..a5b0ca54a31 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/comma-dangle.shot @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes comma-dangle 1`] = ` +" +# SCHEMA: + +{ + "$defs": { + "value": { + "enum": ["always", "always-multiline", "never", "only-multiline"] + }, + "valueWithIgnore": { + "enum": [ + "always", + "always-multiline", + "ignore", + "never", + "only-multiline" + ] + } + }, + "additionalProperties": false, + "items": [ + { + "oneOf": [ + { + "$ref": "#/$defs/value" + }, + { + "additionalProperties": false, + "properties": { + "arrays": { + "$ref": "#/$defs/valueWithIgnore" + }, + "enums": { + "$ref": "#/$defs/valueWithIgnore" + }, + "exports": { + "$ref": "#/$defs/valueWithIgnore" + }, + "functions": { + "$ref": "#/$defs/valueWithIgnore" + }, + "generics": { + "$ref": "#/$defs/valueWithIgnore" + }, + "imports": { + "$ref": "#/$defs/valueWithIgnore" + }, + "objects": { + "$ref": "#/$defs/valueWithIgnore" + }, + "tuples": { + "$ref": "#/$defs/valueWithIgnore" + } + }, + "type": "object" + } + ] + } + ], + "type": "array" +} + + +# TYPES: + +type Value = 'always' | 'always-multiline' | 'never' | 'only-multiline'; + +type ValueWithIgnore = + | 'always' + | 'always-multiline' + | 'ignore' + | 'never' + | 'only-multiline'; + +type Options = + | [] + | [ + | { + arrays?: ValueWithIgnore; + enums?: ValueWithIgnore; + exports?: ValueWithIgnore; + functions?: ValueWithIgnore; + generics?: ValueWithIgnore; + imports?: ValueWithIgnore; + objects?: ValueWithIgnore; + tuples?: ValueWithIgnore; + } + | Value, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/comma-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/comma-spacing.shot new file mode 100644 index 00000000000..5399369fee5 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/comma-spacing.shot @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes comma-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "after": { + "default": true, + "type": "boolean" + }, + "before": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + after?: boolean; + before?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-generic-constructors.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-generic-constructors.shot new file mode 100644 index 00000000000..540eea55862 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-generic-constructors.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-generic-constructors 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["constructor", "type-annotation"] + } +] + + +# TYPES: + +type Options = ['constructor' | 'type-annotation']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-indexed-object-style.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-indexed-object-style.shot new file mode 100644 index 00000000000..5befaa24e0c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-indexed-object-style.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-indexed-object-style 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["index-signature", "record"] + } +] + + +# TYPES: + +type Options = ['index-signature' | 'record']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-type-assertions.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-assertions.shot new file mode 100644 index 00000000000..04acdfde423 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-assertions.shot @@ -0,0 +1,50 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-type-assertions 1`] = ` +" +# SCHEMA: + +[ + { + "oneOf": [ + { + "additionalProperties": false, + "properties": { + "assertionStyle": { + "enum": ["never"] + } + }, + "required": ["assertionStyle"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "assertionStyle": { + "enum": ["angle-bracket", "as"] + }, + "objectLiteralTypeAssertions": { + "enum": ["allow", "allow-as-parameter", "never"] + } + }, + "required": ["assertionStyle"], + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | { + assertionStyle: 'angle-bracket' | 'as'; + objectLiteralTypeAssertions?: 'allow' | 'allow-as-parameter' | 'never'; + } + | { + assertionStyle: 'never'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-type-definitions.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-definitions.shot new file mode 100644 index 00000000000..130f2ac3c9c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-definitions.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-type-definitions 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["interface", "type"] + } +] + + +# TYPES: + +type Options = ['interface' | 'type']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-type-exports.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-exports.shot new file mode 100644 index 00000000000..1ad2d951194 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-exports.shot @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-type-exports 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "fixMixedExportsWithInlineTypeSpecifier": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + fixMixedExportsWithInlineTypeSpecifier?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/consistent-type-imports.shot b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-imports.shot new file mode 100644 index 00000000000..4f8ad794909 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/consistent-type-imports.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes consistent-type-imports 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "disallowTypeAnnotations": { + "type": "boolean" + }, + "fixStyle": { + "enum": ["inline-type-imports", "separate-type-imports"] + }, + "prefer": { + "enum": ["no-type-imports", "type-imports"] + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + disallowTypeAnnotations?: boolean; + fixStyle?: 'inline-type-imports' | 'separate-type-imports'; + prefer?: 'no-type-imports' | 'type-imports'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot b/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot new file mode 100644 index 00000000000..dccc9316644 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/default-param-last.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes default-param-last 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/dot-notation.shot b/packages/eslint-plugin/tests/schema-snapshots/dot-notation.shot new file mode 100644 index 00000000000..73c0dcdad74 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/dot-notation.shot @@ -0,0 +1,49 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes dot-notation 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowIndexSignaturePropertyAccess": { + "default": false, + "type": "boolean" + }, + "allowKeywords": { + "default": true, + "type": "boolean" + }, + "allowPattern": { + "default": "", + "type": "string" + }, + "allowPrivateClassPropertyAccess": { + "default": false, + "type": "boolean" + }, + "allowProtectedClassPropertyAccess": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowIndexSignaturePropertyAccess?: boolean; + allowKeywords?: boolean; + allowPattern?: string; + allowPrivateClassPropertyAccess?: boolean; + allowProtectedClassPropertyAccess?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/explicit-function-return-type.shot b/packages/eslint-plugin/tests/schema-snapshots/explicit-function-return-type.shot new file mode 100644 index 00000000000..9239baf5003 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/explicit-function-return-type.shot @@ -0,0 +1,75 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes explicit-function-return-type 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowConciseArrowFunctionExpressionsStartingWithVoid": { + "description": "Whether to allow arrow functions that start with the \`void\` keyword.", + "type": "boolean" + }, + "allowDirectConstAssertionInArrowFunctions": { + "description": "Whether to ignore arrow functions immediately returning a \`as const\` value.", + "type": "boolean" + }, + "allowedNames": { + "description": "An array of function/method names that will not have their arguments or return values checked.", + "items": { + "type": "string" + }, + "type": "array" + }, + "allowExpressions": { + "description": "Whether to ignore function expressions (functions which are not part of a declaration).", + "type": "boolean" + }, + "allowFunctionsWithoutTypeParameters": { + "description": "Whether to ignore functions that don't have generic type parameters.", + "type": "boolean" + }, + "allowHigherOrderFunctions": { + "description": "Whether to ignore functions immediately returning another function expression.", + "type": "boolean" + }, + "allowIIFEs": { + "description": "Whether to ignore immediately invoked function expressions (IIFEs).", + "type": "boolean" + }, + "allowTypedFunctionExpressions": { + "description": "Whether to ignore type annotations on the variable of function expressions.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow arrow functions that start with the \`void\` keyword. */ + allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean; + /** Whether to ignore arrow functions immediately returning a \`as const\` value. */ + allowDirectConstAssertionInArrowFunctions?: boolean; + /** Whether to ignore function expressions (functions which are not part of a declaration). */ + allowExpressions?: boolean; + /** Whether to ignore functions that don't have generic type parameters. */ + allowFunctionsWithoutTypeParameters?: boolean; + /** Whether to ignore functions immediately returning another function expression. */ + allowHigherOrderFunctions?: boolean; + /** Whether to ignore immediately invoked function expressions (IIFEs). */ + allowIIFEs?: boolean; + /** Whether to ignore type annotations on the variable of function expressions. */ + allowTypedFunctionExpressions?: boolean; + /** An array of function/method names that will not have their arguments or return values checked. */ + allowedNames?: string[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/explicit-member-accessibility.shot b/packages/eslint-plugin/tests/schema-snapshots/explicit-member-accessibility.shot new file mode 100644 index 00000000000..f0a2dc9a4fb --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/explicit-member-accessibility.shot @@ -0,0 +1,89 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes explicit-member-accessibility 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "accessibilityLevel": { + "oneOf": [ + { + "description": "Always require an accessor.", + "enum": ["explicit"] + }, + { + "description": "Require an accessor except when public.", + "enum": ["no-public"] + }, + { + "description": "Never check whether there is an accessor.", + "enum": ["off"] + } + ] + } + }, + "additionalProperties": false, + "properties": { + "accessibility": { + "$ref": "#/items/0/$defs/accessibilityLevel" + }, + "ignoredMethodNames": { + "items": { + "type": "string" + }, + "type": "array" + }, + "overrides": { + "additionalProperties": false, + "properties": { + "accessors": { + "$ref": "#/items/0/$defs/accessibilityLevel" + }, + "constructors": { + "$ref": "#/items/0/$defs/accessibilityLevel" + }, + "methods": { + "$ref": "#/items/0/$defs/accessibilityLevel" + }, + "parameterProperties": { + "$ref": "#/items/0/$defs/accessibilityLevel" + }, + "properties": { + "$ref": "#/items/0/$defs/accessibilityLevel" + } + }, + "type": "object" + } + }, + "type": "object" + } +] + + +# TYPES: + +type AccessibilityLevel = + /** Always require an accessor. */ + | 'explicit' + /** Never check whether there is an accessor. */ + | 'off' + /** Require an accessor except when public. */ + | 'no-public'; + +type Options = [ + { + accessibility?: AccessibilityLevel; + ignoredMethodNames?: string[]; + overrides?: { + accessors?: AccessibilityLevel; + constructors?: AccessibilityLevel; + methods?: AccessibilityLevel; + parameterProperties?: AccessibilityLevel; + properties?: AccessibilityLevel; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/explicit-module-boundary-types.shot b/packages/eslint-plugin/tests/schema-snapshots/explicit-module-boundary-types.shot new file mode 100644 index 00000000000..cd004e5a22b --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/explicit-module-boundary-types.shot @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes explicit-module-boundary-types 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowArgumentsExplicitlyTypedAsAny": { + "description": "Whether to ignore arguments that are explicitly typed as \`any\`.", + "type": "boolean" + }, + "allowDirectConstAssertionInArrowFunctions": { + "description": "Whether to ignore return type annotations on body-less arrow functions that return an \`as const\` type assertion.\\nYou must still type the parameters of the function.", + "type": "boolean" + }, + "allowedNames": { + "description": "An array of function/method names that will not have their arguments or return values checked.", + "items": { + "type": "string" + }, + "type": "array" + }, + "allowHigherOrderFunctions": { + "description": "Whether to ignore return type annotations on functions immediately returning another function expression.\\nYou must still type the parameters of the function.", + "type": "boolean" + }, + "allowTypedFunctionExpressions": { + "description": "Whether to ignore type annotations on the variable of a function expresion.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to ignore arguments that are explicitly typed as \`any\`. */ + allowArgumentsExplicitlyTypedAsAny?: boolean; + /** + * Whether to ignore return type annotations on body-less arrow functions that return an \`as const\` type assertion. + * You must still type the parameters of the function. + */ + allowDirectConstAssertionInArrowFunctions?: boolean; + /** + * Whether to ignore return type annotations on functions immediately returning another function expression. + * You must still type the parameters of the function. + */ + allowHigherOrderFunctions?: boolean; + /** Whether to ignore type annotations on the variable of a function expresion. */ + allowTypedFunctionExpressions?: boolean; + /** An array of function/method names that will not have their arguments or return values checked. */ + allowedNames?: string[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/func-call-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/func-call-spacing.shot new file mode 100644 index 00000000000..3c9d0f7ed23 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/func-call-spacing.shot @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes func-call-spacing 1`] = ` +" +# SCHEMA: + +{ + "anyOf": [ + { + "items": [ + { + "enum": ["never"] + } + ], + "maxItems": 1, + "minItems": 0, + "type": "array" + }, + { + "items": [ + { + "enum": ["always"] + }, + { + "additionalProperties": false, + "properties": { + "allowNewlines": { + "type": "boolean" + } + }, + "type": "object" + } + ], + "maxItems": 2, + "minItems": 0, + "type": "array" + } + ] +} + + +# TYPES: + +type Options = + | [] + | ['always'] + | ['never'] + | [ + 'always', + { + allowNewlines?: boolean; + }, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/init-declarations.shot b/packages/eslint-plugin/tests/schema-snapshots/init-declarations.shot new file mode 100644 index 00000000000..2b3d70185b6 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/init-declarations.shot @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes init-declarations 1`] = ` +" +# SCHEMA: + +{ + "anyOf": [ + { + "items": [ + { + "enum": ["always"] + } + ], + "maxItems": 1, + "minItems": 0, + "type": "array" + }, + { + "items": [ + { + "enum": ["never"] + }, + { + "additionalProperties": false, + "properties": { + "ignoreForLoopInit": { + "type": "boolean" + } + }, + "type": "object" + } + ], + "maxItems": 2, + "minItems": 0, + "type": "array" + } + ] +} + + +# TYPES: + +type Options = + | [] + | ['always'] + | ['never'] + | [ + 'never', + { + ignoreForLoopInit?: boolean; + }, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/key-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/key-spacing.shot new file mode 100644 index 00000000000..d476304884a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/key-spacing.shot @@ -0,0 +1,228 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes key-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "align": { + "anyOf": [ + { + "enum": ["colon", "value"] + }, + { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + }, + "on": { + "enum": ["colon", "value"] + } + }, + "type": "object" + } + ] + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + } + }, + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "multiLine": { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "align": { + "anyOf": [ + { + "enum": ["colon", "value"] + }, + { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + }, + "on": { + "enum": ["colon", "value"] + } + }, + "type": "object" + } + ] + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + } + }, + "type": "object" + }, + "singleLine": { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + } + }, + "type": "object" + } + }, + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "align": { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + }, + "on": { + "enum": ["colon", "value"] + } + }, + "type": "object" + }, + "multiLine": { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + } + }, + "type": "object" + }, + "singleLine": { + "additionalProperties": false, + "properties": { + "afterColon": { + "type": "boolean" + }, + "beforeColon": { + "type": "boolean" + }, + "mode": { + "enum": ["minimum", "strict"] + } + }, + "type": "object" + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | { + afterColon?: boolean; + align?: + | 'colon' + | 'value' + | { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + on?: 'colon' | 'value'; + }; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + } + | { + align?: { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + on?: 'colon' | 'value'; + }; + multiLine?: { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + }; + singleLine?: { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + }; + } + | { + multiLine?: { + afterColon?: boolean; + align?: + | 'colon' + | 'value' + | { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + on?: 'colon' | 'value'; + }; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + }; + singleLine?: { + afterColon?: boolean; + beforeColon?: boolean; + mode?: 'minimum' | 'strict'; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/keyword-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/keyword-spacing.shot new file mode 100644 index 00000000000..1c0d3563df8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/keyword-spacing.shot @@ -0,0 +1,1146 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes keyword-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "after": { + "default": true, + "type": "boolean" + }, + "before": { + "default": true, + "type": "boolean" + }, + "overrides": { + "additionalProperties": false, + "properties": { + "abstract": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "as": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "async": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "await": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "boolean": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "break": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "byte": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "case": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "catch": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "char": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "class": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "const": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "continue": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "debugger": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "default": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "delete": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "do": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "double": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "else": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "enum": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "export": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "extends": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "false": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "final": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "finally": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "float": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "for": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "from": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "function": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "get": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "goto": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "if": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "implements": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "import": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "in": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "instanceof": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "int": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "interface": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "let": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "long": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "native": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "new": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "null": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "of": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "package": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "private": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "protected": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "public": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "return": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "set": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "short": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "static": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "super": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "switch": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "synchronized": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "this": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "throw": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "throws": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "transient": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "true": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "try": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "type": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "typeof": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "var": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "void": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "volatile": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "while": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "with": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + }, + "yield": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + } + }, + "type": "object" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + after?: boolean; + before?: boolean; + overrides?: { + abstract?: { + after?: boolean; + before?: boolean; + }; + as?: { + after?: boolean; + before?: boolean; + }; + async?: { + after?: boolean; + before?: boolean; + }; + await?: { + after?: boolean; + before?: boolean; + }; + boolean?: { + after?: boolean; + before?: boolean; + }; + break?: { + after?: boolean; + before?: boolean; + }; + byte?: { + after?: boolean; + before?: boolean; + }; + case?: { + after?: boolean; + before?: boolean; + }; + catch?: { + after?: boolean; + before?: boolean; + }; + char?: { + after?: boolean; + before?: boolean; + }; + class?: { + after?: boolean; + before?: boolean; + }; + const?: { + after?: boolean; + before?: boolean; + }; + continue?: { + after?: boolean; + before?: boolean; + }; + debugger?: { + after?: boolean; + before?: boolean; + }; + default?: { + after?: boolean; + before?: boolean; + }; + delete?: { + after?: boolean; + before?: boolean; + }; + do?: { + after?: boolean; + before?: boolean; + }; + double?: { + after?: boolean; + before?: boolean; + }; + else?: { + after?: boolean; + before?: boolean; + }; + enum?: { + after?: boolean; + before?: boolean; + }; + export?: { + after?: boolean; + before?: boolean; + }; + extends?: { + after?: boolean; + before?: boolean; + }; + false?: { + after?: boolean; + before?: boolean; + }; + final?: { + after?: boolean; + before?: boolean; + }; + finally?: { + after?: boolean; + before?: boolean; + }; + float?: { + after?: boolean; + before?: boolean; + }; + for?: { + after?: boolean; + before?: boolean; + }; + from?: { + after?: boolean; + before?: boolean; + }; + function?: { + after?: boolean; + before?: boolean; + }; + get?: { + after?: boolean; + before?: boolean; + }; + goto?: { + after?: boolean; + before?: boolean; + }; + if?: { + after?: boolean; + before?: boolean; + }; + implements?: { + after?: boolean; + before?: boolean; + }; + import?: { + after?: boolean; + before?: boolean; + }; + in?: { + after?: boolean; + before?: boolean; + }; + instanceof?: { + after?: boolean; + before?: boolean; + }; + int?: { + after?: boolean; + before?: boolean; + }; + interface?: { + after?: boolean; + before?: boolean; + }; + let?: { + after?: boolean; + before?: boolean; + }; + long?: { + after?: boolean; + before?: boolean; + }; + native?: { + after?: boolean; + before?: boolean; + }; + new?: { + after?: boolean; + before?: boolean; + }; + null?: { + after?: boolean; + before?: boolean; + }; + of?: { + after?: boolean; + before?: boolean; + }; + package?: { + after?: boolean; + before?: boolean; + }; + private?: { + after?: boolean; + before?: boolean; + }; + protected?: { + after?: boolean; + before?: boolean; + }; + public?: { + after?: boolean; + before?: boolean; + }; + return?: { + after?: boolean; + before?: boolean; + }; + set?: { + after?: boolean; + before?: boolean; + }; + short?: { + after?: boolean; + before?: boolean; + }; + static?: { + after?: boolean; + before?: boolean; + }; + super?: { + after?: boolean; + before?: boolean; + }; + switch?: { + after?: boolean; + before?: boolean; + }; + synchronized?: { + after?: boolean; + before?: boolean; + }; + this?: { + after?: boolean; + before?: boolean; + }; + throw?: { + after?: boolean; + before?: boolean; + }; + throws?: { + after?: boolean; + before?: boolean; + }; + transient?: { + after?: boolean; + before?: boolean; + }; + true?: { + after?: boolean; + before?: boolean; + }; + try?: { + after?: boolean; + before?: boolean; + }; + type?: { + after?: boolean; + before?: boolean; + }; + typeof?: { + after?: boolean; + before?: boolean; + }; + var?: { + after?: boolean; + before?: boolean; + }; + void?: { + after?: boolean; + before?: boolean; + }; + volatile?: { + after?: boolean; + before?: boolean; + }; + while?: { + after?: boolean; + before?: boolean; + }; + with?: { + after?: boolean; + before?: boolean; + }; + yield?: { + after?: boolean; + before?: boolean; + }; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/lines-around-comment.shot b/packages/eslint-plugin/tests/schema-snapshots/lines-around-comment.shot new file mode 100644 index 00000000000..9a683cf8b25 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/lines-around-comment.shot @@ -0,0 +1,118 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes lines-around-comment 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "afterBlockComment": { + "default": false, + "type": "boolean" + }, + "afterLineComment": { + "default": false, + "type": "boolean" + }, + "allowArrayEnd": { + "type": "boolean" + }, + "allowArrayStart": { + "type": "boolean" + }, + "allowBlockEnd": { + "default": false, + "type": "boolean" + }, + "allowBlockStart": { + "default": false, + "type": "boolean" + }, + "allowClassEnd": { + "type": "boolean" + }, + "allowClassStart": { + "type": "boolean" + }, + "allowEnumEnd": { + "type": "boolean" + }, + "allowEnumStart": { + "type": "boolean" + }, + "allowInterfaceEnd": { + "type": "boolean" + }, + "allowInterfaceStart": { + "type": "boolean" + }, + "allowModuleEnd": { + "type": "boolean" + }, + "allowModuleStart": { + "type": "boolean" + }, + "allowObjectEnd": { + "type": "boolean" + }, + "allowObjectStart": { + "type": "boolean" + }, + "allowTypeEnd": { + "type": "boolean" + }, + "allowTypeStart": { + "type": "boolean" + }, + "applyDefaultIgnorePatterns": { + "type": "boolean" + }, + "beforeBlockComment": { + "default": true, + "type": "boolean" + }, + "beforeLineComment": { + "default": false, + "type": "boolean" + }, + "ignorePattern": { + "type": "string" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + afterBlockComment?: boolean; + afterLineComment?: boolean; + allowArrayEnd?: boolean; + allowArrayStart?: boolean; + allowBlockEnd?: boolean; + allowBlockStart?: boolean; + allowClassEnd?: boolean; + allowClassStart?: boolean; + allowEnumEnd?: boolean; + allowEnumStart?: boolean; + allowInterfaceEnd?: boolean; + allowInterfaceStart?: boolean; + allowModuleEnd?: boolean; + allowModuleStart?: boolean; + allowObjectEnd?: boolean; + allowObjectStart?: boolean; + allowTypeEnd?: boolean; + allowTypeStart?: boolean; + applyDefaultIgnorePatterns?: boolean; + beforeBlockComment?: boolean; + beforeLineComment?: boolean; + ignorePattern?: string; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/lines-between-class-members.shot b/packages/eslint-plugin/tests/schema-snapshots/lines-between-class-members.shot new file mode 100644 index 00000000000..9e8924e05e8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/lines-between-class-members.shot @@ -0,0 +1,38 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes lines-between-class-members 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["always", "never"] + }, + { + "additionalProperties": false, + "properties": { + "exceptAfterOverload": { + "default": true, + "type": "boolean" + }, + "exceptAfterSingleLine": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + 'always' | 'never', + { + exceptAfterOverload?: boolean; + exceptAfterSingleLine?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/member-delimiter-style.shot b/packages/eslint-plugin/tests/schema-snapshots/member-delimiter-style.shot new file mode 100644 index 00000000000..6b5cf0a4a41 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/member-delimiter-style.shot @@ -0,0 +1,129 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes member-delimiter-style 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "delimiterConfig": { + "additionalProperties": false, + "properties": { + "multiline": { + "additionalProperties": false, + "properties": { + "delimiter": { + "$ref": "#/items/0/$defs/multiLineOption" + }, + "requireLast": { + "type": "boolean" + } + }, + "type": "object" + }, + "singleline": { + "additionalProperties": false, + "properties": { + "delimiter": { + "$ref": "#/items/0/$defs/singleLineOption" + }, + "requireLast": { + "type": "boolean" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "multiLineOption": { + "enum": ["comma", "none", "semi"] + }, + "singleLineOption": { + "enum": ["comma", "semi"] + } + }, + "additionalProperties": false, + "properties": { + "multiline": { + "additionalProperties": false, + "properties": { + "delimiter": { + "$ref": "#/items/0/$defs/multiLineOption" + }, + "requireLast": { + "type": "boolean" + } + }, + "type": "object" + }, + "multilineDetection": { + "enum": ["brackets", "last-member"] + }, + "overrides": { + "additionalProperties": false, + "properties": { + "interface": { + "$ref": "#/items/0/$defs/delimiterConfig" + }, + "typeLiteral": { + "$ref": "#/items/0/$defs/delimiterConfig" + } + }, + "type": "object" + }, + "singleline": { + "additionalProperties": false, + "properties": { + "delimiter": { + "$ref": "#/items/0/$defs/singleLineOption" + }, + "requireLast": { + "type": "boolean" + } + }, + "type": "object" + } + }, + "type": "object" + } +] + + +# TYPES: + +type MultiLineOption = 'comma' | 'none' | 'semi'; + +type SingleLineOption = 'comma' | 'semi'; + +type DelimiterConfig = { + multiline?: { + delimiter?: MultiLineOption; + requireLast?: boolean; + }; + singleline?: { + delimiter?: SingleLineOption; + requireLast?: boolean; + }; +}; + +type Options = [ + { + multiline?: { + delimiter?: MultiLineOption; + requireLast?: boolean; + }; + multilineDetection?: 'brackets' | 'last-member'; + overrides?: { + interface?: DelimiterConfig; + typeLiteral?: DelimiterConfig; + }; + singleline?: { + delimiter?: SingleLineOption; + requireLast?: boolean; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/member-ordering.shot b/packages/eslint-plugin/tests/schema-snapshots/member-ordering.shot new file mode 100644 index 00000000000..d7e2517bb91 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/member-ordering.shot @@ -0,0 +1,495 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes member-ordering 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "allItems": { + "enum": [ + "#private-field", + "#private-get", + "#private-instance-field", + "#private-instance-get", + "#private-instance-method", + "#private-instance-readonly-field", + "#private-instance-set", + "#private-instance-static-initialization", + "#private-method", + "#private-readonly-field", + "#private-set", + "#private-static-field", + "#private-static-get", + "#private-static-method", + "#private-static-readonly-field", + "#private-static-set", + "#private-static-static-initialization", + "abstract-field", + "abstract-get", + "abstract-method", + "abstract-readonly-field", + "abstract-set", + "abstract-static-initialization", + "call-signature", + "constructor", + "decorated-field", + "decorated-get", + "decorated-method", + "decorated-readonly-field", + "decorated-set", + "field", + "get", + "instance-field", + "instance-get", + "instance-method", + "instance-readonly-field", + "instance-set", + "instance-static-initialization", + "method", + "private-constructor", + "private-decorated-field", + "private-decorated-get", + "private-decorated-method", + "private-decorated-readonly-field", + "private-decorated-set", + "private-field", + "private-get", + "private-instance-field", + "private-instance-get", + "private-instance-method", + "private-instance-readonly-field", + "private-instance-set", + "private-instance-static-initialization", + "private-method", + "private-readonly-field", + "private-set", + "private-static-field", + "private-static-get", + "private-static-method", + "private-static-readonly-field", + "private-static-set", + "private-static-static-initialization", + "protected-abstract-field", + "protected-abstract-get", + "protected-abstract-method", + "protected-abstract-readonly-field", + "protected-abstract-set", + "protected-abstract-static-initialization", + "protected-constructor", + "protected-decorated-field", + "protected-decorated-get", + "protected-decorated-method", + "protected-decorated-readonly-field", + "protected-decorated-set", + "protected-field", + "protected-get", + "protected-instance-field", + "protected-instance-get", + "protected-instance-method", + "protected-instance-readonly-field", + "protected-instance-set", + "protected-instance-static-initialization", + "protected-method", + "protected-readonly-field", + "protected-set", + "protected-static-field", + "protected-static-get", + "protected-static-method", + "protected-static-readonly-field", + "protected-static-set", + "protected-static-static-initialization", + "public-abstract-field", + "public-abstract-get", + "public-abstract-method", + "public-abstract-readonly-field", + "public-abstract-set", + "public-abstract-static-initialization", + "public-constructor", + "public-decorated-field", + "public-decorated-get", + "public-decorated-method", + "public-decorated-readonly-field", + "public-decorated-set", + "public-field", + "public-get", + "public-instance-field", + "public-instance-get", + "public-instance-method", + "public-instance-readonly-field", + "public-instance-set", + "public-instance-static-initialization", + "public-method", + "public-readonly-field", + "public-set", + "public-static-field", + "public-static-get", + "public-static-method", + "public-static-readonly-field", + "public-static-set", + "public-static-static-initialization", + "readonly-field", + "readonly-signature", + "set", + "signature", + "static-field", + "static-get", + "static-initialization", + "static-method", + "static-readonly-field", + "static-set", + "static-static-initialization" + ], + "type": "string" + }, + "baseConfig": { + "oneOf": [ + { + "enum": ["never"], + "type": "string" + }, + { + "items": { + "oneOf": [ + { + "$ref": "#/items/0/$defs/allItems" + }, + { + "items": { + "$ref": "#/items/0/$defs/allItems" + }, + "type": "array" + } + ] + }, + "type": "array" + }, + { + "additionalProperties": false, + "properties": { + "memberTypes": { + "oneOf": [ + { + "items": { + "oneOf": [ + { + "$ref": "#/items/0/$defs/allItems" + }, + { + "items": { + "$ref": "#/items/0/$defs/allItems" + }, + "type": "array" + } + ] + }, + "type": "array" + }, + { + "enum": ["never"], + "type": "string" + } + ] + }, + "optionalityOrder": { + "$ref": "#/items/0/$defs/optionalityOrderOptions" + }, + "order": { + "$ref": "#/items/0/$defs/orderOptions" + } + }, + "type": "object" + } + ] + }, + "optionalityOrderOptions": { + "enum": ["optional-first", "required-first"], + "type": "string" + }, + "orderOptions": { + "enum": [ + "alphabetically", + "alphabetically-case-insensitive", + "as-written", + "natural", + "natural-case-insensitive" + ], + "type": "string" + }, + "typeItems": { + "enum": [ + "constructor", + "field", + "method", + "readonly-field", + "readonly-signature", + "signature" + ], + "type": "string" + }, + "typesConfig": { + "oneOf": [ + { + "enum": ["never"], + "type": "string" + }, + { + "items": { + "oneOf": [ + { + "$ref": "#/items/0/$defs/typeItems" + }, + { + "items": { + "$ref": "#/items/0/$defs/typeItems" + }, + "type": "array" + } + ] + }, + "type": "array" + }, + { + "additionalProperties": false, + "properties": { + "memberTypes": { + "oneOf": [ + { + "items": { + "oneOf": [ + { + "$ref": "#/items/0/$defs/typeItems" + }, + { + "items": { + "$ref": "#/items/0/$defs/typeItems" + }, + "type": "array" + } + ] + }, + "type": "array" + }, + { + "enum": ["never"], + "type": "string" + } + ] + }, + "optionalityOrder": { + "$ref": "#/items/0/$defs/optionalityOrderOptions" + }, + "order": { + "$ref": "#/items/0/$defs/orderOptions" + } + }, + "type": "object" + } + ] + } + }, + "additionalProperties": false, + "properties": { + "classes": { + "$ref": "#/items/0/$defs/baseConfig" + }, + "classExpressions": { + "$ref": "#/items/0/$defs/baseConfig" + }, + "default": { + "$ref": "#/items/0/$defs/baseConfig" + }, + "interfaces": { + "$ref": "#/items/0/$defs/typesConfig" + }, + "typeLiterals": { + "$ref": "#/items/0/$defs/typesConfig" + } + }, + "type": "object" + } +] + + +# TYPES: + +type OrderOptions = + | 'alphabetically' + | 'alphabetically-case-insensitive' + | 'as-written' + | 'natural' + | 'natural-case-insensitive'; + +type OptionalityOrderOptions = 'optional-first' | 'required-first'; + +type AllItems = + | '#private-field' + | '#private-get' + | '#private-instance-field' + | '#private-instance-get' + | '#private-instance-method' + | '#private-instance-readonly-field' + | '#private-instance-set' + | '#private-instance-static-initialization' + | '#private-method' + | '#private-readonly-field' + | '#private-set' + | '#private-static-field' + | '#private-static-get' + | '#private-static-method' + | '#private-static-readonly-field' + | '#private-static-set' + | '#private-static-static-initialization' + | 'abstract-field' + | 'abstract-get' + | 'abstract-method' + | 'abstract-readonly-field' + | 'abstract-set' + | 'abstract-static-initialization' + | 'call-signature' + | 'constructor' + | 'decorated-field' + | 'decorated-get' + | 'decorated-method' + | 'decorated-readonly-field' + | 'decorated-set' + | 'field' + | 'get' + | 'instance-field' + | 'instance-get' + | 'instance-method' + | 'instance-readonly-field' + | 'instance-set' + | 'instance-static-initialization' + | 'method' + | 'private-constructor' + | 'private-decorated-field' + | 'private-decorated-get' + | 'private-decorated-method' + | 'private-decorated-readonly-field' + | 'private-decorated-set' + | 'private-field' + | 'private-get' + | 'private-instance-field' + | 'private-instance-get' + | 'private-instance-method' + | 'private-instance-readonly-field' + | 'private-instance-set' + | 'private-instance-static-initialization' + | 'private-method' + | 'private-readonly-field' + | 'private-set' + | 'private-static-field' + | 'private-static-get' + | 'private-static-method' + | 'private-static-readonly-field' + | 'private-static-set' + | 'private-static-static-initialization' + | 'protected-abstract-field' + | 'protected-abstract-get' + | 'protected-abstract-method' + | 'protected-abstract-readonly-field' + | 'protected-abstract-set' + | 'protected-abstract-static-initialization' + | 'protected-constructor' + | 'protected-decorated-field' + | 'protected-decorated-get' + | 'protected-decorated-method' + | 'protected-decorated-readonly-field' + | 'protected-decorated-set' + | 'protected-field' + | 'protected-get' + | 'protected-instance-field' + | 'protected-instance-get' + | 'protected-instance-method' + | 'protected-instance-readonly-field' + | 'protected-instance-set' + | 'protected-instance-static-initialization' + | 'protected-method' + | 'protected-readonly-field' + | 'protected-set' + | 'protected-static-field' + | 'protected-static-get' + | 'protected-static-method' + | 'protected-static-readonly-field' + | 'protected-static-set' + | 'protected-static-static-initialization' + | 'public-abstract-field' + | 'public-abstract-get' + | 'public-abstract-method' + | 'public-abstract-readonly-field' + | 'public-abstract-set' + | 'public-abstract-static-initialization' + | 'public-constructor' + | 'public-decorated-field' + | 'public-decorated-get' + | 'public-decorated-method' + | 'public-decorated-readonly-field' + | 'public-decorated-set' + | 'public-field' + | 'public-get' + | 'public-instance-field' + | 'public-instance-get' + | 'public-instance-method' + | 'public-instance-readonly-field' + | 'public-instance-set' + | 'public-instance-static-initialization' + | 'public-method' + | 'public-readonly-field' + | 'public-set' + | 'public-static-field' + | 'public-static-get' + | 'public-static-method' + | 'public-static-readonly-field' + | 'public-static-set' + | 'public-static-static-initialization' + | 'readonly-field' + | 'readonly-signature' + | 'set' + | 'signature' + | 'static-field' + | 'static-get' + | 'static-initialization' + | 'static-method' + | 'static-readonly-field' + | 'static-set' + | 'static-static-initialization'; + +type TypeItems = + | 'constructor' + | 'field' + | 'method' + | 'readonly-field' + | 'readonly-signature' + | 'signature'; + +type BaseConfig = + | 'never' + | (AllItems | AllItems[])[] + | { + memberTypes?: 'never' | (AllItems | AllItems[])[]; + optionalityOrder?: OptionalityOrderOptions; + order?: OrderOptions; + }; + +type TypesConfig = + | 'never' + | (TypeItems | TypeItems[])[] + | { + memberTypes?: 'never' | (TypeItems | TypeItems[])[]; + optionalityOrder?: OptionalityOrderOptions; + order?: OrderOptions; + }; + +type Options = [ + { + classExpressions?: BaseConfig; + classes?: BaseConfig; + default?: BaseConfig; + interfaces?: TypesConfig; + typeLiterals?: TypesConfig; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/method-signature-style.shot b/packages/eslint-plugin/tests/schema-snapshots/method-signature-style.shot new file mode 100644 index 00000000000..d03573a0898 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/method-signature-style.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes method-signature-style 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["method", "property"] + } +] + + +# TYPES: + +type Options = ['method' | 'property']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/naming-convention.shot b/packages/eslint-plugin/tests/schema-snapshots/naming-convention.shot new file mode 100644 index 00000000000..c97b0eefc22 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/naming-convention.shot @@ -0,0 +1,1992 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes naming-convention 1`] = ` +" +# SCHEMA: + +{ + "$defs": { + "formatOptionsConfig": { + "oneOf": [ + { + "additionalItems": false, + "items": { + "$ref": "#/$defs/predefinedFormats" + }, + "type": "array" + }, + { + "type": "null" + } + ] + }, + "matchRegexConfig": { + "properties": { + "match": { + "type": "boolean" + }, + "regex": { + "type": "string" + } + }, + "required": ["match", "regex"], + "type": "object" + }, + "predefinedFormats": { + "enum": [ + "PascalCase", + "StrictPascalCase", + "UPPER_CASE", + "camelCase", + "snake_case", + "strictCamelCase" + ], + "type": "string" + }, + "prefixSuffixConfig": { + "additionalItems": false, + "items": { + "minLength": 1, + "type": "string" + }, + "type": "array" + }, + "typeModifiers": { + "enum": ["array", "boolean", "function", "number", "string"], + "type": "string" + }, + "underscoreOptions": { + "enum": [ + "allow", + "allowDouble", + "allowSingleOrDouble", + "forbid", + "require", + "requireDouble" + ], + "type": "string" + } + }, + "additionalItems": false, + "items": { + "oneOf": [ + { + "additionalProperties": false, + "description": "Multiple selectors in one config", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "const", + "destructured", + "exported", + "global", + "override", + "private", + "protected", + "public", + "readonly", + "requiresQuotes", + "static", + "unused" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "additionalItems": false, + "items": { + "enum": [ + "accessor", + "class", + "classMethod", + "classProperty", + "default", + "enum", + "enumMember", + "function", + "interface", + "memberLike", + "method", + "objectLiteralMethod", + "objectLiteralProperty", + "parameter", + "parameterProperty", + "property", + "typeAlias", + "typeLike", + "typeMethod", + "typeParameter", + "typeProperty", + "variable", + "variableLike" + ], + "type": "string" + }, + "type": "array" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'default'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "const", + "destructured", + "exported", + "global", + "override", + "private", + "protected", + "public", + "readonly", + "requiresQuotes", + "static", + "unused" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["default"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'variableLike'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["async", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["variableLike"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'variable'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "async", + "const", + "destructured", + "exported", + "global", + "unused" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["variable"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'function'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["async", "exported", "global", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["function"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'parameter'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["destructured", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["parameter"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'memberLike'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "override", + "private", + "protected", + "public", + "readonly", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["memberLike"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'classProperty'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "override", + "private", + "protected", + "public", + "readonly", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["classProperty"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'objectLiteralProperty'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["public", "requiresQuotes"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["objectLiteralProperty"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'typeProperty'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["public", "readonly", "requiresQuotes"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["typeProperty"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'parameterProperty'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["private", "protected", "public", "readonly"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["parameterProperty"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'property'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "override", + "private", + "protected", + "public", + "readonly", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["property"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'classMethod'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "override", + "private", + "protected", + "public", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["classMethod"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'objectLiteralMethod'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["async", "public", "requiresQuotes"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["objectLiteralMethod"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'typeMethod'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["public", "requiresQuotes"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["typeMethod"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'method'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "#private", + "abstract", + "async", + "override", + "private", + "protected", + "public", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["method"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'accessor'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": [ + "abstract", + "override", + "private", + "protected", + "public", + "requiresQuotes", + "static" + ], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["accessor"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "types": { + "additionalItems": false, + "items": { + "$ref": "#/$defs/typeModifiers" + }, + "type": "array" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'enumMember'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["requiresQuotes"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["enumMember"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'typeLike'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["abstract", "exported", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["typeLike"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'class'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["abstract", "exported", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["class"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'interface'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["exported", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["interface"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'typeAlias'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["exported", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["typeAlias"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'enum'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["exported", "unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["enum"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + }, + { + "additionalProperties": false, + "description": "Selector 'typeParameter'", + "properties": { + "custom": { + "$ref": "#/$defs/matchRegexConfig" + }, + "failureMessage": { + "type": "string" + }, + "filter": { + "oneOf": [ + { + "minLength": 1, + "type": "string" + }, + { + "$ref": "#/$defs/matchRegexConfig" + } + ] + }, + "format": { + "$ref": "#/$defs/formatOptionsConfig" + }, + "leadingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + }, + "modifiers": { + "additionalItems": false, + "items": { + "enum": ["unused"], + "type": "string" + }, + "type": "array" + }, + "prefix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "selector": { + "enum": ["typeParameter"], + "type": "string" + }, + "suffix": { + "$ref": "#/$defs/prefixSuffixConfig" + }, + "trailingUnderscore": { + "$ref": "#/$defs/underscoreOptions" + } + }, + "required": ["selector", "format"], + "type": "object" + } + ] + }, + "type": "array" +} + + +# TYPES: + +type UnderscoreOptions = + | 'allow' + | 'allowDouble' + | 'allowSingleOrDouble' + | 'forbid' + | 'require' + | 'requireDouble'; + +type PredefinedFormats = + | 'PascalCase' + | 'StrictPascalCase' + | 'UPPER_CASE' + | 'camelCase' + | 'snake_case' + | 'strictCamelCase'; + +type TypeModifiers = 'array' | 'boolean' | 'function' | 'number' | 'string'; + +type PrefixSuffixConfig = string[]; + +type MatchRegexConfig = { + match: boolean; + regex: string; +}; + +type FormatOptionsConfig = PredefinedFormats[] | null; + +type Options = /** Multiple selectors in one config */ +(| { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'const' + | 'destructured' + | 'exported' + | 'global' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'readonly' + | 'requiresQuotes' + | 'static' + | 'unused' + )[]; + prefix?: PrefixSuffixConfig; + selector: ( + | 'accessor' + | 'class' + | 'classMethod' + | 'classProperty' + | 'default' + | 'enum' + | 'enumMember' + | 'function' + | 'interface' + | 'memberLike' + | 'method' + | 'objectLiteralMethod' + | 'objectLiteralProperty' + | 'parameter' + | 'parameterProperty' + | 'property' + | 'typeAlias' + | 'typeLike' + | 'typeMethod' + | 'typeParameter' + | 'typeProperty' + | 'variable' + | 'variableLike' + )[]; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'accessor' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | 'abstract' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'accessor'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'class' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('abstract' | 'exported' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'class'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'classMethod' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'classMethod'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'classProperty' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'readonly' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'classProperty'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'default' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'const' + | 'destructured' + | 'exported' + | 'global' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'readonly' + | 'requiresQuotes' + | 'static' + | 'unused' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'default'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'enum' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('exported' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'enum'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'enumMember' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('requiresQuotes')[]; + prefix?: PrefixSuffixConfig; + selector: 'enumMember'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'function' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('async' | 'exported' | 'global' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'function'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'interface' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('exported' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'interface'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'memberLike' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'readonly' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'memberLike'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'method' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'method'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'objectLiteralMethod' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('async' | 'public' | 'requiresQuotes')[]; + prefix?: PrefixSuffixConfig; + selector: 'objectLiteralMethod'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'objectLiteralProperty' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('public' | 'requiresQuotes')[]; + prefix?: PrefixSuffixConfig; + selector: 'objectLiteralProperty'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'parameter' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('destructured' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'parameter'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'parameterProperty' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('private' | 'protected' | 'public' | 'readonly')[]; + prefix?: PrefixSuffixConfig; + selector: 'parameterProperty'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'property' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | '#private' + | 'abstract' + | 'async' + | 'override' + | 'private' + | 'protected' + | 'public' + | 'readonly' + | 'requiresQuotes' + | 'static' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'property'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'typeAlias' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('exported' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'typeAlias'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'typeLike' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('abstract' | 'exported' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'typeLike'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'typeMethod' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('public' | 'requiresQuotes')[]; + prefix?: PrefixSuffixConfig; + selector: 'typeMethod'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'typeParameter' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'typeParameter'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } + /** Selector 'typeProperty' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('public' | 'readonly' | 'requiresQuotes')[]; + prefix?: PrefixSuffixConfig; + selector: 'typeProperty'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'variable' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ( + | 'async' + | 'const' + | 'destructured' + | 'exported' + | 'global' + | 'unused' + )[]; + prefix?: PrefixSuffixConfig; + selector: 'variable'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + types?: TypeModifiers[]; + } + /** Selector 'variableLike' */ + | { + custom?: MatchRegexConfig; + failureMessage?: string; + filter?: MatchRegexConfig | string; + format: FormatOptionsConfig; + leadingUnderscore?: UnderscoreOptions; + modifiers?: ('async' | 'unused')[]; + prefix?: PrefixSuffixConfig; + selector: 'variableLike'; + suffix?: PrefixSuffixConfig; + trailingUnderscore?: UnderscoreOptions; + } +)[]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot b/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot new file mode 100644 index 00000000000..fddb0ea6c63 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-array-constructor.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-array-constructor 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-base-to-string.shot b/packages/eslint-plugin/tests/schema-snapshots/no-base-to-string.shot new file mode 100644 index 00000000000..af652bc7e38 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-base-to-string.shot @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-base-to-string 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoredTypeNames": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + ignoredTypeNames?: string[]; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..6f0b386771a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-confusing-non-null-assertion.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-confusing-non-null-assertion 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-confusing-void-expression.shot b/packages/eslint-plugin/tests/schema-snapshots/no-confusing-void-expression.shot new file mode 100644 index 00000000000..b7481d1000c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-confusing-void-expression.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-confusing-void-expression 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreArrowShorthand": { + "type": "boolean" + }, + "ignoreVoidOperator": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + ignoreArrowShorthand?: boolean; + ignoreVoidOperator?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..3860df1d232 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-dupe-class-members.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-dupe-class-members 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..466f69dde1e --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-enum-values.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-duplicate-enum-values 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-type-constituents.shot b/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-type-constituents.shot new file mode 100644 index 00000000000..d111b2e3729 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-duplicate-type-constituents.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-duplicate-type-constituents 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreIntersections": { + "type": "boolean" + }, + "ignoreUnions": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + ignoreIntersections?: boolean; + ignoreUnions?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot b/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot new file mode 100644 index 00000000000..3a77da1e1ca --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-dynamic-delete.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-dynamic-delete 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-empty-function.shot b/packages/eslint-plugin/tests/schema-snapshots/no-empty-function.shot new file mode 100644 index 00000000000..e863a0f81cc --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-empty-function.shot @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-empty-function 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allow": { + "items": { + "enum": [ + "arrowFunctions", + "asyncFunctions", + "asyncMethods", + "constructors", + "decoratedFunctions", + "functions", + "generatorFunctions", + "generatorMethods", + "getters", + "methods", + "overrideMethods", + "private-constructors", + "protected-constructors", + "setters" + ] + }, + "type": "array", + "uniqueItems": true + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allow?: ( + | 'arrowFunctions' + | 'asyncFunctions' + | 'asyncMethods' + | 'constructors' + | 'decoratedFunctions' + | 'functions' + | 'generatorFunctions' + | 'generatorMethods' + | 'getters' + | 'methods' + | 'overrideMethods' + | 'private-constructors' + | 'protected-constructors' + | 'setters' + )[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-empty-interface.shot b/packages/eslint-plugin/tests/schema-snapshots/no-empty-interface.shot new file mode 100644 index 00000000000..fa4dbf83d2c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-empty-interface.shot @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-empty-interface 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowSingleExtends": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowSingleExtends?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-explicit-any.shot b/packages/eslint-plugin/tests/schema-snapshots/no-explicit-any.shot new file mode 100644 index 00000000000..0a857d21554 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-explicit-any.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-explicit-any 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "fixToUnknown": { + "description": "Whether to enable auto-fixing in which the \`any\` type is converted to the \`unknown\` type.", + "type": "boolean" + }, + "ignoreRestArgs": { + "description": "Whether to ignore rest parameter arrays.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to enable auto-fixing in which the \`any\` type is converted to the \`unknown\` type. */ + fixToUnknown?: boolean; + /** Whether to ignore rest parameter arrays. */ + ignoreRestArgs?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..1bdd3183789 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-extra-non-null-assertion.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-extra-non-null-assertion 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-extra-parens.shot b/packages/eslint-plugin/tests/schema-snapshots/no-extra-parens.shot new file mode 100644 index 00000000000..b260e62f17b --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-extra-parens.shot @@ -0,0 +1,87 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-extra-parens 1`] = ` +" +# SCHEMA: + +{ + "anyOf": [ + { + "items": [ + { + "enum": ["functions"] + } + ], + "maxItems": 1, + "minItems": 0, + "type": "array" + }, + { + "items": [ + { + "enum": ["all"] + }, + { + "additionalProperties": false, + "properties": { + "allowParensAfterCommentPattern": { + "type": "string" + }, + "conditionalAssign": { + "type": "boolean" + }, + "enforceForArrowConditionals": { + "type": "boolean" + }, + "enforceForFunctionPrototypeMethods": { + "type": "boolean" + }, + "enforceForNewInMemberExpressions": { + "type": "boolean" + }, + "enforceForSequenceExpressions": { + "type": "boolean" + }, + "ignoreJSX": { + "enum": ["all", "multi-line", "none", "single-line"] + }, + "nestedBinaryExpressions": { + "type": "boolean" + }, + "returnAssign": { + "type": "boolean" + } + }, + "type": "object" + } + ], + "maxItems": 2, + "minItems": 0, + "type": "array" + } + ] +} + + +# TYPES: + +type Options = + | [] + | ['all'] + | ['functions'] + | [ + 'all', + { + allowParensAfterCommentPattern?: string; + conditionalAssign?: boolean; + enforceForArrowConditionals?: boolean; + enforceForFunctionPrototypeMethods?: boolean; + enforceForNewInMemberExpressions?: boolean; + enforceForSequenceExpressions?: boolean; + ignoreJSX?: 'all' | 'multi-line' | 'none' | 'single-line'; + nestedBinaryExpressions?: boolean; + returnAssign?: boolean; + }, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-extra-semi.shot b/packages/eslint-plugin/tests/schema-snapshots/no-extra-semi.shot new file mode 100644 index 00000000000..dc3b391ba2f --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-extra-semi.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-extra-semi 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-extraneous-class.shot b/packages/eslint-plugin/tests/schema-snapshots/no-extraneous-class.shot new file mode 100644 index 00000000000..b02bb56e590 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-extraneous-class.shot @@ -0,0 +1,48 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-extraneous-class 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowConstructorOnly": { + "description": "Whether to allow extraneous classes that contain only a constructor.", + "type": "boolean" + }, + "allowEmpty": { + "description": "Whether to allow extraneous classes that have no body (i.e. are empty).", + "type": "boolean" + }, + "allowStaticOnly": { + "description": "Whether to allow extraneous classes that only contain static members.", + "type": "boolean" + }, + "allowWithDecorator": { + "description": "Whether to allow extraneous classes that include a decorator.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow extraneous classes that contain only a constructor. */ + allowConstructorOnly?: boolean; + /** Whether to allow extraneous classes that have no body (i.e. are empty). */ + allowEmpty?: boolean; + /** Whether to allow extraneous classes that only contain static members. */ + allowStaticOnly?: boolean; + /** Whether to allow extraneous classes that include a decorator. */ + allowWithDecorator?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-floating-promises.shot b/packages/eslint-plugin/tests/schema-snapshots/no-floating-promises.shot new file mode 100644 index 00000000000..1218cb2d329 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-floating-promises.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-floating-promises 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreIIFE": { + "description": "Whether to ignore async IIFEs (Immediately Invocated Function Expressions).", + "type": "boolean" + }, + "ignoreVoid": { + "description": "Whether to ignore \`void\` expressions.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to ignore async IIFEs (Immediately Invocated Function Expressions). */ + ignoreIIFE?: boolean; + /** Whether to ignore \`void\` expressions. */ + ignoreVoid?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..f5942d6181c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-for-in-array.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-for-in-array 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..32ce767e813 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-implied-eval.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-implied-eval 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..02d33924257 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-import-type-side-effects.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-import-type-side-effects 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-inferrable-types.shot b/packages/eslint-plugin/tests/schema-snapshots/no-inferrable-types.shot new file mode 100644 index 00000000000..c913653a007 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-inferrable-types.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-inferrable-types 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreParameters": { + "type": "boolean" + }, + "ignoreProperties": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + ignoreParameters?: boolean; + ignoreProperties?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-invalid-this.shot b/packages/eslint-plugin/tests/schema-snapshots/no-invalid-this.shot new file mode 100644 index 00000000000..75cd5974f14 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-invalid-this.shot @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-invalid-this 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "capIsConstructor": { + "default": true, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + capIsConstructor?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-invalid-void-type.shot b/packages/eslint-plugin/tests/schema-snapshots/no-invalid-void-type.shot new file mode 100644 index 00000000000..61f32fe43a8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-invalid-void-type.shot @@ -0,0 +1,43 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-invalid-void-type 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowAsThisParameter": { + "type": "boolean" + }, + "allowInGenericTypeArguments": { + "oneOf": [ + { + "type": "boolean" + }, + { + "items": { + "type": "string" + }, + "minLength": 1, + "type": "array" + } + ] + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowAsThisParameter?: boolean; + allowInGenericTypeArguments?: boolean | string[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot b/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot new file mode 100644 index 00000000000..1509d5ece1b --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-loop-func.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-loop-func 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..54ee68e2e89 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-loss-of-precision.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-loss-of-precision 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-magic-numbers.shot b/packages/eslint-plugin/tests/schema-snapshots/no-magic-numbers.shot new file mode 100644 index 00000000000..5628d7b9927 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-magic-numbers.shot @@ -0,0 +1,81 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-magic-numbers 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "detectObjects": { + "default": false, + "type": "boolean" + }, + "enforceConst": { + "default": false, + "type": "boolean" + }, + "ignore": { + "items": { + "anyOf": [ + { + "type": "number" + }, + { + "pattern": "^[+-]?(?:0|[1-9][0-9]*)n$", + "type": "string" + } + ] + }, + "type": "array", + "uniqueItems": true + }, + "ignoreArrayIndexes": { + "default": false, + "type": "boolean" + }, + "ignoreClassFieldInitialValues": { + "default": false, + "type": "boolean" + }, + "ignoreDefaultValues": { + "default": false, + "type": "boolean" + }, + "ignoreEnums": { + "type": "boolean" + }, + "ignoreNumericLiteralTypes": { + "type": "boolean" + }, + "ignoreReadonlyClassProperties": { + "type": "boolean" + }, + "ignoreTypeIndexes": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + detectObjects?: boolean; + enforceConst?: boolean; + ignore?: (number | string)[]; + ignoreArrayIndexes?: boolean; + ignoreClassFieldInitialValues?: boolean; + ignoreDefaultValues?: boolean; + ignoreEnums?: boolean; + ignoreNumericLiteralTypes?: boolean; + ignoreReadonlyClassProperties?: boolean; + ignoreTypeIndexes?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-meaningless-void-operator.shot b/packages/eslint-plugin/tests/schema-snapshots/no-meaningless-void-operator.shot new file mode 100644 index 00000000000..8f66e54f40d --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-meaningless-void-operator.shot @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-meaningless-void-operator 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "checkNever": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + checkNever?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot b/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot new file mode 100644 index 00000000000..52ae6ae98c0 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-misused-new.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-misused-new 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-misused-promises.shot b/packages/eslint-plugin/tests/schema-snapshots/no-misused-promises.shot new file mode 100644 index 00000000000..be4e2d56112 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-misused-promises.shot @@ -0,0 +1,68 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-misused-promises 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "checksConditionals": { + "type": "boolean" + }, + "checksSpreads": { + "type": "boolean" + }, + "checksVoidReturn": { + "oneOf": [ + { + "type": "boolean" + }, + { + "additionalProperties": false, + "properties": { + "arguments": { + "type": "boolean" + }, + "attributes": { + "type": "boolean" + }, + "properties": { + "type": "boolean" + }, + "returns": { + "type": "boolean" + }, + "variables": { + "type": "boolean" + } + }, + "type": "object" + } + ] + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + checksConditionals?: boolean; + checksSpreads?: boolean; + checksVoidReturn?: + | { + arguments?: boolean; + attributes?: boolean; + properties?: boolean; + returns?: boolean; + variables?: boolean; + } + | boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot b/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot new file mode 100644 index 00000000000..ce6f1562980 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-mixed-enums.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-mixed-enums 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-namespace.shot b/packages/eslint-plugin/tests/schema-snapshots/no-namespace.shot new file mode 100644 index 00000000000..79c1f36922d --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-namespace.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-namespace 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowDeclarations": { + "description": "Whether to allow \`declare\` with custom TypeScript namespaces.", + "type": "boolean" + }, + "allowDefinitionFiles": { + "description": "Whether to allow \`declare\` with custom TypeScript namespaces inside definition files.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow \`declare\` with custom TypeScript namespaces. */ + allowDeclarations?: boolean; + /** Whether to allow \`declare\` with custom TypeScript namespaces inside definition files. */ + allowDefinitionFiles?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..ce0bfb40fe4 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-nullish-coalescing.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-non-null-asserted-nullish-coalescing 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..27c579c858c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-asserted-optional-chain.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-non-null-asserted-optional-chain 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..f292b46e306 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-non-null-assertion.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-non-null-assertion 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-redeclare.shot b/packages/eslint-plugin/tests/schema-snapshots/no-redeclare.shot new file mode 100644 index 00000000000..61f33831a07 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-redeclare.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-redeclare 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "builtinGlobals": { + "type": "boolean" + }, + "ignoreDeclarationMerge": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + builtinGlobals?: boolean; + ignoreDeclarationMerge?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..e80f262a7ce --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-redundant-type-constituents.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-redundant-type-constituents 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-require-imports.shot b/packages/eslint-plugin/tests/schema-snapshots/no-require-imports.shot new file mode 100644 index 00000000000..bdb7cb32538 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-require-imports.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-require-imports 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-restricted-imports.shot b/packages/eslint-plugin/tests/schema-snapshots/no-restricted-imports.shot new file mode 100644 index 00000000000..e41e144b41c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-restricted-imports.shot @@ -0,0 +1,183 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-restricted-imports 1`] = ` +" +# SCHEMA: + +{ + "anyOf": [ + { + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "additionalProperties": false, + "properties": { + "allowTypeImports": { + "description": "Disallow value imports, but allow type-only imports.", + "type": "boolean" + }, + "importNames": { + "items": { + "type": "string" + }, + "type": "array" + }, + "message": { + "minLength": 1, + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": ["name"], + "type": "object" + } + ] + }, + "type": "array", + "uniqueItems": true + }, + { + "additionalItems": false, + "items": [ + { + "additionalProperties": false, + "properties": { + "paths": { + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "additionalProperties": false, + "properties": { + "allowTypeImports": { + "description": "Disallow value imports, but allow type-only imports.", + "type": "boolean" + }, + "importNames": { + "items": { + "type": "string" + }, + "type": "array" + }, + "message": { + "minLength": 1, + "type": "string" + }, + "name": { + "type": "string" + } + }, + "required": ["name"], + "type": "object" + } + ] + }, + "type": "array", + "uniqueItems": true + }, + "patterns": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array", + "uniqueItems": true + }, + { + "items": { + "additionalProperties": false, + "properties": { + "allowTypeImports": { + "description": "Disallow value imports, but allow type-only imports.", + "type": "boolean" + }, + "caseSensitive": { + "type": "boolean" + }, + "group": { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "importNames": { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "message": { + "minLength": 1, + "type": "string" + } + }, + "required": ["group"], + "type": "object" + }, + "type": "array", + "uniqueItems": true + } + ] + } + }, + "type": "object" + } + ], + "type": "array" + } + ] +} + + +# TYPES: + +type Options = + | ( + | { + /** Disallow value imports, but allow type-only imports. */ + allowTypeImports?: boolean; + importNames?: string[]; + message?: string; + name: string; + } + | string + )[] + | [] + | [ + { + paths?: ( + | { + /** Disallow value imports, but allow type-only imports. */ + allowTypeImports?: boolean; + importNames?: string[]; + message?: string; + name: string; + } + | string + )[]; + patterns?: + | { + /** Disallow value imports, but allow type-only imports. */ + allowTypeImports?: boolean; + caseSensitive?: boolean; + group: [string, ...string[]]; + importNames?: [string, ...string[]]; + message?: string; + }[] + | string[]; + }, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-shadow.shot b/packages/eslint-plugin/tests/schema-snapshots/no-shadow.shot new file mode 100644 index 00000000000..d16291030d6 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-shadow.shot @@ -0,0 +1,51 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-shadow 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allow": { + "items": { + "type": "string" + }, + "type": "array" + }, + "builtinGlobals": { + "type": "boolean" + }, + "hoist": { + "enum": ["all", "functions", "never"] + }, + "ignoreFunctionTypeParameterNameValueShadow": { + "type": "boolean" + }, + "ignoreOnInitialization": { + "type": "boolean" + }, + "ignoreTypeValueShadow": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allow?: string[]; + builtinGlobals?: boolean; + hoist?: 'all' | 'functions' | 'never'; + ignoreFunctionTypeParameterNameValueShadow?: boolean; + ignoreOnInitialization?: boolean; + ignoreTypeValueShadow?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-this-alias.shot b/packages/eslint-plugin/tests/schema-snapshots/no-this-alias.shot new file mode 100644 index 00000000000..7bf1f235430 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-this-alias.shot @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-this-alias 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowDestructuring": { + "description": "Whether to ignore destructurings, such as \`const { props, state } = this\`.", + "type": "boolean" + }, + "allowedNames": { + "description": "Names to ignore, such as [\\"self\\"] for \`const self = this;\`.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to ignore destructurings, such as \`const { props, state } = this\`. */ + allowDestructuring?: boolean; + /** Names to ignore, such as ["self"] for \`const self = this;\`. */ + allowedNames?: string[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-throw-literal.shot b/packages/eslint-plugin/tests/schema-snapshots/no-throw-literal.shot new file mode 100644 index 00000000000..eb5380cdecc --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-throw-literal.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-throw-literal 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowThrowingAny": { + "type": "boolean" + }, + "allowThrowingUnknown": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowThrowingAny?: boolean; + allowThrowingUnknown?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-type-alias.shot b/packages/eslint-plugin/tests/schema-snapshots/no-type-alias.shot new file mode 100644 index 00000000000..16653ab2565 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-type-alias.shot @@ -0,0 +1,95 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-type-alias 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "expandedOptions": { + "enum": [ + "always", + "in-intersections", + "in-unions", + "in-unions-and-intersections", + "never" + ] + }, + "simpleOptions": { + "enum": ["always", "never"] + } + }, + "additionalProperties": false, + "properties": { + "allowAliases": { + "$ref": "#/items/0/$defs/expandedOptions", + "description": "Whether to allow direct one-to-one type aliases." + }, + "allowCallbacks": { + "$ref": "#/items/0/$defs/simpleOptions", + "description": "Whether to allow type aliases for callbacks." + }, + "allowConditionalTypes": { + "$ref": "#/items/0/$defs/simpleOptions", + "description": "Whether to allow type aliases for conditional types." + }, + "allowConstructors": { + "$ref": "#/items/0/$defs/simpleOptions", + "description": "Whether to allow type aliases with constructors." + }, + "allowGenerics": { + "$ref": "#/items/0/$defs/simpleOptions", + "description": "Whether to allow type aliases with generic types." + }, + "allowLiterals": { + "$ref": "#/items/0/$defs/expandedOptions", + "description": "Whether to allow type aliases with object literal types." + }, + "allowMappedTypes": { + "$ref": "#/items/0/$defs/expandedOptions", + "description": "Whether to allow type aliases with mapped types." + }, + "allowTupleTypes": { + "$ref": "#/items/0/$defs/expandedOptions", + "description": "Whether to allow type aliases with tuple types." + } + }, + "type": "object" + } +] + + +# TYPES: + +type ExpandedOptions = + | 'always' + | 'in-intersections' + | 'in-unions' + | 'in-unions-and-intersections' + | 'never'; + +type SimpleOptions = 'always' | 'never'; + +type Options = [ + { + /** Whether to allow direct one-to-one type aliases. */ + allowAliases?: ExpandedOptions; + /** Whether to allow type aliases for callbacks. */ + allowCallbacks?: SimpleOptions; + /** Whether to allow type aliases for conditional types. */ + allowConditionalTypes?: SimpleOptions; + /** Whether to allow type aliases with constructors. */ + allowConstructors?: SimpleOptions; + /** Whether to allow type aliases with generic types. */ + allowGenerics?: SimpleOptions; + /** Whether to allow type aliases with object literal types. */ + allowLiterals?: ExpandedOptions; + /** Whether to allow type aliases with mapped types. */ + allowMappedTypes?: ExpandedOptions; + /** Whether to allow type aliases with tuple types. */ + allowTupleTypes?: ExpandedOptions; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-boolean-literal-compare.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-boolean-literal-compare.shot new file mode 100644 index 00000000000..faf2bf9e182 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-boolean-literal-compare.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-boolean-literal-compare 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowComparingNullableBooleansToFalse": { + "description": "Whether to allow comparisons between nullable boolean variables and \`false\`.", + "type": "boolean" + }, + "allowComparingNullableBooleansToTrue": { + "description": "Whether to allow comparisons between nullable boolean variables and \`true\`.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow comparisons between nullable boolean variables and \`false\`. */ + allowComparingNullableBooleansToFalse?: boolean; + /** Whether to allow comparisons between nullable boolean variables and \`true\`. */ + allowComparingNullableBooleansToTrue?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-condition.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-condition.shot new file mode 100644 index 00000000000..4f7fef6518e --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-condition.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-condition 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowConstantLoopConditions": { + "description": "Whether to ignore constant loop conditions, such as \`while (true)\`.", + "type": "boolean" + }, + "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": { + "description": "Whether to not error when running with a tsconfig that has strictNullChecks turned.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to ignore constant loop conditions, such as \`while (true)\`. */ + allowConstantLoopConditions?: boolean; + /** Whether to not error when running with a tsconfig that has strictNullChecks turned. */ + allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot new file mode 100644 index 00000000000..728930a1d9c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-qualifier.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-qualifier 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..275c98ba22f --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-arguments.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-type-arguments 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-assertion.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-assertion.shot new file mode 100644 index 00000000000..29683a8039c --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-assertion.shot @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-type-assertion 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "typesToIgnore": { + "description": "A list of type names to ignore.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** A list of type names to ignore. */ + typesToIgnore?: string[]; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..2a2fbcd8b92 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unnecessary-type-constraint.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unnecessary-type-constraint 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..9acbeed8bf2 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-argument.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-argument 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..0df27b8f4bd --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-assignment.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-assignment 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..6c7d5b0a83a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-call.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-call 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..559a8bc7fe7 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-declaration-merging.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-declaration-merging 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..1fc8fd77fbc --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-enum-comparison.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-enum-comparison 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..bf7c89189dc --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-member-access.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-member-access 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..a66f82fae7a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unsafe-return.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unsafe-return 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unused-expressions.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unused-expressions.shot new file mode 100644 index 00000000000..43950ac51ce --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unused-expressions.shot @@ -0,0 +1,44 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unused-expressions 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowShortCircuit": { + "default": false, + "type": "boolean" + }, + "allowTaggedTemplates": { + "default": false, + "type": "boolean" + }, + "allowTernary": { + "default": false, + "type": "boolean" + }, + "enforceForJSX": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowShortCircuit?: boolean; + allowTaggedTemplates?: boolean; + allowTernary?: boolean; + enforceForJSX?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-unused-vars.shot b/packages/eslint-plugin/tests/schema-snapshots/no-unused-vars.shot new file mode 100644 index 00000000000..802a33bfade --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-unused-vars.shot @@ -0,0 +1,65 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-unused-vars 1`] = ` +" +# SCHEMA: + +[ + { + "oneOf": [ + { + "enum": ["all", "local"] + }, + { + "additionalProperties": false, + "properties": { + "args": { + "enum": ["after-used", "all", "none"] + }, + "argsIgnorePattern": { + "type": "string" + }, + "caughtErrors": { + "enum": ["all", "none"] + }, + "caughtErrorsIgnorePattern": { + "type": "string" + }, + "destructuredArrayIgnorePattern": { + "type": "string" + }, + "ignoreRestSiblings": { + "type": "boolean" + }, + "vars": { + "enum": ["all", "local"] + }, + "varsIgnorePattern": { + "type": "string" + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | 'all' + | 'local' + | { + args?: 'after-used' | 'all' | 'none'; + argsIgnorePattern?: string; + caughtErrors?: 'all' | 'none'; + caughtErrorsIgnorePattern?: string; + destructuredArrayIgnorePattern?: string; + ignoreRestSiblings?: boolean; + vars?: 'all' | 'local'; + varsIgnorePattern?: string; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-use-before-define.shot b/packages/eslint-plugin/tests/schema-snapshots/no-use-before-define.shot new file mode 100644 index 00000000000..cfe91c2c7b7 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-use-before-define.shot @@ -0,0 +1,60 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-use-before-define 1`] = ` +" +# SCHEMA: + +[ + { + "oneOf": [ + { + "enum": ["nofunc"] + }, + { + "additionalProperties": false, + "properties": { + "allowNamedExports": { + "type": "boolean" + }, + "classes": { + "type": "boolean" + }, + "enums": { + "type": "boolean" + }, + "functions": { + "type": "boolean" + }, + "ignoreTypeReferences": { + "type": "boolean" + }, + "typedefs": { + "type": "boolean" + }, + "variables": { + "type": "boolean" + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | 'nofunc' + | { + allowNamedExports?: boolean; + classes?: boolean; + enums?: boolean; + functions?: boolean; + ignoreTypeReferences?: boolean; + typedefs?: boolean; + variables?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot b/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot new file mode 100644 index 00000000000..59fac39b876 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-useless-constructor.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-useless-constructor 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..40b42b0fa7e --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-useless-empty-export.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-useless-empty-export 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/no-var-requires.shot b/packages/eslint-plugin/tests/schema-snapshots/no-var-requires.shot new file mode 100644 index 00000000000..992833a20ae --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/no-var-requires.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes no-var-requires 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..483a62f5f09 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/non-nullable-type-assertion-style.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes non-nullable-type-assertion-style 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/object-curly-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/object-curly-spacing.shot new file mode 100644 index 00000000000..25f315066bb --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/object-curly-spacing.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes object-curly-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["always", "never"] + }, + { + "additionalProperties": false, + "properties": { + "arraysInObjects": { + "type": "boolean" + }, + "objectsInObjects": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + 'always' | 'never', + { + arraysInObjects?: boolean; + objectsInObjects?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/padding-line-between-statements.shot b/packages/eslint-plugin/tests/schema-snapshots/padding-line-between-statements.shot new file mode 100644 index 00000000000..7e87a4e6856 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/padding-line-between-statements.shot @@ -0,0 +1,270 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes padding-line-between-statements 1`] = ` +" +# SCHEMA: + +{ + "$defs": { + "paddingType": { + "enum": ["always", "any", "never"] + }, + "statementType": { + "anyOf": [ + { + "enum": [ + "*", + "block", + "block-like", + "break", + "case", + "class", + "const", + "continue", + "debugger", + "default", + "directive", + "do", + "empty", + "export", + "exports", + "expression", + "for", + "function", + "if", + "iife", + "import", + "interface", + "let", + "multiline-block-like", + "multiline-const", + "multiline-expression", + "multiline-let", + "multiline-var", + "require", + "return", + "singleline-const", + "singleline-let", + "singleline-var", + "switch", + "throw", + "try", + "type", + "var", + "while", + "with" + ] + }, + { + "additionalItems": false, + "items": { + "enum": [ + "*", + "block", + "block-like", + "break", + "case", + "class", + "const", + "continue", + "debugger", + "default", + "directive", + "do", + "empty", + "export", + "exports", + "expression", + "for", + "function", + "if", + "iife", + "import", + "interface", + "let", + "multiline-block-like", + "multiline-const", + "multiline-expression", + "multiline-let", + "multiline-var", + "require", + "return", + "singleline-const", + "singleline-let", + "singleline-var", + "switch", + "throw", + "try", + "type", + "var", + "while", + "with" + ] + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + } + ] + } + }, + "additionalItems": false, + "items": { + "additionalProperties": false, + "properties": { + "blankLine": { + "$ref": "#/$defs/paddingType" + }, + "next": { + "$ref": "#/$defs/statementType" + }, + "prev": { + "$ref": "#/$defs/statementType" + } + }, + "required": ["blankLine", "prev", "next"], + "type": "object" + }, + "type": "array" +} + + +# TYPES: + +type PaddingType = 'always' | 'any' | 'never'; + +type StatementType = + | '*' + | 'block' + | 'block-like' + | 'break' + | 'case' + | 'class' + | 'const' + | 'continue' + | 'debugger' + | 'default' + | 'directive' + | 'do' + | 'empty' + | 'export' + | 'exports' + | 'expression' + | 'for' + | 'function' + | 'if' + | 'iife' + | 'import' + | 'interface' + | 'let' + | 'multiline-block-like' + | 'multiline-const' + | 'multiline-expression' + | 'multiline-let' + | 'multiline-var' + | 'require' + | 'return' + | 'singleline-const' + | 'singleline-let' + | 'singleline-var' + | 'switch' + | 'throw' + | 'try' + | 'type' + | 'var' + | 'while' + | 'with' + | [ + ( + | '*' + | 'block' + | 'block-like' + | 'break' + | 'case' + | 'class' + | 'const' + | 'continue' + | 'debugger' + | 'default' + | 'directive' + | 'do' + | 'empty' + | 'export' + | 'exports' + | 'expression' + | 'for' + | 'function' + | 'if' + | 'iife' + | 'import' + | 'interface' + | 'let' + | 'multiline-block-like' + | 'multiline-const' + | 'multiline-expression' + | 'multiline-let' + | 'multiline-var' + | 'require' + | 'return' + | 'singleline-const' + | 'singleline-let' + | 'singleline-var' + | 'switch' + | 'throw' + | 'try' + | 'type' + | 'var' + | 'while' + | 'with' + ), + ...( + | '*' + | 'block' + | 'block-like' + | 'break' + | 'case' + | 'class' + | 'const' + | 'continue' + | 'debugger' + | 'default' + | 'directive' + | 'do' + | 'empty' + | 'export' + | 'exports' + | 'expression' + | 'for' + | 'function' + | 'if' + | 'iife' + | 'import' + | 'interface' + | 'let' + | 'multiline-block-like' + | 'multiline-const' + | 'multiline-expression' + | 'multiline-let' + | 'multiline-var' + | 'require' + | 'return' + | 'singleline-const' + | 'singleline-let' + | 'singleline-var' + | 'switch' + | 'throw' + | 'try' + | 'type' + | 'var' + | 'while' + | 'with' + )[], + ]; + +type Options = { + blankLine: PaddingType; + next: StatementType; + prev: StatementType; +}[]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/parameter-properties.shot b/packages/eslint-plugin/tests/schema-snapshots/parameter-properties.shot new file mode 100644 index 00000000000..f317443ca00 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/parameter-properties.shot @@ -0,0 +1,58 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes parameter-properties 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "modifier": { + "enum": [ + "private", + "private readonly", + "protected", + "protected readonly", + "public", + "public readonly", + "readonly" + ] + } + }, + "additionalProperties": false, + "properties": { + "allow": { + "items": { + "$ref": "#/items/0/$defs/modifier" + }, + "minItems": 1, + "type": "array" + }, + "prefer": { + "enum": ["class-property", "parameter-property"] + } + }, + "type": "object" + } +] + + +# TYPES: + +type Modifier = + | 'private readonly' + | 'private' + | 'protected readonly' + | 'protected' + | 'public readonly' + | 'public' + | 'readonly'; + +type Options = [ + { + allow?: [Modifier, ...Modifier[]]; + prefer?: 'class-property' | 'parameter-property'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot new file mode 100644 index 00000000000..1e687c2a354 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-as-const.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-as-const 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..281bbd737c0 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-enum-initializers.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-enum-initializers 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..07e7b0510c4 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-for-of.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-for-of 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..5c28dbbe392 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-function-type.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-function-type 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot new file mode 100644 index 00000000000..0315e76ddaa --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-includes.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-includes 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-literal-enum-member.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-literal-enum-member.shot new file mode 100644 index 00000000000..9bbb15fe6dd --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-literal-enum-member.shot @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-literal-enum-member 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowBitwiseExpressions": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowBitwiseExpressions?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot new file mode 100644 index 00000000000..6ef076952a8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-namespace-keyword.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-namespace-keyword 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-nullish-coalescing.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-nullish-coalescing.shot new file mode 100644 index 00000000000..13091c88c64 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-nullish-coalescing.shot @@ -0,0 +1,40 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-nullish-coalescing 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": { + "type": "boolean" + }, + "ignoreConditionalTests": { + "type": "boolean" + }, + "ignoreMixedLogicalExpressions": { + "type": "boolean" + }, + "ignoreTernaryTests": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean; + ignoreConditionalTests?: boolean; + ignoreMixedLogicalExpressions?: boolean; + ignoreTernaryTests?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-optional-chain.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-optional-chain.shot new file mode 100644 index 00000000000..4f5b7623fd8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-optional-chain.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-optional-chain 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly-parameter-types.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly-parameter-types.shot new file mode 100644 index 00000000000..332e54184b3 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly-parameter-types.shot @@ -0,0 +1,147 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-readonly-parameter-types 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allow": { + "items": { + "oneOf": [ + { + "type": "string" + }, + { + "additionalProperties": false, + "properties": { + "from": { + "enum": ["file"], + "type": "string" + }, + "name": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + } + ] + }, + "path": { + "type": "string" + } + }, + "required": ["from", "name"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "from": { + "enum": ["lib"], + "type": "string" + }, + "name": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + } + ] + } + }, + "required": ["from", "name"], + "type": "object" + }, + { + "additionalProperties": false, + "properties": { + "from": { + "enum": ["package"], + "type": "string" + }, + "name": { + "oneOf": [ + { + "type": "string" + }, + { + "items": { + "type": "string" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + } + ] + }, + "package": { + "type": "string" + } + }, + "required": ["from", "name", "package"], + "type": "object" + } + ] + }, + "type": "array" + }, + "checkParameterProperties": { + "type": "boolean" + }, + "ignoreInferredTypes": { + "type": "boolean" + }, + "treatMethodsAsReadonly": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allow?: ( + | { + from: 'file'; + name: [string, ...string[]] | string; + path?: string; + } + | { + from: 'lib'; + name: [string, ...string[]] | string; + } + | { + from: 'package'; + name: [string, ...string[]] | string; + package: string; + } + | string + )[]; + checkParameterProperties?: boolean; + ignoreInferredTypes?: boolean; + treatMethodsAsReadonly?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly.shot new file mode 100644 index 00000000000..34e4a22204a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-readonly.shot @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-readonly 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "onlyInlineLambdas": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + onlyInlineLambdas?: boolean; + }, +]; +" +`; 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 new file mode 100644 index 00000000000..d3aa7a0217f --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-reduce-type-parameter.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-reduce-type-parameter 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..7a34c379269 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-regexp-exec.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-regexp-exec 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..043d5a211b5 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-return-this-type.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-return-this-type 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/prefer-string-starts-ends-with.shot b/packages/eslint-plugin/tests/schema-snapshots/prefer-string-starts-ends-with.shot new file mode 100644 index 00000000000..d05465a64ca --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-string-starts-ends-with.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-string-starts-ends-with 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +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 new file mode 100644 index 00000000000..44fe6704b60 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/prefer-ts-expect-error.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes prefer-ts-expect-error 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/promise-function-async.shot b/packages/eslint-plugin/tests/schema-snapshots/promise-function-async.shot new file mode 100644 index 00000000000..c073af42009 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/promise-function-async.shot @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes promise-function-async 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowAny": { + "description": "Whether to consider \`any\` and \`unknown\` to be Promises.", + "type": "boolean" + }, + "allowedPromiseNames": { + "description": "Any extra names of classes or interfaces to be considered Promises.", + "items": { + "type": "string" + }, + "type": "array" + }, + "checkArrowFunctions": { + "type": "boolean" + }, + "checkFunctionDeclarations": { + "type": "boolean" + }, + "checkFunctionExpressions": { + "type": "boolean" + }, + "checkMethodDeclarations": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to consider \`any\` and \`unknown\` to be Promises. */ + allowAny?: boolean; + /** Any extra names of classes or interfaces to be considered Promises. */ + allowedPromiseNames?: string[]; + checkArrowFunctions?: boolean; + checkFunctionDeclarations?: boolean; + checkFunctionExpressions?: boolean; + checkMethodDeclarations?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/quotes.shot b/packages/eslint-plugin/tests/schema-snapshots/quotes.shot new file mode 100644 index 00000000000..bf7bb170ed0 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/quotes.shot @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes quotes 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["backtick", "double", "single"] + }, + { + "anyOf": [ + { + "enum": ["avoid-escape"] + }, + { + "additionalProperties": false, + "properties": { + "allowTemplateLiterals": { + "type": "boolean" + }, + "avoidEscape": { + "type": "boolean" + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + 'backtick' | 'double' | 'single', + ( + | 'avoid-escape' + | { + allowTemplateLiterals?: boolean; + avoidEscape?: boolean; + } + ), +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/require-array-sort-compare.shot b/packages/eslint-plugin/tests/schema-snapshots/require-array-sort-compare.shot new file mode 100644 index 00000000000..938d7b6887a --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/require-array-sort-compare.shot @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes require-array-sort-compare 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "ignoreStringArrays": { + "description": "Whether to ignore arrays in which all elements are strings.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to ignore arrays in which all elements are strings. */ + ignoreStringArrays?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/require-await.shot b/packages/eslint-plugin/tests/schema-snapshots/require-await.shot new file mode 100644 index 00000000000..61fb0467b29 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/require-await.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes require-await 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/restrict-plus-operands.shot b/packages/eslint-plugin/tests/schema-snapshots/restrict-plus-operands.shot new file mode 100644 index 00000000000..a1727d55fca --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/restrict-plus-operands.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes restrict-plus-operands 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowAny": { + "description": "Whether to allow \`any\` typed values.", + "type": "boolean" + }, + "checkCompoundAssignments": { + "description": "Whether to check compound assignments such as \`+=\`.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow \`any\` typed values. */ + allowAny?: boolean; + /** Whether to check compound assignments such as \`+=\`. */ + checkCompoundAssignments?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/restrict-template-expressions.shot b/packages/eslint-plugin/tests/schema-snapshots/restrict-template-expressions.shot new file mode 100644 index 00000000000..a5af1c8d063 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/restrict-template-expressions.shot @@ -0,0 +1,59 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes restrict-template-expressions 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "allowAny": { + "description": "Whether to allow \`any\` typed values in template expressions.", + "type": "boolean" + }, + "allowBoolean": { + "description": "Whether to allow \`boolean\` typed values in template expressions.", + "type": "boolean" + }, + "allowNever": { + "description": "Whether to allow \`never\` typed values in template expressions.", + "type": "boolean" + }, + "allowNullish": { + "description": "Whether to allow \`nullish\` typed values in template expressions.", + "type": "boolean" + }, + "allowNumber": { + "description": "Whether to allow \`number\` typed values in template expressions.", + "type": "boolean" + }, + "allowRegExp": { + "description": "Whether to allow \`regexp\` typed values in template expressions.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to allow \`any\` typed values in template expressions. */ + allowAny?: boolean; + /** Whether to allow \`boolean\` typed values in template expressions. */ + allowBoolean?: boolean; + /** Whether to allow \`never\` typed values in template expressions. */ + allowNever?: boolean; + /** Whether to allow \`nullish\` typed values in template expressions. */ + allowNullish?: boolean; + /** Whether to allow \`number\` typed values in template expressions. */ + allowNumber?: boolean; + /** Whether to allow \`regexp\` typed values in template expressions. */ + allowRegExp?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/return-await.shot b/packages/eslint-plugin/tests/schema-snapshots/return-await.shot new file mode 100644 index 00000000000..7d0a6d5e142 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/return-await.shot @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes return-await 1`] = ` +" +# SCHEMA: + +[ + { + "enum": ["always", "in-try-catch", "never"] + } +] + + +# TYPES: + +type Options = ['always' | 'in-try-catch' | 'never']; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/semi.shot b/packages/eslint-plugin/tests/schema-snapshots/semi.shot new file mode 100644 index 00000000000..cd452fe0cf8 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/semi.shot @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes semi 1`] = ` +" +# SCHEMA: + +{ + "anyOf": [ + { + "items": [ + { + "enum": ["never"] + }, + { + "additionalProperties": false, + "properties": { + "beforeStatementContinuationChars": { + "enum": ["always", "any", "never"] + } + }, + "type": "object" + } + ], + "maxItems": 2, + "minItems": 0, + "type": "array" + }, + { + "items": [ + { + "enum": ["always"] + }, + { + "additionalProperties": false, + "properties": { + "omitLastInOneLineBlock": { + "type": "boolean" + } + }, + "type": "object" + } + ], + "maxItems": 2, + "minItems": 0, + "type": "array" + } + ] +} + + +# TYPES: + +type Options = + | [] + | ['always'] + | ['never'] + | [ + 'always', + { + omitLastInOneLineBlock?: boolean; + }, + ] + | [ + 'never', + { + beforeStatementContinuationChars?: 'always' | 'any' | 'never'; + }, + ]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/sort-type-constituents.shot b/packages/eslint-plugin/tests/schema-snapshots/sort-type-constituents.shot new file mode 100644 index 00000000000..d84cff0e09d --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/sort-type-constituents.shot @@ -0,0 +1,71 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes sort-type-constituents 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "checkIntersections": { + "description": "Whether to check intersection types.", + "type": "boolean" + }, + "checkUnions": { + "description": "Whether to check union types.", + "type": "boolean" + }, + "groupOrder": { + "description": "Ordering of the groups.", + "items": { + "enum": [ + "conditional", + "function", + "import", + "intersection", + "keyword", + "literal", + "named", + "nullish", + "object", + "operator", + "tuple", + "union" + ], + "type": "string" + }, + "type": "array" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to check intersection types. */ + checkIntersections?: boolean; + /** Whether to check union types. */ + checkUnions?: boolean; + /** Ordering of the groups. */ + groupOrder?: ( + | 'conditional' + | 'function' + | 'import' + | 'intersection' + | 'keyword' + | 'literal' + | 'named' + | 'nullish' + | 'object' + | 'operator' + | 'tuple' + | 'union' + )[]; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/space-before-blocks.shot b/packages/eslint-plugin/tests/schema-snapshots/space-before-blocks.shot new file mode 100644 index 00000000000..96faea20aa2 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/space-before-blocks.shot @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes space-before-blocks 1`] = ` +" +# SCHEMA: + +[ + { + "oneOf": [ + { + "enum": ["always", "never"] + }, + { + "additionalProperties": false, + "properties": { + "classes": { + "enum": ["always", "never", "off"] + }, + "functions": { + "enum": ["always", "never", "off"] + }, + "keywords": { + "enum": ["always", "never", "off"] + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | 'always' + | 'never' + | { + classes?: 'always' | 'never' | 'off'; + functions?: 'always' | 'never' | 'off'; + keywords?: 'always' | 'never' | 'off'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/space-before-function-paren.shot b/packages/eslint-plugin/tests/schema-snapshots/space-before-function-paren.shot new file mode 100644 index 00000000000..67ca6e24371 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/space-before-function-paren.shot @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes space-before-function-paren 1`] = ` +" +# SCHEMA: + +[ + { + "oneOf": [ + { + "enum": ["always", "never"] + }, + { + "additionalProperties": false, + "properties": { + "anonymous": { + "enum": ["always", "ignore", "never"] + }, + "asyncArrow": { + "enum": ["always", "ignore", "never"] + }, + "named": { + "enum": ["always", "ignore", "never"] + } + }, + "type": "object" + } + ] + } +] + + +# TYPES: + +type Options = [ + | 'always' + | 'never' + | { + anonymous?: 'always' | 'ignore' | 'never'; + asyncArrow?: 'always' | 'ignore' | 'never'; + named?: 'always' | 'ignore' | 'never'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/space-infix-ops.shot b/packages/eslint-plugin/tests/schema-snapshots/space-infix-ops.shot new file mode 100644 index 00000000000..92fd6d7dd04 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/space-infix-ops.shot @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes space-infix-ops 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "int32Hint": { + "default": false, + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + int32Hint?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/strict-boolean-expressions.shot b/packages/eslint-plugin/tests/schema-snapshots/strict-boolean-expressions.shot new file mode 100644 index 00000000000..140b7e556a4 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/strict-boolean-expressions.shot @@ -0,0 +1,60 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes strict-boolean-expressions 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "allowAny": { + "type": "boolean" + }, + "allowNullableBoolean": { + "type": "boolean" + }, + "allowNullableEnum": { + "type": "boolean" + }, + "allowNullableNumber": { + "type": "boolean" + }, + "allowNullableObject": { + "type": "boolean" + }, + "allowNullableString": { + "type": "boolean" + }, + "allowNumber": { + "type": "boolean" + }, + "allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing": { + "type": "boolean" + }, + "allowString": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + allowAny?: boolean; + allowNullableBoolean?: boolean; + allowNullableEnum?: boolean; + allowNullableNumber?: boolean; + allowNullableObject?: boolean; + allowNullableString?: boolean; + allowNumber?: boolean; + allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean; + allowString?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/switch-exhaustiveness-check.shot b/packages/eslint-plugin/tests/schema-snapshots/switch-exhaustiveness-check.shot new file mode 100644 index 00000000000..b9d9916dc42 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/switch-exhaustiveness-check.shot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes switch-exhaustiveness-check 1`] = ` +" +# SCHEMA: + +[] + + +# TYPES: + +/** No options declared */ +type Options = [];" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/triple-slash-reference.shot b/packages/eslint-plugin/tests/schema-snapshots/triple-slash-reference.shot new file mode 100644 index 00000000000..c5b400712bf --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/triple-slash-reference.shot @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes triple-slash-reference 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "lib": { + "enum": ["always", "never"] + }, + "path": { + "enum": ["always", "never"] + }, + "types": { + "enum": ["always", "never", "prefer-import"] + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + lib?: 'always' | 'never'; + path?: 'always' | 'never'; + types?: 'always' | 'never' | 'prefer-import'; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/type-annotation-spacing.shot b/packages/eslint-plugin/tests/schema-snapshots/type-annotation-spacing.shot new file mode 100644 index 00000000000..5fc608ca4bc --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/type-annotation-spacing.shot @@ -0,0 +1,83 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes type-annotation-spacing 1`] = ` +" +# SCHEMA: + +[ + { + "$defs": { + "spacingConfig": { + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + } + }, + "type": "object" + } + }, + "additionalProperties": false, + "properties": { + "after": { + "type": "boolean" + }, + "before": { + "type": "boolean" + }, + "overrides": { + "additionalProperties": false, + "properties": { + "arrow": { + "$ref": "#/items/0/$defs/spacingConfig" + }, + "colon": { + "$ref": "#/items/0/$defs/spacingConfig" + }, + "parameter": { + "$ref": "#/items/0/$defs/spacingConfig" + }, + "property": { + "$ref": "#/items/0/$defs/spacingConfig" + }, + "returnType": { + "$ref": "#/items/0/$defs/spacingConfig" + }, + "variable": { + "$ref": "#/items/0/$defs/spacingConfig" + } + }, + "type": "object" + } + }, + "type": "object" + } +] + + +# TYPES: + +type SpacingConfig = { + after?: boolean; + before?: boolean; +}; + +type Options = [ + { + after?: boolean; + before?: boolean; + overrides?: { + arrow?: SpacingConfig; + colon?: SpacingConfig; + parameter?: SpacingConfig; + property?: SpacingConfig; + returnType?: SpacingConfig; + variable?: SpacingConfig; + }; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/typedef.shot b/packages/eslint-plugin/tests/schema-snapshots/typedef.shot new file mode 100644 index 00000000000..d08f373ab79 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/typedef.shot @@ -0,0 +1,55 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes typedef 1`] = ` +" +# SCHEMA: + +[ + { + "properties": { + "arrayDestructuring": { + "type": "boolean" + }, + "arrowParameter": { + "type": "boolean" + }, + "memberVariableDeclaration": { + "type": "boolean" + }, + "objectDestructuring": { + "type": "boolean" + }, + "parameter": { + "type": "boolean" + }, + "propertyDeclaration": { + "type": "boolean" + }, + "variableDeclaration": { + "type": "boolean" + }, + "variableDeclarationIgnoreFunction": { + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + arrayDestructuring?: boolean; + arrowParameter?: boolean; + memberVariableDeclaration?: boolean; + objectDestructuring?: boolean; + parameter?: boolean; + propertyDeclaration?: boolean; + variableDeclaration?: boolean; + variableDeclarationIgnoreFunction?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/unbound-method.shot b/packages/eslint-plugin/tests/schema-snapshots/unbound-method.shot new file mode 100644 index 00000000000..4ce3ddd4a51 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/unbound-method.shot @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes unbound-method 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreStatic": { + "description": "Whether to skip checking whether \`static\` methods are correctly bound.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether to skip checking whether \`static\` methods are correctly bound. */ + ignoreStatic?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schema-snapshots/unified-signatures.shot b/packages/eslint-plugin/tests/schema-snapshots/unified-signatures.shot new file mode 100644 index 00000000000..39b61b6dde7 --- /dev/null +++ b/packages/eslint-plugin/tests/schema-snapshots/unified-signatures.shot @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Rule schemas should be convertible to TS types for documentation purposes unified-signatures 1`] = ` +" +# SCHEMA: + +[ + { + "additionalProperties": false, + "properties": { + "ignoreDifferentlyNamedParameters": { + "description": "Whether two parameters with different names at the same index should be considered different even if their types are the same.", + "type": "boolean" + } + }, + "type": "object" + } +] + + +# TYPES: + +type Options = [ + { + /** Whether two parameters with different names at the same index should be considered different even if their types are the same. */ + ignoreDifferentlyNamedParameters?: boolean; + }, +]; +" +`; diff --git a/packages/eslint-plugin/tests/schemas.test.ts b/packages/eslint-plugin/tests/schemas.test.ts new file mode 100644 index 00000000000..19cf8280c5b --- /dev/null +++ b/packages/eslint-plugin/tests/schemas.test.ts @@ -0,0 +1,155 @@ +import 'jest-specific-snapshot'; + +import { compile } from '@typescript-eslint/rule-schema-to-typescript-types'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; +import fs, { mkdirSync } from 'fs'; +import path from 'path'; +import { format, resolveConfig } from 'prettier'; + +import rules from '../src/rules/index'; + +const snapshotFolder = path.resolve(__dirname, 'schema-snapshots'); +try { + mkdirSync(snapshotFolder); +} catch { + // ignore failure as it means it already exists probably +} + +const prettierConfigJson = { + ...(resolveConfig.sync(__filename) ?? {}), + filepath: path.join(__dirname, 'schema.json'), +}; + +const SKIPPED_RULES_FOR_TYPE_GENERATION = new Set(['indent']); +// Set this to a rule name to only run that rule +const ONLY = ''; + +describe('Rule schemas should be convertible to TS types for documentation purposes', () => { + for (const [ruleName, ruleDef] of Object.entries(rules)) { + if (SKIPPED_RULES_FOR_TYPE_GENERATION.has(ruleName)) { + // eslint-disable-next-line jest/no-disabled-tests -- intentional skip for documentation purposes + it.skip(ruleName, () => {}); + continue; + } + + (ruleName === ONLY ? it.only : it)(ruleName, () => { + const schemaString = format( + JSON.stringify( + ruleDef.meta.schema, + (k, v: unknown) => { + if (k === 'enum' && Array.isArray(v)) { + // sort enum arrays for consistency regardless of source order + v.sort(); + } else if ( + typeof v === 'object' && + v != null && + !Array.isArray(v) + ) { + // sort properties for consistency regardless of source order + return Object.fromEntries( + Object.entries(v).sort(([a], [b]) => a.localeCompare(b)), + ); + } + return v; + }, + // use the indent feature as it forces all objects to be multiline + // if we don't do this then prettier decides what objects are multiline + // based on what fits on a line - which looks less consistent + // and makes changes harder to understand as you can have multiple + // changes per line, or adding a prop can restructure an object + 2, + ), + prettierConfigJson, + ); + const compilationResult = compile(ruleDef.meta.schema); + + expect( + [ + '', + '# SCHEMA:', + '', + schemaString, + '', + '# TYPES:', + '', + compilationResult, + ].join('\n'), + ).toMatchSpecificSnapshot(path.join(snapshotFolder, `${ruleName}.shot`)); + }); + } +}); + +test('There should be no old snapshots for rules that have been deleted', () => { + const files = fs.readdirSync(snapshotFolder); + const names = new Set( + Object.keys(rules) + .filter(k => !SKIPPED_RULES_FOR_TYPE_GENERATION.has(k)) + .map(k => `${k}.shot`), + ); + + for (const file of files) { + expect(names).toContain(file); + } +}); + +const VALID_SCHEMA_PROPS = new Set([ + '$defs', + '$ref', + '$schema', + 'additionalItems', + 'additionalProperties', + 'allOf', + 'anyOf', + 'default', + 'definitions', + 'dependencies', + 'description', + 'enum', + 'exclusiveMaximum', + 'exclusiveMinimum', + 'extends', + 'format', + 'id', + 'items', + 'maximum', + 'maxItems', + 'maxLength', + 'maxProperties', + 'minimum', + 'minItems', + 'minLength', + 'minProperties', + 'multipleOf', + 'not', + 'oneOf', + 'pattern', + 'patternProperties', + 'properties', + 'required', + 'title', + 'type', + 'uniqueItems', +] satisfies (keyof JSONSchema4)[]); +describe('Rules should only define valid keys on schemas', () => { + for (const [ruleName, ruleDef] of Object.entries(rules)) { + (ruleName === ONLY ? it.only : it)(ruleName, () => { + JSON.stringify(ruleDef.meta.schema, (key, value: unknown) => { + if (key === '') { + // the root object will have key "" + return value; + } + if (key === '$defs' || key === 'definitions' || key === 'properties') { + // definition keys and property keys should not be validated, only the values + return Object.values(value as object); + } + if (parseInt(key).toString() === key) { + // hack to detect arrays as JSON.stringify will traverse them and stringify the number + return value; + } + + expect(VALID_SCHEMA_PROPS).toContain(key); + return value; + }); + }); + } +}); diff --git a/packages/eslint-plugin/tsconfig.json b/packages/eslint-plugin/tsconfig.json index fa20841493f..ae5a5e0f988 100644 --- a/packages/eslint-plugin/tsconfig.json +++ b/packages/eslint-plugin/tsconfig.json @@ -8,6 +8,7 @@ "references": [ { "path": "../utils/tsconfig.build.json" }, { "path": "../parser/tsconfig.build.json" }, + { "path": "../rule-schema-to-typescript-types/tsconfig.build.json" }, { "path": "../scope-manager/tsconfig.build.json" }, { "path": "../type-utils/tsconfig.build.json" } ] diff --git a/packages/repo-tools/package.json b/packages/repo-tools/package.json index 1acd3ff50fa..6dbb0797812 100644 --- a/packages/repo-tools/package.json +++ b/packages/repo-tools/package.json @@ -3,6 +3,7 @@ "version": "5.59.0", "private": true, "scripts": { + "build": "tsc -b tsconfig.build.json", "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", "generate-contributors": "tsx ./src/generate-contributors.ts", "generate-sponsors": "tsx ./src/generate-sponsors.ts", diff --git a/packages/repo-tools/tsconfig.build.json b/packages/repo-tools/tsconfig.build.json index 2f504b292b0..b9ac3e1b977 100644 --- a/packages/repo-tools/tsconfig.build.json +++ b/packages/repo-tools/tsconfig.build.json @@ -1,13 +1,11 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - // specifically disable declarations for the plugin - "declaration": false, - "declarationMap": false, + "composite": true, "outDir": "./dist", "rootDir": "./src", "resolveJsonModule": true }, - "include": ["src", "tests", "typings"], + "include": ["src", "typings"], "references": [] } diff --git a/packages/repo-tools/tsconfig.json b/packages/repo-tools/tsconfig.json index 736e7fb6dc1..06b94d057fa 100644 --- a/packages/repo-tools/tsconfig.json +++ b/packages/repo-tools/tsconfig.json @@ -4,6 +4,6 @@ "composite": false, "rootDir": "." }, - "include": ["src", "typings"], + "include": ["src", "tests", "typings"], "references": [] } diff --git a/packages/rule-schema-to-typescript-types/README.md b/packages/rule-schema-to-typescript-types/README.md new file mode 100644 index 00000000000..25f004c77a1 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/README.md @@ -0,0 +1,9 @@ +# `@typescript-eslint/rule-schema-to-typescript-types` + +> Tool for generating TypeScript type definitions from a rule's options schema + +## ✋ Internal Package + +This is an _internal package_ to the [typescript-eslint monorepo](https://github.com/typescript-eslint/typescript-eslint). + +👉 See **https://typescript-eslint.io** for docs on typescript-eslint. diff --git a/packages/rule-schema-to-typescript-types/jest.config.js b/packages/rule-schema-to-typescript-types/jest.config.js new file mode 100644 index 00000000000..209d055cc65 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/jest.config.js @@ -0,0 +1,8 @@ +'use strict'; + +// @ts-check +/** @type {import('@jest/types').Config.InitialOptions} */ +module.exports = { + ...require('../../jest.config.base.js'), + passWithNoTests: true, +}; diff --git a/packages/rule-schema-to-typescript-types/package.json b/packages/rule-schema-to-typescript-types/package.json new file mode 100644 index 00000000000..a1fd1d7ea4b --- /dev/null +++ b/packages/rule-schema-to-typescript-types/package.json @@ -0,0 +1,48 @@ +{ + "name": "@typescript-eslint/rule-schema-to-typescript-types", + "version": "5.59.0", + "private": true, + "type": "commonjs", + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./dist/index.js" + }, + "./package.json": "./package.json" + }, + "engines": { + "node": "^14.18.0 || ^16.0.0 || >=18.0.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/typescript-eslint/typescript-eslint.git", + "directory": "packages/rule-schema-to-typescript-types" + }, + "bugs": { + "url": "https://github.com/typescript-eslint/typescript-eslint/issues" + }, + "license": "MIT", + "scripts": { + "build": "tsc -b tsconfig.build.json", + "format": "prettier --write \"./**/*.{ts,mts,cts,tsx,js,mjs,cjs,jsx,json,md,css}\" --ignore-path ../../.prettierignore", + "generate-contributors": "tsx ./src/generate-contributors.ts", + "generate-sponsors": "tsx ./src/generate-sponsors.ts", + "lint": "nx lint", + "postinstall-script": "tsx ./src/postinstall.ts", + "test": "jest --coverage", + "typecheck": "tsc -p tsconfig.json --noEmit" + }, + "dependencies": { + "@types/prettier": "*", + "@typescript-eslint/type-utils": "5.59.0", + "natural-compare": "^1.4.0", + "prettier": "*" + }, + "devDependencies": { + "@types/natural-compare": "*" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } +} diff --git a/packages/rule-schema-to-typescript-types/project.json b/packages/rule-schema-to-typescript-types/project.json new file mode 100644 index 00000000000..e0566604c1d --- /dev/null +++ b/packages/rule-schema-to-typescript-types/project.json @@ -0,0 +1,18 @@ +{ + "name": "rule-schema-to-typescript-types", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "type": "library", + "implicitDependencies": [], + "targets": { + "lint": { + "executor": "@nrwl/linter:eslint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": [ + "packages/rule-schema-to-typescript-types/**/*.{mts,cts,ts,tsx}" + ], + "ignorePath": ".eslintignore" + } + } + } +} diff --git a/packages/rule-schema-to-typescript-types/src/errors.ts b/packages/rule-schema-to-typescript-types/src/errors.ts new file mode 100644 index 00000000000..aa3168af5f9 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/errors.ts @@ -0,0 +1,17 @@ +export class NotSupportedError extends Error { + constructor(thing: string, target: unknown) { + super( + `Generating a type for ${thing} is not currently supported:\n${JSON.stringify( + target, + null, + 2, + )}`, + ); + } +} + +export class UnexpectedError extends Error { + constructor(error: string, target: unknown) { + super(`Unexpected Error: ${error}:\n${JSON.stringify(target, null, 2)}`); + } +} diff --git a/packages/rule-schema-to-typescript-types/src/generateArrayType.ts b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts new file mode 100644 index 00000000000..cece1fa4025 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/generateArrayType.ts @@ -0,0 +1,153 @@ +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; + +import { NotSupportedError, UnexpectedError } from './errors'; +import { generateType } from './generateType'; +import { getCommentLines } from './getCommentLines'; +import { isArray } from './isArray'; +import type { ArrayAST, AST, RefMap, TupleAST, UnionAST } from './types'; + +/** + * If there are more than 20 tuple items then we will not make it a tuple type + * and instead will just make it an array type for brevity + */ +const MAX_ITEMS_TO_TUPLIZE = 20; + +export function generateArrayType( + schema: JSONSchema4, + refMap: RefMap, +): ArrayAST | TupleAST | UnionAST { + if (!schema.items) { + // it's technically valid to declare things like {type: 'array'} -> any[] + // but that's obviously dumb and loose so let's not even bother with it + throw new UnexpectedError('Unexpected missing items', schema); + } + if (schema.items && !isArray(schema.items) && schema.additionalItems) { + throw new NotSupportedError( + 'singlely-typed array with additionalItems', + schema, + ); + } + + const commentLines = getCommentLines(schema); + + const minItems = schema.minItems ?? 0; + const maxItems = + schema.maxItems != null && schema.maxItems < MAX_ITEMS_TO_TUPLIZE + ? schema.maxItems + : -1; + const hasMinItems = minItems > 0; + const hasMaxItems = maxItems >= 0; + + let items: JSONSchema4[]; + let spreadItemSchema: JSONSchema4 | null = null; + + if (!isArray(schema.items)) { + if (hasMinItems || hasMaxItems) { + // treat as a tuple + items = Array( + (hasMaxItems && maxItems) || minItems || 0, + ).fill(schema.items); + if (!hasMaxItems) { + spreadItemSchema = + typeof schema.additionalItems === 'object' + ? schema.additionalItems + : schema.items; + } + } else { + // treat as an array type + return { + type: 'array', + elementType: generateType(schema.items, refMap), + commentLines, + }; + } + } else { + // treat as a tuple + items = schema.items; + if (hasMaxItems && items.length < maxItems) { + spreadItemSchema = + typeof schema.additionalItems === 'object' + ? schema.additionalItems + : { type: 'any' }; + } + } + + // quick validation so we generate sensible types + if (hasMaxItems && maxItems < items.length) { + throw new UnexpectedError( + `maxItems (${maxItems}) is smaller than the number of items schemas provided (${items.length})`, + schema, + ); + } + if (maxItems > items.length && spreadItemSchema == null) { + throw new UnexpectedError( + 'maxItems is larger than the number of items schemas, but there was not an additionalItems schema provided', + schema, + ); + } + + const itemTypes = items.map(i => generateType(i, refMap)); + const spreadItem = + spreadItemSchema == null ? null : generateType(spreadItemSchema, refMap); + + if (itemTypes.length > minItems) { + /* + if there are more items than the min, we return a union of tuples instead of + using the optional element operator. This is done because it is more type-safe. + + // optional element operator + type A = [string, string?, string?] + const a: A = ['a', undefined, 'c'] // no error + + // union of tuples + type B = [string] | [string, string] | [string, string, string] + const b: B = ['a', undefined, 'c'] // TS error + */ + const cumulativeTypesList = itemTypes.slice(0, minItems); + const typesToUnion: AST[] = []; + if (cumulativeTypesList.length > 0) { + // actually has minItems, so add the initial state + typesToUnion.push(createTupleType(cumulativeTypesList)); + } else { + // no minItems means it's acceptable to have an empty tuple type + typesToUnion.push(createTupleType([])); + } + + for (let i = minItems; i < itemTypes.length; i += 1) { + cumulativeTypesList.push(itemTypes[i]); + + if (i === itemTypes.length - 1) { + // only the last item in the union should have the spread parameter + typesToUnion.push(createTupleType(cumulativeTypesList, spreadItem)); + } else { + typesToUnion.push(createTupleType(cumulativeTypesList)); + } + } + + return { + type: 'union', + elements: typesToUnion, + commentLines, + }; + } + + return { + type: 'tuple', + elements: itemTypes, + spreadType: spreadItem, + commentLines, + }; +} + +function createTupleType( + elements: AST[], + spreadType: AST | null = null, +): TupleAST { + return { + type: 'tuple', + // clone the array because we know we'll keep mutating it + elements: [...elements], + spreadType, + commentLines: [], + }; +} diff --git a/packages/rule-schema-to-typescript-types/src/generateObjectType.ts b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts new file mode 100644 index 00000000000..9ff4b928dcd --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/generateObjectType.ts @@ -0,0 +1,50 @@ +import { requiresQuoting } from '@typescript-eslint/type-utils'; +import type { JSONSchema4 } from 'json-schema'; + +import { generateType } from './generateType'; +import { getCommentLines } from './getCommentLines'; +import { isArray } from './isArray'; +import type { AST, ObjectAST, RefMap } from './types'; + +export function generateObjectType( + schema: JSONSchema4, + refMap: RefMap, +): ObjectAST { + const commentLines = getCommentLines(schema); + + let indexSignature: AST | null = null; + if (schema.additionalProperties === true) { + indexSignature = { + type: 'type-reference', + typeName: 'unknown', + commentLines: [], + }; + } else if (schema.additionalProperties) { + const indexSigType = generateType(schema.additionalProperties, refMap); + indexSignature = indexSigType; + } + + const properties: ObjectAST['properties'] = []; + const required = new Set(isArray(schema.required) ? schema.required : []); + if (schema.properties) { + const propertyDefs = Object.entries(schema.properties); + for (const [propName, propSchema] of propertyDefs) { + const propType = generateType(propSchema, refMap); + const sanitisedPropName = requiresQuoting(propName) + ? `'${propName}'` + : propName; + properties.push({ + name: sanitisedPropName, + optional: !required.has(propName), + type: propType, + }); + } + } + + return { + type: 'object', + properties, + indexSignature, + commentLines, + }; +} diff --git a/packages/rule-schema-to-typescript-types/src/generateType.ts b/packages/rule-schema-to-typescript-types/src/generateType.ts new file mode 100644 index 00000000000..d6c0efa2890 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/generateType.ts @@ -0,0 +1,124 @@ +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; + +import { NotSupportedError, UnexpectedError } from './errors'; +import { generateArrayType } from './generateArrayType'; +import { generateObjectType } from './generateObjectType'; +import { generateUnionType } from './generateUnionType'; +import { getCommentLines } from './getCommentLines'; +import { isArray } from './isArray'; +import type { AST, RefMap } from './types'; + +// keywords we probably should support but currently do not support +const UNSUPPORTED_KEYWORDS = new Set([ + 'allOf', + 'dependencies', + 'extends', + 'maxProperties', + 'minProperties', + 'multipleOf', + 'not', + 'patternProperties', +] satisfies (keyof JSONSchema4)[]); + +export function generateType(schema: JSONSchema4, refMap: RefMap): AST { + const unsupportedProps = Object.keys(schema).filter(key => + UNSUPPORTED_KEYWORDS.has(key), + ); + if (unsupportedProps.length > 0) { + throw new NotSupportedError(unsupportedProps.join(','), schema); + } + + const commentLines = getCommentLines(schema); + + if (schema.$ref) { + const refName = refMap.get(schema.$ref); + if (refName == null) { + throw new UnexpectedError( + `Could not find definition for $ref ${ + schema.$ref + }.\nAvailable refs:\n${Array.from(refMap.keys()).join('\n')})`, + schema, + ); + } + return { + type: 'type-reference', + typeName: refName, + commentLines, + }; + } + if (schema.enum) { + return { + ...generateUnionType(schema.enum, refMap), + commentLines, + }; + } + if (schema.anyOf) { + return { + // a union isn't *TECHNICALLY* correct - technically anyOf is actually + // anyOf: [T, U, V] -> T | U | V | T & U | T & V | U & V + // in practice though it is most used to emulate a oneOf + ...generateUnionType(schema.anyOf, refMap), + commentLines, + }; + } + if (schema.oneOf) { + return { + ...generateUnionType(schema.oneOf, refMap), + commentLines, + }; + } + + if (isArray(schema.type)) { + throw new NotSupportedError('schemas with multiple types', schema); + } + if (schema.type == null) { + throw new NotSupportedError( + 'untyped schemas without one of [$ref, enum, oneOf]', + schema, + ); + } + + switch (schema.type) { + case 'any': + return { + type: 'type-reference', + typeName: 'unknown', + commentLines, + }; + + case 'null': + return { + type: 'type-reference', + typeName: 'null', + commentLines, + }; + + case 'number': + case 'string': + return { + type: 'literal', + code: schema.type, + commentLines, + }; + + case 'array': + return generateArrayType(schema, refMap); + + case 'boolean': + return { + type: 'type-reference', + typeName: 'boolean', + commentLines, + }; + + case 'integer': + return { + type: 'type-reference', + typeName: 'number', + commentLines, + }; + + case 'object': + return generateObjectType(schema, refMap); + } +} diff --git a/packages/rule-schema-to-typescript-types/src/generateUnionType.ts b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts new file mode 100644 index 00000000000..9ec9dc3b7bd --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/generateUnionType.ts @@ -0,0 +1,53 @@ +import type { + JSONSchema4, + JSONSchema4Type, +} from '@typescript-eslint/utils/json-schema'; + +import { NotSupportedError } from './errors'; +import { generateType } from './generateType'; +import type { AST, RefMap, UnionAST } from './types'; + +export function generateUnionType( + members: (JSONSchema4 | JSONSchema4Type)[], + refMap: RefMap, +): UnionAST { + const elements: AST[] = []; + + for (const memberSchema of members) { + elements.push( + ((): AST => { + switch (typeof memberSchema) { + case 'string': + return { + type: 'literal', + code: `'${memberSchema.replace(/'/g, "\\'")}'`, + commentLines: [], + }; + + case 'number': + case 'boolean': + return { + type: 'literal', + code: `${memberSchema}`, + commentLines: [], + }; + + case 'object': + if (memberSchema == null) { + throw new NotSupportedError('null in an enum', memberSchema); + } + if (Array.isArray(memberSchema)) { + throw new NotSupportedError('array in an enum', memberSchema); + } + return generateType(memberSchema, refMap); + } + })(), + ); + } + + return { + type: 'union', + elements, + commentLines: [], + }; +} diff --git a/packages/rule-schema-to-typescript-types/src/getCommentLines.ts b/packages/rule-schema-to-typescript-types/src/getCommentLines.ts new file mode 100644 index 00000000000..675bf374c22 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/getCommentLines.ts @@ -0,0 +1,9 @@ +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; + +export function getCommentLines(schema: JSONSchema4): string[] { + const lines: string[] = []; + if (schema.description) { + lines.push(schema.description); + } + return lines; +} diff --git a/packages/rule-schema-to-typescript-types/src/index.ts b/packages/rule-schema-to-typescript-types/src/index.ts new file mode 100644 index 00000000000..3100f122f2d --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/index.ts @@ -0,0 +1,98 @@ +import type { JSONSchema4 } from 'json-schema'; +import path from 'path'; +import { format as prettierFormat, resolveConfig } from 'prettier'; + +import { generateType } from './generateType'; +import { isArray } from './isArray'; +import { optimizeAST } from './optimizeAST'; +import { printTypeAlias } from './printAST'; +import type { AST } from './types'; + +const prettierConfig = { + ...(resolveConfig.sync(__filename) ?? {}), + filepath: path.join(__dirname, 'schema.ts'), +}; + +export function compile( + schemaIn: JSONSchema4 | readonly JSONSchema4[], +): string { + const { schema, isArraySchema } = (() => { + if (isArray(schemaIn)) { + return { + schema: schemaIn, + isArraySchema: true, + }; + } + return { + schema: [schemaIn], + isArraySchema: false, + }; + })(); + + if (schema.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); + refTypes.push(...result.refTypes); + types.push(result.type); + } + + const optionsType = isArraySchema + ? printTypeAlias('Options', { + type: 'tuple', + elements: types, + spreadType: null, + commentLines: [], + }) + : printTypeAlias('Options', types[0]); + + const unformattedCode = [...refTypes, optionsType].join('\n\n'); + try { + return prettierFormat(unformattedCode, prettierConfig); + } catch (e) { + if (e instanceof Error) { + e.message = e.message + `\n\nUnformatted Code:\n${unformattedCode}`; + } + throw e; + } +} + +function compileSchema( + schema: JSONSchema4, + index: number, +): { type: AST; refTypes: string[] } { + const refTypes: string[] = []; + + const refMap = new Map(); + // we only support defs at the top level for simplicity + const defs = (schema.$defs ?? schema.definitions) as + | Record + | undefined; + if (defs) { + for (const [defKey, defSchema] of Object.entries(defs)) { + const typeName = toPascalCase(defKey); + refMap.set(`#/$defs/${defKey}`, typeName); + refMap.set(`#/items/${index}/$defs/${defKey}`, typeName); + + const type = generateType(defSchema, refMap); + optimizeAST(type); + refTypes.push(printTypeAlias(typeName, type)); + } + } + + const type = generateType(schema, refMap); + optimizeAST(type); + + return { + type, + refTypes, + }; +} + +function toPascalCase(key: string): string { + return key[0].toUpperCase() + key.substring(1); +} diff --git a/packages/rule-schema-to-typescript-types/src/isArray.ts b/packages/rule-schema-to-typescript-types/src/isArray.ts new file mode 100644 index 00000000000..dfd77652a26 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/isArray.ts @@ -0,0 +1,4 @@ +// https://github.com/microsoft/TypeScript/issues/17002 +export function isArray(arg: unknown): arg is readonly unknown[] { + return Array.isArray(arg); +} diff --git a/packages/rule-schema-to-typescript-types/src/optimizeAST.ts b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts new file mode 100644 index 00000000000..ba39aae909a --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/optimizeAST.ts @@ -0,0 +1,72 @@ +import type { AST, UnionAST } from './types'; + +export function optimizeAST(ast: AST | null): void { + if (ast == null) { + return; + } + + switch (ast.type) { + case 'array': { + optimizeAST(ast.elementType); + return; + } + + case 'literal': + return; + + case 'object': { + for (const property of ast.properties) { + optimizeAST(property.type); + } + optimizeAST(ast.indexSignature); + return; + } + + case 'tuple': { + for (const element of ast.elements) { + optimizeAST(element); + } + optimizeAST(ast.spreadType); + return; + } + + case 'type-reference': + return; + + case 'union': { + const elements = unwrapUnions(ast); + for (const element of elements) { + optimizeAST(element); + } + + // hacky way to deduplicate union members + const uniqueElementsMap = new Map(); + for (const element of elements) { + uniqueElementsMap.set(JSON.stringify(element), element); + } + const uniqueElements = Array.from(uniqueElementsMap.values()); + + // @ts-expect-error -- purposely overwriting the property with a flattened list + ast.elements = uniqueElements; + return; + } + } +} + +function unwrapUnions(union: UnionAST): AST[] { + const elements: AST[] = []; + for (const element of union.elements) { + if (element.type === 'union') { + elements.push(...unwrapUnions(element)); + } else { + elements.push(element); + } + } + + if (elements.length > 0) { + // preserve the union's comment lines by prepending them to the first element's lines + elements[0].commentLines.unshift(...union.commentLines); + } + + return elements; +} diff --git a/packages/rule-schema-to-typescript-types/src/printAST.ts b/packages/rule-schema-to-typescript-types/src/printAST.ts new file mode 100644 index 00000000000..f0582953550 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/printAST.ts @@ -0,0 +1,168 @@ +import naturalCompare from 'natural-compare'; + +import type { AST, TupleAST } from './types'; + +export function printTypeAlias(aliasName: string, ast: AST): string { + return `${printComment(ast)}type ${aliasName} = ${printAST(ast).code}`; +} + +export function printASTWithComment(ast: AST): string { + const result = printAST(ast); + return `${printComment(result)}${result.code}`; +} + +function printComment({ + commentLines: commentLinesIn, +}: { + readonly commentLines?: string[] | undefined | null; +}): string { + if (commentLinesIn == null || commentLinesIn.length === 0) { + return ''; + } + + const commentLines: string[] = []; + for (const line of commentLinesIn) { + commentLines.push(...line.split('\n')); + } + + if (commentLines.length === 1) { + return `/** ${commentLines[0]} */\n`; + } + + return ['/**', ...commentLines.map(l => ` * ${l}`), ' */', ''].join('\n'); +} + +interface CodeWithComments { + code: string; + commentLines: string[]; +} +function printAST(ast: AST): CodeWithComments { + switch (ast.type) { + case 'array': { + const code = printAndMaybeParenthesise(ast.elementType); + return { + code: `${code.code}[]`, + commentLines: ast.commentLines.concat(code.commentLines), + }; + } + + case 'literal': + return { + code: ast.code, + commentLines: ast.commentLines, + }; + + case 'object': { + const properties = []; + // sort the properties so that we get consistent output regardless + // of import declaration order + const sortedPropertyDefs = ast.properties.sort((a, b) => + naturalCompare(a.name, b.name), + ); + for (const property of sortedPropertyDefs) { + const result = printAST(property.type); + properties.push( + `${printComment(result)}${property.name}${ + property.optional ? '?:' : ':' + } ${result.code}`, + ); + } + + if (ast.indexSignature) { + const result = printAST(ast.indexSignature); + properties.push(`${printComment(result)}[k: string]: ${result.code}`); + } + return { + // force insert a newline so prettier consistently prints all objects as multiline + code: `{\n${properties.join(';\n')}}`, + commentLines: ast.commentLines, + }; + } + + case 'tuple': { + const elements = []; + for (const element of ast.elements) { + elements.push(printASTWithComment(element)); + } + if (ast.spreadType) { + const result = printAndMaybeParenthesise(ast.spreadType); + elements.push(`${printComment(result)}...${result.code}[]`); + } + + return { + code: `[${elements.join(',')}]`, + commentLines: ast.commentLines, + }; + } + + case 'type-reference': + return { + code: ast.typeName, + commentLines: ast.commentLines, + }; + + case 'union': + return { + code: ast.elements + .map(element => { + const result = printAST(element); + const code = `${printComment(result)} | ${result.code}`; + return { + code, + element, + }; + }) + // sort the union members so that we get consistent output regardless + // of declaration order + .sort((a, b) => compareElements(a, b)) + .map(el => el.code) + .join('\n'), + commentLines: ast.commentLines, + }; + } +} + +interface Element { + code: string; + element: AST; +} +function compareElements(a: Element, b: Element): number { + if (a.element.type !== b.element.type) { + return naturalCompare(a.code, b.code); + } + + switch (a.element.type) { + case 'array': + case 'literal': + case 'type-reference': + case 'object': + case 'union': + return naturalCompare(a.code, b.code); + + case 'tuple': { + // natural compare will sort longer tuples before shorter ones + // which is the opposite of what we want, so we sort first by length THEN + // by code to ensure shorter tuples come first + const aElement = a.element; + const bElement = b.element as TupleAST; + if (aElement.elements.length !== bElement.elements.length) { + return aElement.elements.length - bElement.elements.length; + } + return naturalCompare(a.code, b.code); + } + } +} + +function printAndMaybeParenthesise(ast: AST): CodeWithComments { + const printed = printAST(ast); + if (ast.type === 'union') { + return { + code: `(${printed.code})`, + commentLines: printed.commentLines, + }; + } + return { + code: `${printed.code}`, + commentLines: printed.commentLines, + }; +} diff --git a/packages/rule-schema-to-typescript-types/src/types.ts b/packages/rule-schema-to-typescript-types/src/types.ts new file mode 100644 index 00000000000..78d0bfa994d --- /dev/null +++ b/packages/rule-schema-to-typescript-types/src/types.ts @@ -0,0 +1,49 @@ +export type RefMap = ReadonlyMap< + // ref path + string, + // type name + string +>; + +export type AST = + | ArrayAST + | LiteralAST + | ObjectAST + | TupleAST + | TypeReferenceAST + | UnionAST; + +interface BaseASTNode { + readonly commentLines: string[]; +} + +export interface ArrayAST extends BaseASTNode { + readonly type: 'array'; + readonly elementType: AST; +} +export interface LiteralAST extends BaseASTNode { + readonly type: 'literal'; + readonly code: string; +} +export interface ObjectAST extends BaseASTNode { + readonly type: 'object'; + readonly properties: { + readonly name: string; + readonly optional: boolean; + readonly type: AST; + }[]; + readonly indexSignature: AST | null; +} +export interface TupleAST extends BaseASTNode { + readonly type: 'tuple'; + readonly elements: AST[]; + readonly spreadType: AST | null; +} +export interface TypeReferenceAST extends BaseASTNode { + readonly type: 'type-reference'; + readonly typeName: string; +} +export interface UnionAST extends BaseASTNode { + readonly type: 'union'; + readonly elements: AST[]; +} diff --git a/packages/rule-schema-to-typescript-types/tsconfig.build.json b/packages/rule-schema-to-typescript-types/tsconfig.build.json new file mode 100644 index 00000000000..b9ac3e1b977 --- /dev/null +++ b/packages/rule-schema-to-typescript-types/tsconfig.build.json @@ -0,0 +1,11 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./dist", + "rootDir": "./src", + "resolveJsonModule": true + }, + "include": ["src", "typings"], + "references": [] +} diff --git a/packages/rule-schema-to-typescript-types/tsconfig.json b/packages/rule-schema-to-typescript-types/tsconfig.json new file mode 100644 index 00000000000..06b94d057fa --- /dev/null +++ b/packages/rule-schema-to-typescript-types/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "composite": false, + "rootDir": "." + }, + "include": ["src", "tests", "typings"], + "references": [] +} diff --git a/packages/type-utils/src/TypeOrValueSpecifier.ts b/packages/type-utils/src/TypeOrValueSpecifier.ts index 9ba33588a04..be426297d0a 100644 --- a/packages/type-utils/src/TypeOrValueSpecifier.ts +++ b/packages/type-utils/src/TypeOrValueSpecifier.ts @@ -1,3 +1,4 @@ +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import path from 'path'; import type * as ts from 'typescript'; @@ -24,7 +25,7 @@ export type TypeOrValueSpecifier = | LibSpecifier | PackageSpecifier; -export const typeOrValueSpecifierSchema = { +export const typeOrValueSpecifierSchema: JSONSchema4 = { oneOf: [ { type: 'string', @@ -35,7 +36,7 @@ export const typeOrValueSpecifierSchema = { properties: { from: { type: 'string', - const: 'file', + enum: ['file'], }, name: { oneOf: [ @@ -64,7 +65,7 @@ export const typeOrValueSpecifierSchema = { properties: { from: { type: 'string', - const: 'lib', + enum: ['lib'], }, name: { oneOf: [ @@ -90,7 +91,7 @@ export const typeOrValueSpecifierSchema = { properties: { from: { type: 'string', - const: 'package', + enum: ['package'], }, name: { oneOf: [ diff --git a/packages/type-utils/src/isTypeReadonly.ts b/packages/type-utils/src/isTypeReadonly.ts index 494548d91cf..63a02ea4464 100644 --- a/packages/type-utils/src/isTypeReadonly.ts +++ b/packages/type-utils/src/isTypeReadonly.ts @@ -1,4 +1,5 @@ import { ESLintUtils } from '@typescript-eslint/utils'; +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema'; import * as tsutils from 'ts-api-utils'; import * as ts from 'typescript'; @@ -36,7 +37,7 @@ export const readonlynessOptionsSchema = { items: typeOrValueSpecifierSchema, }, }, -}; +} satisfies JSONSchema4; export const readonlynessOptionsDefaults: ReadonlynessOptions = { treatMethodsAsReadonly: false, diff --git a/packages/website/package.json b/packages/website/package.json index 746f03df991..c637c2dbd55 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -29,7 +29,6 @@ "clsx": "^1.1.1", "eslint": "*", "json-schema": "^0.4.0", - "json-schema-to-typescript": "^11.0.1", "json5": "^2.2.1", "konamimojisplosion": "^0.5.1", "lz-string": "^1.5.0", @@ -53,6 +52,7 @@ "@types/react-helmet": "^6.1.5", "@types/react-router-dom": "^5.3.3", "@typescript-eslint/eslint-plugin": "5.59.0", + "@typescript-eslint/rule-schema-to-typescript-types": "5.59.0", "@typescript-eslint/types": "5.59.0", "copy-webpack-plugin": "^11.0.0", "cross-fetch": "*", diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 962f0141476..3b515fe35d9 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -1,14 +1,11 @@ import pluginRules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; -import * as tseslintParser from '@typescript-eslint/parser'; +import { compile } from '@typescript-eslint/rule-schema-to-typescript-types'; import * as fs from 'fs'; -import type { JSONSchema7 } from 'json-schema'; -import type { JSONSchema } from 'json-schema-to-typescript'; -import { compile } from 'json-schema-to-typescript'; import * as lz from 'lz-string'; import type * as mdast from 'mdast'; import { EOL } from 'os'; import * as path from 'path'; -import { format } from 'prettier'; +import { format, resolveConfig } from 'prettier'; import type { Plugin } from 'unified'; import type * as unist from 'unist'; @@ -22,6 +19,19 @@ const COMPLICATED_RULE_OPTIONS = new Set([ 'member-ordering', 'naming-convention', ]); +/** + * Rules that do funky things with their defaults and require special code + * rather than just JSON.stringify-ing their defaults blob + */ +const SPECIAL_CASE_DEFAULTS = new Map([ + // + ['ban-types', '[{ /* See below for default options */ }]'], +]); + +const prettierConfig = { + ...(resolveConfig.sync(__filename) ?? {}), + filepath: path.join(__dirname, 'defaults.ts'), +}; const sourceUrlPrefix = 'https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/'; @@ -35,7 +45,7 @@ function nodeIsParent(node: unist.Node): node is unist.Parent { } export const generatedRuleDocs: Plugin = () => { - return async (root, file) => { + return (root, file) => { if (!nodeIsParent(root) || file.stem == null) { return; } @@ -243,7 +253,10 @@ export const generatedRuleDocs: Plugin = () => { optionsH2Index += 2; - if (meta.schema.length === 0) { + const hasNoConfig = Array.isArray(meta.schema) + ? meta.schema.length === 0 + : Object.keys(meta.schema).length === 0; + if (hasNoConfig) { children.splice(optionsH2Index + 1, 0, { children: [ { @@ -254,21 +267,9 @@ export const generatedRuleDocs: Plugin = () => { type: 'paragraph', } as mdast.Paragraph); } else if (!COMPLICATED_RULE_OPTIONS.has(file.stem)) { - const optionsSchema: JSONSchema = - meta.schema instanceof Array - ? meta.schema[0] - : meta.schema.type === 'array' - ? { - ...(meta.schema.definitions - ? { definitions: meta.schema.definitions } - : {}), - ...(meta.schema.$defs - ? { $defs: (meta.schema as JSONSchema7).$defs } - : {}), - ...(meta.schema.prefixItems as [JSONSchema])[0], - } - : meta.schema; - + const defaults = + SPECIAL_CASE_DEFAULTS.get(file.stem) ?? + JSON.stringify(rule.defaultOptions); children.splice( optionsH2Index + 1, 0, @@ -276,11 +277,7 @@ export const generatedRuleDocs: Plugin = () => { children: [ { type: 'text', - value: `This rule accepts an options ${ - 'enum' in optionsSchema - ? 'string of the following possible values' - : 'object with the following properties' - }:`, + value: 'This rule accepts the following options', } as mdast.Text, ], type: 'paragraph', @@ -289,27 +286,10 @@ export const generatedRuleDocs: Plugin = () => { lang: 'ts', type: 'code', value: [ - ( - await compile( - { - title: `Options`, - ...optionsSchema, - }, - file.stem, - { - additionalProperties: false, - bannerComment: '', - declareExternallyReferenced: true, - }, - ) - ).replace(/^export /gm, ''), + compile(rule.meta.schema), format( - `const defaultOptions: Options = ${JSON.stringify( - rule.defaultOptions, - )};`, - { - parser: tseslintParser.parse, - }, + `const defaultOptions: Options = ${defaults};`, + prettierConfig, ), ] .join(EOL) diff --git a/packages/website/src/components/lib/jsonSchema.ts b/packages/website/src/components/lib/jsonSchema.ts index db11292c084..6b5c3af421a 100644 --- a/packages/website/src/components/lib/jsonSchema.ts +++ b/packages/website/src/components/lib/jsonSchema.ts @@ -8,6 +8,11 @@ const defaultRuleSchema: JSONSchema4 = { enum: ['off', 'warn', 'error', 0, 1, 2], }; +// https://github.com/microsoft/TypeScript/issues/17002 +function isArray(arg: unknown): arg is readonly unknown[] { + return Array.isArray(arg); +} + /** * Add the error level to the rule schema items * @@ -18,9 +23,9 @@ const defaultRuleSchema: JSONSchema4 = { */ export function getRuleJsonSchemaWithErrorLevel( name: string, - ruleSchema: JSONSchema4 | JSONSchema4[], + ruleSchema: JSONSchema4 | readonly JSONSchema4[], ): JSONSchema4 { - if (Array.isArray(ruleSchema)) { + if (isArray(ruleSchema)) { return { type: 'array', items: [defaultRuleSchema, ...ruleSchema], @@ -28,20 +33,8 @@ export function getRuleJsonSchemaWithErrorLevel( additionalItems: false, }; } - // TODO: delete this once we update schemas - // example: ban-ts-comment - if (Array.isArray(ruleSchema.prefixItems)) { - const { prefixItems, ...rest } = ruleSchema; - return { - ...rest, - items: [defaultRuleSchema, ...(prefixItems as JSONSchema4[])], - maxItems: ruleSchema.maxItems ? ruleSchema.maxItems + 1 : undefined, - minItems: ruleSchema.minItems ? ruleSchema.minItems + 1 : 1, - additionalItems: false, - }; - } // example: explicit-member-accessibility - if (Array.isArray(ruleSchema.items)) { + if (isArray(ruleSchema.items)) { return { ...ruleSchema, items: [defaultRuleSchema, ...ruleSchema.items], @@ -59,7 +52,7 @@ export function getRuleJsonSchemaWithErrorLevel( }; } // example eqeqeq - if (Array.isArray(ruleSchema.anyOf)) { + if (isArray(ruleSchema.anyOf)) { return { ...ruleSchema, anyOf: ruleSchema.anyOf.map(item => @@ -68,7 +61,7 @@ export function getRuleJsonSchemaWithErrorLevel( }; } // example logical-assignment-operators - if (Array.isArray(ruleSchema.oneOf)) { + if (isArray(ruleSchema.oneOf)) { return { ...ruleSchema, oneOf: ruleSchema.oneOf.map(item => diff --git a/packages/website/src/components/linter/createLinter.ts b/packages/website/src/components/linter/createLinter.ts index 06299c9e3ee..2f0c1725329 100644 --- a/packages/website/src/components/linter/createLinter.ts +++ b/packages/website/src/components/linter/createLinter.ts @@ -21,7 +21,7 @@ export interface CreateLinter { name: string; description?: string; url?: string; - schema: JSONSchema.JSONSchema4; + schema: JSONSchema.JSONSchema4 | readonly JSONSchema.JSONSchema4[]; } >; configs: string[]; diff --git a/patches/@types+json-schema+7.0.11.patch b/patches/@types+json-schema+7.0.11.patch new file mode 100644 index 00000000000..33f3206e1ac --- /dev/null +++ b/patches/@types+json-schema+7.0.11.patch @@ -0,0 +1,35 @@ +diff --git a/node_modules/@types/json-schema/index.d.ts b/node_modules/@types/json-schema/index.d.ts +index 7a92dec..44d9691 100755 +--- a/node_modules/@types/json-schema/index.d.ts ++++ b/node_modules/@types/json-schema/index.d.ts +@@ -154,9 +154,18 @@ export interface JSONSchema4 { + */ + additionalProperties?: boolean | JSONSchema4 | undefined; + ++ /** ++ * Reusable definitions that can be referenced via `$ref` ++ */ + definitions?: { + [k: string]: JSONSchema4; + } | undefined; ++ /** ++ * Reusable definitions that can be referenced via `$ref` ++ */ ++ $defs?: { ++ [k: string]: JSONSchema4; ++ } | undefined; + + /** + * This attribute is an object with property definitions that define the +@@ -232,11 +241,6 @@ export interface JSONSchema4 { + */ + extends?: string | string[] | undefined; + +- /** +- * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.6 +- */ +- [k: string]: any; +- + format?: string | undefined; + } + diff --git a/yarn.lock b/yarn.lock index 274e3144b9c..03195b91279 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1219,16 +1219,6 @@ "@babel/helper-validator-identifier" "^7.19.1" to-fast-properties "^2.0.0" -"@bcherny/json-schema-ref-parser@10.0.5-fork": - version "10.0.5-fork" - resolved "https://registry.yarnpkg.com/@bcherny/json-schema-ref-parser/-/json-schema-ref-parser-10.0.5-fork.tgz#9b5e1e7e07964ea61840174098e634edbe8197bc" - integrity sha512-E/jKbPoca1tfUPj3iSbitDZTGnq6FUFjkH6L8U2oDwSuwK1WhnnVtCG7oFOTg/DDnyoXbQYUiUiGOibHqaGVnw== - dependencies: - "@jsdevtools/ono" "^7.1.3" - "@types/json-schema" "^7.0.6" - call-me-maybe "^1.0.1" - js-yaml "^4.1.0" - "@bcoe/v8-coverage@^0.2.3": version "0.2.3" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" @@ -2545,11 +2535,6 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" -"@jsdevtools/ono@^7.1.3": - version "7.1.3" - resolved "https://registry.yarnpkg.com/@jsdevtools/ono/-/ono-7.1.3.tgz#9df03bbd7c696a5c58885c34aa06da41c8543796" - integrity sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg== - "@leichtgewicht/ip-codec@^2.0.1": version "2.0.4" resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b" @@ -3758,14 +3743,6 @@ "@types/minimatch" "^5.1.2" "@types/node" "*" -"@types/glob@^7.1.3": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" - integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA== - dependencies: - "@types/minimatch" "*" - "@types/node" "*" - "@types/graceful-fs@^4.1.3": version "4.1.6" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.6.tgz#e14b2576a1c25026b7f02ede1de3b84c3a1efeae" @@ -3836,7 +3813,7 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/json-schema@*", "@types/json-schema@^7.0.11", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9": +"@types/json-schema@*", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.8", "@types/json-schema@^7.0.9": version "7.0.11" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== @@ -3846,7 +3823,7 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ== -"@types/lodash@*", "@types/lodash@^4.14.182": +"@types/lodash@*": version "4.14.194" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76" integrity sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g== @@ -3868,16 +3845,16 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== -"@types/minimatch@*", "@types/minimatch@^5.1.2": - version "5.1.2" - resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" - integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== - "@types/minimatch@^3.0.3": version "3.0.5" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40" integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ== +"@types/minimatch@^5.1.2": + version "5.1.2" + resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" + integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== + "@types/minimist@^1.2.0": version "1.2.2" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" @@ -3888,7 +3865,7 @@ resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197" integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== -"@types/natural-compare@^1.4.0": +"@types/natural-compare@*", "@types/natural-compare@^1.4.0": version "1.4.1" resolved "https://registry.yarnpkg.com/@types/natural-compare/-/natural-compare-1.4.1.tgz#fc2b11ea100d380b0de7af15768bef209157bfb9" integrity sha512-9dr4UakpvN0QUvwNefk9+o14Sr1pPPIDWkgCxPkHcg3kyjtc9eKK1ng6dZ23vRwByloCqXYtZ1T5nJxkk3Ib3A== @@ -3920,7 +3897,7 @@ resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-5.0.3.tgz#e7b5aebbac150f8b5fdd4a46e7f0bd8e65e19109" integrity sha512-kUNnecmtkunAoQ3CnjmMkzNU/gtxG8guhi+Fk2U/kOpIKjIMKnXGp4IJCgQJrXSgMsWYimYG4TGjz/UzbGEBTw== -"@types/prettier@*", "@types/prettier@^2.1.5", "@types/prettier@^2.6.0", "@types/prettier@^2.6.1": +"@types/prettier@*", "@types/prettier@^2.1.5", "@types/prettier@^2.6.0": version "2.7.2" resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.2.tgz#6c2324641cc4ba050a8c710b2b251b377581fbf0" integrity sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg== @@ -4449,11 +4426,6 @@ ansi-styles@^6.0.0, ansi-styles@^6.1.0: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.1.tgz#0e62320cf99c21afff3b3012192546aacbfb05c5" integrity sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug== -any-promise@^1.0.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" - integrity sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A== - anymatch@^3.0.3, anymatch@~3.1.2: version "3.1.3" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e" @@ -5101,11 +5073,6 @@ call-bind@^1.0.0, call-bind@^1.0.2: function-bind "^1.1.1" get-intrinsic "^1.0.2" -call-me-maybe@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b" - integrity sha512-wCyFsDQkKPwwF8BDwOiWNx/9K45L/hvggQiDbve+viMNMQnWhrlYIuBk09offfwCRtCO9P6XwUttufzU11WCVw== - callsites@^3.0.0, callsites@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73" @@ -5320,17 +5287,6 @@ cli-boxes@^3.0.0: resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-3.0.0.tgz#71a10c716feeba005e4504f36329ef0b17cf3145" integrity sha512-/lzGpEWL/8PfI0BmBOPRwp0c/wFNX1RdUML3jK/RcSBA9T8mZDdQpqYBKtCFTOfQbwPqWEOpjqW+Fnayc0969g== -cli-color@^2.0.2: - version "2.0.3" - resolved "https://registry.yarnpkg.com/cli-color/-/cli-color-2.0.3.tgz#73769ba969080629670f3f2ef69a4bf4e7cc1879" - integrity sha512-OkoZnxyC4ERN3zLzZaY9Emb7f/MhBOIpePv0Ycok0fJYT+Ouo00UBEIwsVsr0yoow++n5YWlSUgST9GKhNHiRQ== - dependencies: - d "^1.0.1" - es5-ext "^0.10.61" - es6-iterator "^2.0.3" - memoizee "^0.4.15" - timers-ext "^0.1.7" - cli-cursor@3.1.0, cli-cursor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" @@ -6174,14 +6130,6 @@ csstype@^3.0.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b" integrity sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw== -d@1, d@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a" - integrity sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA== - dependencies: - es5-ext "^0.10.50" - type "^1.0.1" - damerau-levenshtein@^1.0.8: version "1.0.8" resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7" @@ -6754,42 +6702,6 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -es5-ext@^0.10.35, es5-ext@^0.10.46, es5-ext@^0.10.50, es5-ext@^0.10.53, es5-ext@^0.10.61, es5-ext@~0.10.14, es5-ext@~0.10.2, es5-ext@~0.10.46: - version "0.10.61" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.61.tgz#311de37949ef86b6b0dcea894d1ffedb909d3269" - integrity sha512-yFhIqQAzu2Ca2I4SE2Au3rxVfmohU9Y7wqGR+s7+H7krk26NXhIRAZDgqd6xqjCEFUomDEA3/Bo/7fKmIkW1kA== - dependencies: - es6-iterator "^2.0.3" - es6-symbol "^3.1.3" - next-tick "^1.1.0" - -es6-iterator@^2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.3.tgz#a7de889141a05a94b0854403b2d0a0fbfa98f3b7" - integrity sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g== - dependencies: - d "1" - es5-ext "^0.10.35" - es6-symbol "^3.1.1" - -es6-symbol@^3.1.1, es6-symbol@^3.1.3: - version "3.1.3" - resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.3.tgz#bad5d3c1bcdac28269f4cb331e431c78ac705d18" - integrity sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA== - dependencies: - d "^1.0.1" - ext "^1.1.2" - -es6-weak-map@^2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.3.tgz#b6da1f16cc2cc0d9be43e6bdbfc5e7dfcdf31d53" - integrity sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA== - dependencies: - d "1" - es5-ext "^0.10.46" - es6-iterator "^2.0.3" - es6-symbol "^3.1.1" - esbuild@~0.17.12, esbuild@~0.17.6: version "0.17.12" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.12.tgz#2ad7523bf1bc01881e9d904bc04e693bd3bdcf2f" @@ -7137,14 +7049,6 @@ eval@^0.1.8: "@types/node" "*" require-like ">= 0.1.1" -event-emitter@^0.3.5: - version "0.3.5" - resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" - integrity sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA== - dependencies: - d "1" - es5-ext "~0.10.14" - event-target-shim@^5.0.0: version "5.0.1" resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" @@ -7258,13 +7162,6 @@ express@^4.17.3: utils-merge "1.0.1" vary "~1.1.2" -ext@^1.1.2: - version "1.6.0" - resolved "https://registry.yarnpkg.com/ext/-/ext-1.6.0.tgz#3871d50641e874cc172e2b53f919842d19db4c52" - integrity sha512-sdBImtzkq2HpkdRLtlLWDa6w4DX22ijZLKx8BMPUuKe1c5lbN6xwQDQCxSfxBQnHZ13ls/FH0MQZx/q/gr6FQg== - dependencies: - type "^2.5.0" - extend-shallow@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f" @@ -7862,13 +7759,6 @@ glob-parent@^6.0.1, glob-parent@^6.0.2: dependencies: is-glob "^4.0.3" -glob-promise@^4.2.2: - version "4.2.2" - resolved "https://registry.yarnpkg.com/glob-promise/-/glob-promise-4.2.2.tgz#15f44bcba0e14219cd93af36da6bb905ff007877" - integrity sha512-xcUzJ8NWN5bktoTIX7eOclO1Npxd/dyVqUJxlLIDasT4C7KZyqlPIwkdJ0Ypiy3p2ZKahTjK4M9uC3sNSfNMzw== - dependencies: - "@types/glob" "^7.1.3" - glob-to-regexp@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" @@ -8910,11 +8800,6 @@ is-plain-object@^5.0.0: resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344" integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q== -is-promise@^2.2.2: - version "2.2.2" - resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.2.2.tgz#39ab959ccbf9a774cf079f7b40c7a26f763135f1" - integrity sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ== - is-regex@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.4.tgz#eef5663cd59fa4c0ae339505323df6854bb15958" @@ -9590,26 +9475,6 @@ json-parse-even-better-errors@^3.0.0: resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-3.0.0.tgz#2cb2ee33069a78870a0c7e3da560026b89669cf7" integrity sha512-iZbGHafX/59r39gPwVPRBGw0QQKnA7tte5pSMrhWOW7swGsVvVTjmfyAV9pNqk8YGT7tRCdxRu8uzcgZwoDooA== -json-schema-to-typescript@^11.0.1: - version "11.0.5" - resolved "https://registry.yarnpkg.com/json-schema-to-typescript/-/json-schema-to-typescript-11.0.5.tgz#04020422b7970e1c3b2ee8b601548e8751e1cd03" - integrity sha512-ZNlvngzlPzjYYECbR+uJ9aUWo25Gw/VuwUytvcuKiwc6NaiZhMyf7qBsxZE2eixmj8AoQEQJhSRG7btln0sUDw== - dependencies: - "@bcherny/json-schema-ref-parser" "10.0.5-fork" - "@types/json-schema" "^7.0.11" - "@types/lodash" "^4.14.182" - "@types/prettier" "^2.6.1" - cli-color "^2.0.2" - get-stdin "^8.0.0" - glob "^7.1.6" - glob-promise "^4.2.2" - is-glob "^4.0.3" - lodash "^4.17.21" - minimist "^1.2.6" - mkdirp "^1.0.4" - mz "^2.7.0" - prettier "^2.6.2" - json-schema-traverse@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660" @@ -10128,13 +9993,6 @@ lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.18.3.tgz#f793896e0fd0e954a59dfdd82f0773808df6aa89" integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA== -lru-queue@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/lru-queue/-/lru-queue-0.1.0.tgz#2738bd9f0d3cf4f84490c5736c48699ac632cda3" - integrity sha512-BpdYkt9EvGl8OfWHDQPISVpcl5xZthb+XPsbELj5AQXxIC8IriDZIQYjBJPEm5rS420sjZ0TLEzRcq5KdBhYrQ== - dependencies: - es5-ext "~0.10.2" - lz-string@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.5.0.tgz#c1ab50f77887b712621201ba9fd4e3a6ed099941" @@ -10340,20 +10198,6 @@ memfs@^3.1.2, memfs@^3.4.1: dependencies: fs-monkey "1.0.3" -memoizee@^0.4.15: - version "0.4.15" - resolved "https://registry.yarnpkg.com/memoizee/-/memoizee-0.4.15.tgz#e6f3d2da863f318d02225391829a6c5956555b72" - integrity sha512-UBWmJpLZd5STPm7PMUlOw/TSy972M+z8gcyQ5veOnSDRREz/0bmpyTfKt3/51DhEBqCZQn1udM/5flcSPYhkdQ== - dependencies: - d "^1.0.1" - es5-ext "^0.10.53" - es6-weak-map "^2.0.3" - event-emitter "^0.3.5" - is-promise "^2.2.2" - lru-queue "^0.1.0" - next-tick "^1.1.0" - timers-ext "^0.1.7" - meow@^8.0.0: version "8.1.2" resolved "https://registry.yarnpkg.com/meow/-/meow-8.1.2.tgz#bcbe45bda0ee1729d350c03cffc8395a36c4e897" @@ -10702,15 +10546,6 @@ mute-stream@0.0.8, mute-stream@~0.0.4: resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== -mz@^2.7.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32" - integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q== - dependencies: - any-promise "^1.0.0" - object-assign "^4.0.1" - thenify-all "^1.0.0" - nanoid@^3.3.4: version "3.3.4" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab" @@ -10736,11 +10571,6 @@ neo-async@^2.6.0, neo-async@^2.6.2: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -next-tick@1, next-tick@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.1.0.tgz#1836ee30ad56d67ef281b22bd199f709449b35eb" - integrity sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ== - nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" @@ -11126,7 +10956,7 @@ nx@15.7.2, "nx@>=15.5.2 < 16": "@nrwl/nx-win32-arm64-msvc" "15.7.2" "@nrwl/nx-win32-x64-msvc" "15.7.2" -object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: +object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= @@ -12062,7 +11892,7 @@ prepend-http@^2.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= -prettier@*, prettier@^2.6.2, prettier@^2.8.4: +prettier@*, prettier@^2.8.4: version "2.8.4" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3" integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw== @@ -14016,20 +13846,6 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw== -thenify-all@^1.0.0: - version "1.6.0" - resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726" - integrity sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA== - dependencies: - thenify ">= 3.1.0 < 4" - -"thenify@>= 3.1.0 < 4": - version "3.3.1" - resolved "https://registry.yarnpkg.com/thenify/-/thenify-3.3.1.tgz#8932e686a4066038a016dd9e2ca46add9838a95f" - integrity sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw== - dependencies: - any-promise "^1.0.0" - through2@^2.0.0: version "2.0.5" resolved "https://registry.yarnpkg.com/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" @@ -14055,14 +13871,6 @@ thunky@^1.0.2: resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d" integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA== -timers-ext@^0.1.7: - version "0.1.7" - resolved "https://registry.yarnpkg.com/timers-ext/-/timers-ext-0.1.7.tgz#6f57ad8578e07a3fb9f91d9387d65647555e25c6" - integrity sha512-b85NUNzTSdodShTIbky6ZF02e8STtVVfD+fu4aXXShEELpozH+bCpJLYMPZbsABN2wDH7fJpqIoXxJpzbf0NqQ== - dependencies: - es5-ext "~0.10.46" - next-tick "1" - tiny-invariant@^1.0.2: version "1.2.0" resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.2.0.tgz#a1141f86b672a9148c72e978a19a73b9b94a15a9" @@ -14352,16 +14160,6 @@ type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" -type@^1.0.1: - version "1.2.0" - resolved "https://registry.yarnpkg.com/type/-/type-1.2.0.tgz#848dd7698dafa3e54a6c479e759c4bc3f18847a0" - integrity sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg== - -type@^2.5.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/type/-/type-2.6.0.tgz#3ca6099af5981d36ca86b78442973694278a219f" - integrity sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ== - typed-array-length@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/typed-array-length/-/typed-array-length-1.0.4.tgz#89d83785e5c4098bec72e08b319651f0eac9c1bb"