From 1ca21c4b62277ca9d869cecfc7f975cf2ead6f39 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 26 Jul 2022 15:54:51 -0400 Subject: [PATCH 01/26] chore(website): generate rule docs options automatically --- .../rules/adjacent-overload-signatures.md | 13 -- .../eslint-plugin/docs/rules/array-type.md | 12 - .../docs/rules/await-thenable.md | 13 -- .../docs/rules/ban-ts-comment.md | 26 +-- .../docs/rules/ban-tslint-comment.md | 13 -- .../eslint-plugin/docs/rules/require-await.md | 18 -- .../utils/src/eslint-utils/RuleCreator.ts | 3 +- packages/utils/src/ts-eslint/Rule.ts | 5 + packages/website/package.json | 4 + .../website/plugins/generated-rule-docs.ts | 215 +++++++++++++++++- yarn.lock | 211 ++++++++++++++++- 11 files changed, 425 insertions(+), 108 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md index 57677bd4ac1f..b829b3ee276a 100644 --- a/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md +++ b/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md @@ -84,19 +84,6 @@ export function foo(n: number): void; export function foo(sn: string | number): void; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about the general structure of the code, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/array-type.md b/packages/eslint-plugin/docs/rules/array-type.md index 9a9ac0985bc3..fa7be4a4541c 100644 --- a/packages/eslint-plugin/docs/rules/array-type.md +++ b/packages/eslint-plugin/docs/rules/array-type.md @@ -10,18 +10,6 @@ This rule aims to standardize usage of array types within your codebase. ## Options -```ts -type ArrayOption = 'array' | 'generic' | 'array-simple'; -type Options = { - default: ArrayOption; - readonly?: ArrayOption; -}; - -const defaultOptions: Options = { - default: 'array', -}; -``` - The rule accepts an options object with the following properties: - `default` - sets the array type expected for mutable cases. diff --git a/packages/eslint-plugin/docs/rules/await-thenable.md b/packages/eslint-plugin/docs/rules/await-thenable.md index d0d3d5f7d521..58129c89d5ed 100644 --- a/packages/eslint-plugin/docs/rules/await-thenable.md +++ b/packages/eslint-plugin/docs/rules/await-thenable.md @@ -29,19 +29,6 @@ const createValue = async () => 'value'; await createValue(); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/await-thenable": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you want to allow code to `await` non-Promise values. diff --git a/packages/eslint-plugin/docs/rules/ban-ts-comment.md b/packages/eslint-plugin/docs/rules/ban-ts-comment.md index f560c55ff054..b4a6ab751d39 100644 --- a/packages/eslint-plugin/docs/rules/ban-ts-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-ts-comment.md @@ -17,32 +17,10 @@ The directive comments supported by TypeScript are: ## Rule Details This rule lets you set which directive comments you want to allow in your codebase. -By default, only `@ts-check` is allowed, as it enables rather than suppresses errors. - -The configuration looks like this: -```ts -type DirectiveConfig = - | boolean - | 'allow-with-description' - | { descriptionFormat: string }; - -interface Options { - 'ts-expect-error'?: DirectiveConfig; - 'ts-ignore'?: DirectiveConfig; - 'ts-nocheck'?: DirectiveConfig; - 'ts-check'?: DirectiveConfig; - minimumDescriptionLength?: number; -} +## Options -const defaultOptions: Options = { - 'ts-expect-error': 'allow-with-description', - 'ts-ignore': true, - 'ts-nocheck': true, - 'ts-check': false, - minimumDescriptionLength: 3, -}; -``` +By default, only `@ts-check` is allowed, as it enables rather than suppresses errors. ### `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check` directives diff --git a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md index 3e5789bc005b..53f5c69062de 100644 --- a/packages/eslint-plugin/docs/rules/ban-tslint-comment.md +++ b/packages/eslint-plugin/docs/rules/ban-tslint-comment.md @@ -30,19 +30,6 @@ someCode(); // tslint:disable-line someCode(); // This is a comment that just happens to mention tslint ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/ban-tslint-comment": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are still using TSLint. diff --git a/packages/eslint-plugin/docs/rules/require-await.md b/packages/eslint-plugin/docs/rules/require-await.md index 21d6271c38c4..dedff2b0422a 100644 --- a/packages/eslint-plugin/docs/rules/require-await.md +++ b/packages/eslint-plugin/docs/rules/require-await.md @@ -18,21 +18,3 @@ const returnsPromise2 = () => returnsPromise1(); ``` ## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "require-await": "off", - "@typescript-eslint/require-await": "error" -} -``` - -## Options - -See [`eslint/require-await` options](https://eslint.org/docs/rules/require-await#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md) - - diff --git a/packages/utils/src/eslint-utils/RuleCreator.ts b/packages/utils/src/eslint-utils/RuleCreator.ts index 2bd24323e782..2e2646db3506 100644 --- a/packages/utils/src/eslint-utils/RuleCreator.ts +++ b/packages/utils/src/eslint-utils/RuleCreator.ts @@ -95,13 +95,14 @@ function createRule< TRuleListener > { return { - meta, create( context: Readonly>, ): TRuleListener { const optionsWithDefault = applyDefault(defaultOptions, context.options); return create(context, optionsWithDefault); }, + defaultOptions, + meta, }; } diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index 25d29bddf115..ff3053863219 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -433,6 +433,11 @@ interface RuleModule< // for extending base rules TRuleListener extends RuleListener = RuleListener, > { + /** + * Default options the rule will be run with + */ + defaultOptions: TOptions; + /** * Metadata about the rule */ diff --git a/packages/website/package.json b/packages/website/package.json index ee5a05772d95..857da4e7feae 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -20,12 +20,16 @@ "@docusaurus/remark-plugin-npm2yarn": "2.0.0-beta.21", "@docusaurus/theme-common": "2.0.0-beta.21", "@mdx-js/react": "1.6.22", + "@typescript-eslint/parser": "^5.31.0", "@typescript-eslint/website-eslint": "5.31.0", "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", "lzstring.ts": "^2.0.2", + "prettier": "*", "prism-react-renderer": "^1.3.3", "react": "^18.1.0", "react-dom": "^18.1.0", diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index f074db043551..0c88e99cf138 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -1,17 +1,23 @@ import type * as unist from 'unist'; -import type * as mdast from 'mdast'; +import * as mdast from 'mdast'; +import { format } from 'prettier'; import type { Plugin } from 'unified'; +import { JSONSchema4Object } from 'json-schema'; +import { compile } from 'json-schema-to-typescript'; +import * as tseslintParser from '@typescript-eslint/parser'; import * as eslintPlugin from '@typescript-eslint/eslint-plugin'; +import { EOL } from 'os'; const generatedRuleDocs: Plugin = () => { - return (root, file) => { + return async (root, file) => { if (file.stem == null) { return; } - const docs = eslintPlugin.rules[file.stem]?.meta.docs; - if (!docs) { + const rule = eslintPlugin.rules[file.stem]; + const meta = rule?.meta; + if (!meta?.docs) { return; } @@ -27,7 +33,7 @@ const generatedRuleDocs: Plugin = () => { parent.children.unshift({ children: [ { - children: docs.description + children: meta.docs.description .split(/`(.+?)`/) .map((value, index, array) => ({ type: index % 2 === 0 ? 'text' : 'inlineCode', @@ -40,22 +46,211 @@ const generatedRuleDocs: Plugin = () => { } as mdast.Blockquote); // 3. Add a rule attributes list... - const h2Idx = + const attributesH2Index = // ...before the first h2, if it exists... parent.children.findIndex( - child => - child.type === 'heading' && (child as mdast.Heading).depth === 2, + child => nodeIsHeading(child) && child.depth === 2, ) ?? // ...or at the very end, if not. parent.children.length; // The actual content will be injected on client side. - const attrNode = { + const attributesNode = { type: 'jsx', value: ``, }; - parent.children.splice(h2Idx, 0, attrNode); + parent.children.splice(attributesH2Index, 0, attributesNode); + + // 4. Add a description of how to use / options for the rule + const optionLevel = meta.docs.recommended === 'error' ? 'error' : 'warn'; + if (meta.docs.extendsBaseRule) { + const howToUseH2Index = parent.children.findIndex( + createH2TextFilter('How to Use'), + ); + + parent.children.splice( + howToUseH2Index + 1, + 0, + { + lang: 'jsonc', + type: 'code', + value: `// .eslintrc.json +{ + // note you must disable the base rule as it can report incorrect errors + "${file.stem}": "off", + "@typescript-eslint/${file.stem}": "${optionLevel}" +}`, + } as mdast.Code, + { + children: [ + { + type: 'text', + value: 'Options', + }, + ], + depth: 2, + type: 'heading', + } as mdast.Heading, + { + children: [ + { + value: 'See ', + type: 'text', + }, + { + children: [ + { + type: 'inlineCode', + value: `eslint/${file.stem}`, + }, + { + type: 'text', + value: ' options', + }, + ], + type: 'link', + url: `https://eslint.org/docs/rules/${file.stem}#options`, + }, + { + type: 'text', + value: '.', + }, + ], + type: 'paragraph', + } as mdast.Paragraph, + // todo: add more? + ); + } else { + let optionsH2Index = parent.children.findIndex( + createH2TextFilter('Options'), + ); + + if (optionsH2Index === -1) { + const whenNotToUseItH2Index = parent.children.findIndex( + createH2TextFilter('When Not To Use It'), + ); + optionsH2Index = + whenNotToUseItH2Index === -1 + ? parent.children.length - 1 + : whenNotToUseItH2Index; + + parent.children.splice(optionsH2Index, 0, { + children: [ + { + type: 'text', + value: 'Options', + }, + ], + depth: 2, + type: 'heading', + } as mdast.Heading); + } + + if (meta.schema.length === 0) { + parent.children.splice( + optionsH2Index + 1, + 0, + { + lang: 'jsonc', + type: 'code', + value: `// .eslintrc.json +{ + "rules": { + "@typescript-eslint/${file.stem}": "${optionLevel}" + } +}`, + } as mdast.Code, + { + children: [ + { + type: 'text', + value: 'This rule is not configurable.', + }, + ], + type: 'paragraph', + } as mdast.Paragraph, + ); + } else { + const optionsInterface = await compile( + { + title: `Options`, + ...(meta.schema[0] as JSONSchema4Object), + }, + file.stem, + { additionalProperties: false, bannerComment: '' }, + ); + + parent.children.splice(optionsH2Index + 1, 0, { + lang: 'ts', + type: 'code', + value: [ + optionsInterface.replace(/^export /g, ''), + format( + `const defaultOptions: Options = ${JSON.stringify( + rule.defaultOptions, + )};`, + { + parser: tseslintParser.parse, + }, + ), + ] + .join(EOL) + .trim(), + } as mdast.Code); + } + } + + // 5. Add a notice about coming from ESLint core for extension rules + if (meta.docs.extendsBaseRule) { + parent.children.push( + { + type: 'html', + value: '', + } as mdast.HTML, + { + children: [ + { + type: 'text', + value: 'Taken with ❤️ ', + }, + { + children: [ + { + type: 'text', + value: 'from ESLint core', + }, + ], + type: 'link', + url: 'https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md', + }, + ], + type: 'paragraph', + } as mdast.Paragraph, + { + type: 'html', + value: '', + } as mdast.HTML, + ); + } + + // TODO: find & use library that converts text to markdown ast + // (that'll fix the not applying issue) }; }; +function nodeIsHeading(node: unist.Node): node is mdast.Heading { + return node.type === 'heading'; +} + +function createH2TextFilter( + text: string, +): (node: unist.Node) => node is mdast.Heading { + return (node: unist.Node): node is mdast.Heading => + nodeIsHeading(node) && + node.depth === 2 && + node.children.length === 1 && + node.children[0].type === 'text' && + node.children[0].value === text; +} + export { generatedRuleDocs }; diff --git a/yarn.lock b/yarn.lock index cd6908db3ad1..882136e08329 100644 --- a/yarn.lock +++ b/yarn.lock @@ -130,6 +130,15 @@ dependencies: "@jridgewell/trace-mapping" "^0.3.0" +"@apidevtools/json-schema-ref-parser@https://github.com/bcherny/json-schema-ref-parser.git#984282d34a2993e5243aa35100fe32a63699164d": + version "0.0.0-dev" + resolved "https://github.com/bcherny/json-schema-ref-parser.git#984282d34a2993e5243aa35100fe32a63699164d" + dependencies: + "@jsdevtools/ono" "^7.1.3" + "@types/json-schema" "^7.0.6" + call-me-maybe "^1.0.1" + js-yaml "^4.1.0" + "@babel/code-frame@*", "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.16.0", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.8.3": version "7.18.6" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.18.6.tgz#3b25d38c89600baa2dcc219edfa88a74eb2c427a" @@ -2323,6 +2332,11 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" +"@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" @@ -4052,7 +4066,7 @@ "@types/qs" "*" "@types/serve-static" "*" -"@types/glob@*", "@types/glob@^7.2.0": +"@types/glob@*", "@types/glob@^7.1.3", "@types/glob@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA== @@ -4130,7 +4144,7 @@ jest-matcher-utils "^28.0.0" pretty-format "^28.0.0" -"@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": +"@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": 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== @@ -4209,6 +4223,11 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.0.tgz#efcbd41937f9ae7434c714ab698604822d890759" integrity sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw== +"@types/prettier@^2.6.1": + version "2.6.3" + resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.3.tgz#68ada76827b0010d0db071f739314fa429943d0a" + integrity sha512-ymZk3LEC/fsut+/Q5qejp6R9O1rMxz3XaRHDV6kX8MrGAhOSPqVARbDi+EZvInBpw+BnCX3TD240byVkOfQsHg== + "@types/prop-types@*": version "15.7.4" resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" @@ -4706,6 +4725,11 @@ ansi-styles@^6.0.0, ansi-styles@^6.1.0: resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.1.0.tgz#87313c102b8118abd57371afab34618bf7350ed3" integrity sha512-VbqNsoz55SYGczauuup0MFUyXNQviSpFTj1RQtFzmQLk18qbVSpTFFGMT293rmDaQuKCT6InmbuEyUne4mTuxQ== +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.2" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" @@ -5344,6 +5368,11 @@ 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" @@ -5584,6 +5613,17 @@ 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" @@ -6405,6 +6445,14 @@ cypress@8.3.0: url "^0.11.0" yauzl "^2.10.0" +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" @@ -7011,6 +7059,42 @@ 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" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -7293,6 +7377,14 @@ 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" + eventemitter2@^6.4.3: version "6.4.5" resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.5.tgz#97380f758ae24ac15df8353e0cc27f8b95644655" @@ -7424,6 +7516,13 @@ 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" @@ -8018,6 +8117,13 @@ glob-parent@^6.0.1: 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" @@ -9009,6 +9115,11 @@ 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-reference@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/is-reference/-/is-reference-1.2.1.tgz#8b2dac0b371f4bc994fdeaba9eb542d03002d0b7" @@ -9796,6 +9907,26 @@ json-parse-even-better-errors@^2.3.0, json-parse-even-better-errors@^2.3.1: resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w== +json-schema-to-typescript@^11.0.1: + version "11.0.1" + resolved "https://registry.yarnpkg.com/json-schema-to-typescript/-/json-schema-to-typescript-11.0.1.tgz#9203036817ca797f1116cbfe9163e8a4ec948bc3" + integrity sha512-iQFEErdr9PWQUN3kLvaFFdgWAfwBeqH3PMzxza4NpSU/8uadwHKKi66Hgu5Rb3NeVSk85xkwTYIeuah+R0ASeA== + dependencies: + "@apidevtools/json-schema-ref-parser" "https://github.com/bcherny/json-schema-ref-parser.git#984282d34a2993e5243aa35100fe32a63699164d" + "@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" @@ -9806,7 +9937,7 @@ json-schema-traverse@^1.0.0: resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz#ae7bcb3656ab77a73ba5c49bf654f38e6b6860e2" integrity sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug== -json-schema@*, json-schema@0.4.0: +json-schema@*, json-schema@0.4.0, json-schema@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.4.0.tgz#f7de4cf6efab838ebaeb3236474cbba5a1930ab5" integrity sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA== @@ -10307,6 +10438,13 @@ 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.10.1.tgz#db577f42a94c168f676b638d15da8fb073448cab" integrity sha512-BQuhQxPuRl79J5zSXRP+uNzPOyZw2oFI9JLRQ80XswSvg21KMKNtQza9eF42rfI/3Z40RvzBdXgziEkudzjo8A== +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" + lzstring.ts@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/lzstring.ts/-/lzstring.ts-2.0.2.tgz#1d269bd6ab423713f31e614f67018110ed860129" @@ -10527,6 +10665,20 @@ 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" @@ -10838,6 +10990,15 @@ 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" @@ -10863,6 +11024,11 @@ 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== + no-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d" @@ -11217,7 +11383,7 @@ nx@14.4.3, "nx@>=14.4.3 < 16": yargs "^17.4.0" yargs-parser "21.0.1" -object-assign@^4.1.0, object-assign@^4.1.1: +object-assign@^4.0.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= @@ -12105,6 +12271,11 @@ prettier@*, prettier@2.5.1: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.5.1.tgz#fff75fa9d519c54cf0fce328c1017d94546bc56a" integrity sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg== +prettier@^2.6.2: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + pretty-bytes@^5.6.0: version "5.6.0" resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" @@ -13911,6 +14082,20 @@ text-table@^0.2.0: resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4" integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= +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" + throat@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/throat/-/throat-6.0.1.tgz#d514fedad95740c12c2d7fc70ea863eb51ade375" @@ -13946,6 +14131,14 @@ 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" + timsort@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4" @@ -14203,6 +14396,16 @@ 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== + typedarray-to-buffer@^3.1.5: version "3.1.5" resolved "https://registry.yarnpkg.com/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz#a97ee7a9ff42691b9f783ff1bc5112fe3fca9080" From 532a80326ec10278bf88debc050585a0b0a6e769 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 27 Jul 2022 20:15:04 -0400 Subject: [PATCH 02/26] Apply suggestions from code review Co-authored-by: Joshua Chen --- packages/website/plugins/generated-rule-docs.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 0c88e99cf138..4c61543f422a 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -74,8 +74,8 @@ const generatedRuleDocs: Plugin = () => { { lang: 'jsonc', type: 'code', - value: `// .eslintrc.json -{ + meta: 'title=".eslintrc.json"', + value: `{ // note you must disable the base rule as it can report incorrect errors "${file.stem}": "off", "@typescript-eslint/${file.stem}": "${optionLevel}" @@ -153,8 +153,8 @@ const generatedRuleDocs: Plugin = () => { { lang: 'jsonc', type: 'code', - value: `// .eslintrc.json -{ + meta: 'title=".eslintrc.json"', + value: `{ "rules": { "@typescript-eslint/${file.stem}": "${optionLevel}" } From 0b1ce8af39ecd6eb6af3ffcd66381840202d6353 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 27 Jul 2022 20:51:29 -0400 Subject: [PATCH 03/26] First round of changes --- packages/website/docusaurusConfig.ts | 7 ++- .../website/plugins/generated-rule-docs.ts | 46 +++++-------------- yarn.lock | 6 +-- 3 files changed, 19 insertions(+), 40 deletions(-) diff --git a/packages/website/docusaurusConfig.ts b/packages/website/docusaurusConfig.ts index 89a97f1c81e7..2750a983d35e 100644 --- a/packages/website/docusaurusConfig.ts +++ b/packages/website/docusaurusConfig.ts @@ -23,8 +23,11 @@ const presetClassicOptions: PresetClassicOptions = { sidebarPath: require.resolve('./sidebars/sidebar.rules.js'), routeBasePath: 'rules', editUrl: `${githubUrl}/edit/main/packages/website/`, - beforeDefaultRemarkPlugins, - remarkPlugins: [...remarkPlugins, [generatedRuleDocs, {}]], + beforeDefaultRemarkPlugins: [ + ...beforeDefaultRemarkPlugins, + [generatedRuleDocs, {}], + ], + remarkPlugins: remarkPlugins, exclude: ['TEMPLATE.md'], breadcrumbs: false, }, diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 4c61543f422a..38020746ebc0 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -74,12 +74,12 @@ const generatedRuleDocs: Plugin = () => { { lang: 'jsonc', type: 'code', - meta: 'title=".eslintrc.json"', - value: `{ + meta: 'title=".eslintrc.cjs"', + value: `module.exports = { // note you must disable the base rule as it can report incorrect errors "${file.stem}": "off", "@typescript-eslint/${file.stem}": "${optionLevel}" -}`, +};`, } as mdast.Code, { children: [ @@ -153,12 +153,12 @@ const generatedRuleDocs: Plugin = () => { { lang: 'jsonc', type: 'code', - meta: 'title=".eslintrc.json"', - value: `{ + meta: 'title=".eslintrc.cjs"', + value: `module.exports = { "rules": { "@typescript-eslint/${file.stem}": "${optionLevel}" } -}`, +};`, } as mdast.Code, { children: [ @@ -202,35 +202,11 @@ const generatedRuleDocs: Plugin = () => { // 5. Add a notice about coming from ESLint core for extension rules if (meta.docs.extendsBaseRule) { - parent.children.push( - { - type: 'html', - value: '', - } as mdast.HTML, - { - children: [ - { - type: 'text', - value: 'Taken with ❤️ ', - }, - { - children: [ - { - type: 'text', - value: 'from ESLint core', - }, - ], - type: 'link', - url: 'https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md', - }, - ], - type: 'paragraph', - } as mdast.Paragraph, - { - type: 'html', - value: '', - } as mdast.HTML, - ); + parent.children.push({ + type: 'jsx', + value: + 'Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md)', + } as unist.Node); } // TODO: find & use library that converts text to markdown ast diff --git a/yarn.lock b/yarn.lock index 882136e08329..b2a287f3184f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4224,9 +4224,9 @@ integrity sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw== "@types/prettier@^2.6.1": - version "2.6.3" - resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.3.tgz#68ada76827b0010d0db071f739314fa429943d0a" - integrity sha512-ymZk3LEC/fsut+/Q5qejp6R9O1rMxz3XaRHDV6kX8MrGAhOSPqVARbDi+EZvInBpw+BnCX3TD240byVkOfQsHg== + version "2.6.4" + resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.4.tgz#ad899dad022bab6b5a9f0a0fe67c2f7a4a8950ed" + integrity sha512-fOwvpvQYStpb/zHMx0Cauwywu9yLDmzWiiQBC7gJyq5tYLUXFZvDG7VK1B7WBxxjBJNKFOZ0zLoOQn8vmATbhw== "@types/prop-types@*": version "15.7.4" From 2e6b6b47e894a46aada09dc1be012644601659fb Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 27 Jul 2022 21:02:26 -0400 Subject: [PATCH 04/26] Simplify Prettier types --- yarn.lock | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index b2a287f3184f..09d0e3fae1a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4218,12 +4218,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": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.0.tgz#efcbd41937f9ae7434c714ab698604822d890759" - integrity sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw== - -"@types/prettier@^2.6.1": +"@types/prettier@*", "@types/prettier@^2.1.5", "@types/prettier@^2.6.0", "@types/prettier@^2.6.1": version "2.6.4" resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.6.4.tgz#ad899dad022bab6b5a9f0a0fe67c2f7a4a8950ed" integrity sha512-fOwvpvQYStpb/zHMx0Cauwywu9yLDmzWiiQBC7gJyq5tYLUXFZvDG7VK1B7WBxxjBJNKFOZ0zLoOQn8vmATbhw== From 029c2a8b0ea435922ad0643a4b22bef3cc05f55e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 27 Jul 2022 22:38:06 -0400 Subject: [PATCH 05/26] Progress on using defs --- .../eslint-plugin/docs/rules/array-type.md | 7 -- .../eslint-plugin/src/rules/array-type.ts | 21 +++- .../eslint-plugin/src/rules/ban-ts-comment.ts | 47 ++++----- .../utils/src/eslint-utils/applyDefault.ts | 1 + .../website/plugins/generated-rule-docs.ts | 98 +++++++++++-------- 5 files changed, 101 insertions(+), 73 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/array-type.md b/packages/eslint-plugin/docs/rules/array-type.md index fa7be4a4541c..9183db8b63eb 100644 --- a/packages/eslint-plugin/docs/rules/array-type.md +++ b/packages/eslint-plugin/docs/rules/array-type.md @@ -10,13 +10,6 @@ This rule aims to standardize usage of array types within your codebase. ## Options -The rule accepts an options object with the following properties: - -- `default` - sets the array type expected for mutable cases. -- `readonly` - sets the array type expected for readonly arrays. If this is omitted, then the value for `default` will be used. - -Each property can be set to one of three strings: `'array' | 'generic' | 'array-simple'`. - The default config will enforce that all mutable and readonly arrays use the `'array'` syntax. ### `"array"` diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index c84afee195f6..ff9d48080abe 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -83,8 +83,6 @@ type MessageIds = | 'errorStringArraySimple' | 'errorStringGenericSimple'; -const arrayOption = { enum: ['array', 'generic', 'array-simple'] }; - export default util.createRule({ name: 'array-type', meta: { @@ -106,11 +104,24 @@ export default util.createRule({ }, schema: [ { - type: 'object', + $definitions: { + arrayOption: { + enum: ['array', 'generic', 'array-simple'], + tsType: 'ArrayOption', + }, + }, properties: { - default: arrayOption, - readonly: arrayOption, + default: { + $ref: '#/$definitions/arrayOption', + description: 'The array type expected for mutable cases.', + }, + readonly: { + $ref: '#/$definitions/arrayOption', + description: + 'The array type expected for readonly cases. If omitted, the value for `default` will be used.', + }, }, + type: 'object', }, ], }, diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index e5cb60876ea3..1239f0db0c5e 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -14,24 +14,6 @@ interface Options { minimumDescriptionLength?: number; } -const directiveConfigSchema = { - oneOf: [ - { - type: 'boolean', - default: true, - }, - { - enum: ['allow-with-description'], - }, - { - type: 'object', - properties: { - descriptionFormat: { type: 'string' }, - }, - }, - ], -}; - export const defaultMinimumDescriptionLength = 3; type MessageIds = @@ -58,12 +40,33 @@ export default util.createRule<[Options], MessageIds>({ }, schema: [ { + $definitions: { + directiveConfigSchema: { + oneOf: [ + { + type: 'boolean', + default: true, + }, + { + enum: ['allow-with-description'], + }, + { + type: 'object', + properties: { + descriptionFormat: { type: 'string' }, + }, + }, + ], + }, + }, type: 'object', properties: { - 'ts-expect-error': directiveConfigSchema, - 'ts-ignore': directiveConfigSchema, - 'ts-nocheck': directiveConfigSchema, - 'ts-check': directiveConfigSchema, + 'ts-expect-error': { + $ref: '#/$definitions/directiveConfigSchema', + }, + 'ts-ignore': { $ref: '#/$definitions/directiveConfigSchema' }, + 'ts-nocheck': { $ref: '#/$definitions/directiveConfigSchema' }, + 'ts-check': { $ref: '#/$definitions/directiveConfigSchema' }, minimumDescriptionLength: { type: 'number', default: defaultMinimumDescriptionLength, diff --git a/packages/utils/src/eslint-utils/applyDefault.ts b/packages/utils/src/eslint-utils/applyDefault.ts index 85cd3b3653be..b0dbdfeb461c 100644 --- a/packages/utils/src/eslint-utils/applyDefault.ts +++ b/packages/utils/src/eslint-utils/applyDefault.ts @@ -22,6 +22,7 @@ function applyDefault( // For avoiding the type error // `This expression is not callable. Type 'unknown' has no call signatures.ts(2349)` + // @ts-ignore (options as unknown[]).forEach((opt: unknown, i: number) => { if (userOptions[i] !== undefined) { const userOpt = userOptions[i]; diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 38020746ebc0..d588bb83cd3e 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -2,7 +2,6 @@ import type * as unist from 'unist'; import * as mdast from 'mdast'; import { format } from 'prettier'; import type { Plugin } from 'unified'; -import { JSONSchema4Object } from 'json-schema'; import { compile } from 'json-schema-to-typescript'; import * as tseslintParser from '@typescript-eslint/parser'; @@ -146,57 +145,78 @@ const generatedRuleDocs: Plugin = () => { } as mdast.Heading); } - if (meta.schema.length === 0) { - parent.children.splice( - optionsH2Index + 1, - 0, - { - lang: 'jsonc', - type: 'code', - meta: 'title=".eslintrc.cjs"', - value: `module.exports = { + parent.children.splice(optionsH2Index + 1, 0, { + lang: 'jsonc', + type: 'code', + meta: 'title=".eslintrc.cjs"', + value: `module.exports = { "rules": { "@typescript-eslint/${file.stem}": "${optionLevel}" } };`, - } as mdast.Code, + } as mdast.Code); + + if (meta.schema.length === 0) { + parent.children.splice(optionsH2Index + 2, 0, { + children: [ + { + type: 'text', + value: 'This rule is not configurable.', + }, + ], + type: 'paragraph', + } as mdast.Paragraph); + } else { + const optionsSchema = + meta.schema instanceof Array ? meta.schema[0] : meta.schema; + + parent.children.splice( + optionsH2Index + 2, + 0, { children: [ { type: 'text', - value: 'This rule is not configurable.', - }, + value: `This rule accepts an options ${ + 'enum' in optionsSchema + ? 'string of the following possible values' + : 'object with the following properties' + }:`, + } as mdast.Text, ], type: 'paragraph', } as mdast.Paragraph, - ); - } else { - const optionsInterface = await compile( { - title: `Options`, - ...(meta.schema[0] as JSONSchema4Object), - }, - file.stem, - { additionalProperties: false, bannerComment: '' }, + lang: 'ts', + type: 'code', + value: [ + ( + await compile( + { + title: `Options`, + ...optionsSchema, + }, + file.stem, + { + additionalProperties: false, + bannerComment: '', + declareExternallyReferenced: true, + }, + ) + ).replace(/^export /g, ''), + format( + `const defaultOptions: Options = ${JSON.stringify( + rule.defaultOptions, + )};`, + { + parser: tseslintParser.parse, + }, + ), + ] + .join(EOL) + .trim(), + } as mdast.Code, ); - - parent.children.splice(optionsH2Index + 1, 0, { - lang: 'ts', - type: 'code', - value: [ - optionsInterface.replace(/^export /g, ''), - format( - `const defaultOptions: Options = ${JSON.stringify( - rule.defaultOptions, - )};`, - { - parser: tseslintParser.parse, - }, - ), - ] - .join(EOL) - .trim(), - } as mdast.Code); } } From 30a08627b2aff2634664ed8a6542c0719e5adc85 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 14:45:42 -0400 Subject: [PATCH 06/26] Progress, through the letter 'd' for rules --- .../eslint-plugin/docs/rules/ban-types.md | 198 ++++++------------ .../eslint-plugin/docs/rules/brace-style.md | 12 +- .../rules/class-literal-property-style.md | 6 +- .../eslint-plugin/docs/rules/comma-dangle.md | 28 +-- .../eslint-plugin/docs/rules/comma-spacing.md | 20 -- .../rules/consistent-generic-constructors.md | 23 +- .../rules/consistent-indexed-object-style.md | 32 ++- .../docs/rules/consistent-type-assertions.md | 22 +- .../docs/rules/consistent-type-definitions.md | 25 +-- .../docs/rules/consistent-type-exports.md | 17 +- .../docs/rules/consistent-type-imports.md | 20 +- .../docs/rules/default-param-last.md | 24 +-- .../eslint-plugin/docs/rules/dot-notation.md | 18 +- .../rules/explicit-function-return-type.md | 2 +- .../rules/explicit-member-accessibility.md | 2 +- .../rules/explicit-module-boundary-types.md | 2 +- .../docs/rules/func-call-spacing.md | 2 +- packages/eslint-plugin/docs/rules/indent.md | 2 +- .../docs/rules/init-declarations.md | 2 +- .../docs/rules/keyword-spacing.md | 2 +- .../docs/rules/lines-between-class-members.md | 2 +- .../docs/rules/no-array-constructor.md | 2 +- .../docs/rules/no-dupe-class-members.md | 2 +- .../docs/rules/no-duplicate-imports.md | 2 +- .../docs/rules/no-empty-function.md | 4 +- .../docs/rules/no-extra-parens.md | 2 +- .../eslint-plugin/docs/rules/no-extra-semi.md | 2 +- .../docs/rules/no-implied-eval.md | 2 +- .../docs/rules/no-invalid-this.md | 2 +- .../eslint-plugin/docs/rules/no-loop-func.md | 2 +- .../docs/rules/no-loss-of-precision.md | 2 +- .../eslint-plugin/docs/rules/no-redeclare.md | 2 +- .../docs/rules/no-restricted-imports.md | 2 +- .../eslint-plugin/docs/rules/no-shadow.md | 2 +- .../docs/rules/no-throw-literal.md | 2 +- .../docs/rules/no-unused-expressions.md | 2 +- .../docs/rules/no-unused-vars.md | 2 +- .../docs/rules/no-use-before-define.md | 2 +- .../docs/rules/no-useless-constructor.md | 2 +- .../docs/rules/object-curly-spacing.md | 2 +- packages/eslint-plugin/docs/rules/quotes.md | 2 +- packages/eslint-plugin/docs/rules/semi.md | 2 +- .../docs/rules/space-before-blocks.md | 2 +- .../docs/rules/space-before-function-paren.md | 2 +- .../eslint-plugin/src/rules/array-type.ts | 9 +- .../eslint-plugin/src/rules/ban-ts-comment.ts | 10 +- packages/eslint-plugin/src/rules/ban-types.ts | 7 +- .../utils/src/eslint-utils/applyDefault.ts | 1 - .../website/plugins/generated-rule-docs.ts | 115 +++++----- 49 files changed, 219 insertions(+), 432 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index 256b12372fe7..807cfeeab43e 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -2,7 +2,7 @@ > > See **https://typescript-eslint.io/rules/ban-types** for documentation. -Some builtin types have aliases, some types are considered dangerous or harmful. +Some built-in types have aliases, while some types are considered dangerous or harmful. It's often a good idea to ban certain types to help with consistency and safety. ## Rule Details @@ -10,24 +10,69 @@ It's often a good idea to ban certain types to help with consistency and safety. This rule bans specific types and can suggest alternatives. Note that it does not ban the corresponding runtime objects from being used. -## Options +Examples of code with the default options: + + + +### ❌ Incorrect + +```ts +// use lower-case primitives for consistency +const str: String = 'foo'; +const bool: Boolean = true; +const num: Number = 1; +const symb: Symbol = Symbol('foo'); +const bigInt: BigInt = 1n; + +// use a proper function type +const func: Function = () => 1; + +// use safer object types +const lowerObj: Object = {}; +const capitalObj: Object = { a: 'string' }; + +const curly1: {} = 1; +const curly2: {} = { a: 'string' }; +``` + +### ✅ Correct ```ts -type Options = { - types?: { - [typeName: string]: - | false - | string - | { - message: string; - fixWith?: string; - }; - }; - extendDefaults?: boolean; -}; +// use lower-case primitives for consistency +const str: string = 'foo'; +const bool: boolean = true; +const num: number = 1; +const symb: symbol = Symbol('foo'); +const bigInt: bigint = 1n; + +// use a proper function type +const func: () => number = () => 1; + +// use safer object types +const lowerObj: object = {}; +const capitalObj: { a: string } = { a: 'string' }; + +const curly1: number = 1; +const curly2: Record<'a', string> = { a: 'string' }; ``` -The rule accepts a single object as options. +## Options + +The default options provide a set of "best practices", intended to provide safety and standardization in your codebase: + +- Don't use the upper-case primitive types, you should use the lower-case types for consistency. +- Avoid the `Function` type, as it provides little safety for the following reasons: + - It provides no type safety when calling the value, which means it's easy to provide the wrong arguments. + - It accepts class declarations, which will fail when called, as they are called without the `new` keyword. +- Avoid the `Object` and `{}` types, as they mean "any non-nullish value". + - This is a point of confusion for many developers, who think it means "any object type". + - See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492). + +:::important + +The default options suggest using `Record`; this was a stylistic decision, as the built-in `Record` type is considered to look cleaner. + +::: ### `types` @@ -74,126 +119,3 @@ Example configuration: ] } ``` - -### Default Options - -The default options provide a set of "best practices", intended to provide safety and standardization in your codebase: - -- Don't use the upper-case primitive types, you should use the lower-case types for consistency. -- Avoid the `Function` type, as it provides little safety for the following reasons: - - It provides no type safety when calling the value, which means it's easy to provide the wrong arguments. - - It accepts class declarations, which will fail when called, as they are called without the `new` keyword. -- Avoid the `Object` and `{}` types, as they mean "any non-nullish value". - - This is a point of confusion for many developers, who think it means "any object type". - - See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492). - -:::important - -The default options suggest using `Record`; this was a stylistic decision, as the built-in `Record` type is considered to look cleaner. - -::: - -
-Default Options - -```ts -const defaultTypes = { - String: { - message: 'Use string instead', - fixWith: 'string', - }, - Boolean: { - message: 'Use boolean instead', - fixWith: 'boolean', - }, - Number: { - message: 'Use number instead', - fixWith: 'number', - }, - Symbol: { - message: 'Use symbol instead', - fixWith: 'symbol', - }, - BigInt: { - message: 'Use bigint instead', - fixWith: 'bigint', - }, - - Function: { - message: [ - 'The `Function` type accepts any function-like value.', - 'It provides no type safety when calling the function, which can be a common source of bugs.', - 'It also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.', - 'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.', - ].join('\n'), - }, - - // object typing - Object: { - message: [ - 'The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.', - '- If you want a type meaning "any object", you probably want `Record` instead.', - '- If you want a type meaning "any value", you probably want `unknown` instead.', - ].join('\n'), - }, - '{}': { - message: [ - '`{}` actually means "any non-nullish value".', - '- If you want a type meaning "any object", you probably want `Record` instead.', - '- If you want a type meaning "any value", you probably want `unknown` instead.', - ].join('\n'), - }, -}; -``` - -
- -### Examples - -Examples of code with the default options: - - - -#### ❌ Incorrect - -```ts -// use lower-case primitives for consistency -const str: String = 'foo'; -const bool: Boolean = true; -const num: Number = 1; -const symb: Symbol = Symbol('foo'); -const bigInt: BigInt = 1n; - -// use a proper function type -const func: Function = () => 1; - -// use safer object types -const capitalObj1: Object = 1; -const capitalObj2: Object = { a: 'string' }; - -const curly1: {} = 1; -const curly2: {} = { a: 'string' }; -``` - -#### ✅ Correct - -```ts -// use lower-case primitives for consistency -const str: string = 'foo'; -const bool: boolean = true; -const num: number = 1; -const symb: symbol = Symbol('foo'); -const bigInt: bigint = 1n; - -// use a proper function type -const func: () => number = () => 1; - -// use safer object types -const lowerObj: object = {}; - -const capitalObj1: number = 1; -const capitalObj2: { a: string } = { a: 'string' }; - -const curly1: number = 1; -const curly2: Record<'a', string> = { a: 'string' }; -``` diff --git a/packages/eslint-plugin/docs/rules/brace-style.md b/packages/eslint-plugin/docs/rules/brace-style.md index 923a841fcbde..6515a39f40a6 100644 --- a/packages/eslint-plugin/docs/rules/brace-style.md +++ b/packages/eslint-plugin/docs/rules/brace-style.md @@ -13,16 +13,6 @@ It adds support for `enum`, `interface`, `namespace` and `module` declarations. { // note you must disable the base rule as it can report incorrect errors "brace-style": "off", - "@typescript-eslint/brace-style": ["error"] + "@typescript-eslint/brace-style": "error" } ``` - -## Options - -See [`eslint/brace-style` options](https://eslint.org/docs/rules/brace-style#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/brace-style.md) - - diff --git a/packages/eslint-plugin/docs/rules/class-literal-property-style.md b/packages/eslint-plugin/docs/rules/class-literal-property-style.md index 5b577e16136f..e12d4a4b6e67 100644 --- a/packages/eslint-plugin/docs/rules/class-literal-property-style.md +++ b/packages/eslint-plugin/docs/rules/class-literal-property-style.md @@ -5,7 +5,7 @@ When writing TypeScript applications, it's typically safe to store literal values on classes using fields with the `readonly` modifier to prevent them from being reassigned. When writing TypeScript libraries that could be used by JavaScript users however, it's typically safer to expose these literals using `getter`s, since the `readonly` modifier is enforced at compile type. -## Rule Details +## Options This rule aims to ensure that literals exposed by classes are done so consistently, in one of the two style described above. By default this rule prefers the `fields` style as it means JS doesn't have to setup & teardown a function closure. @@ -17,7 +17,7 @@ This is because these types can be mutated and carry with them more complex impl ::: -### The `fields` style +### `"fields"` This style checks for any getter methods that return literal values, and requires them to be defined using fields with the `readonly` modifier instead. @@ -60,7 +60,7 @@ class Mx { } ``` -### The `getters` style +### `"getters"` This style checks for any `readonly` fields that are assigned literal values, and requires them to be defined as getters instead. This style pairs well with the [`@typescript-eslint/prefer-readonly`](prefer-readonly.md) rule, diff --git a/packages/eslint-plugin/docs/rules/comma-dangle.md b/packages/eslint-plugin/docs/rules/comma-dangle.md index 0af19151a0eb..1055d3b39781 100644 --- a/packages/eslint-plugin/docs/rules/comma-dangle.md +++ b/packages/eslint-plugin/docs/rules/comma-dangle.md @@ -11,30 +11,8 @@ See the [ESLint documentation](https://eslint.org/docs/rules/comma-dangle) for m ## How to Use -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "comma-dangle": "off", - "@typescript-eslint/comma-dangle": ["error"] -} -``` - In addition to the options supported by the `comma-dangle` rule in ESLint core, the rule adds the following options: -## Options - -This rule has a string option and an object option. - -- Object option: - - - `"enums"` is for trailing comma in enum. (e.g. `enum Foo = {Bar,}`) - - `"generics"` is for trailing comma in generic. (e.g. `function foo() {}`) - - `"tuples"` is for trailing comma in tuple. (e.g. `type Foo = [string,]`) - -- [See the other options allowed](https://eslint.org/docs/rules/comma-dangle#options) - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/comma-dangle.md) - - +- `"enums"` is for trailing comma in enum. (e.g. `enum Foo = {Bar,}`) +- `"generics"` is for trailing comma in generic. (e.g. `function foo() {}`) +- `"tuples"` is for trailing comma in tuple. (e.g. `type Foo = [string,]`) diff --git a/packages/eslint-plugin/docs/rules/comma-spacing.md b/packages/eslint-plugin/docs/rules/comma-spacing.md index 28ea99602d90..4f8a09bc329a 100644 --- a/packages/eslint-plugin/docs/rules/comma-spacing.md +++ b/packages/eslint-plugin/docs/rules/comma-spacing.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/comma-spacing`](https://eslint.org/docs/rules/comma-spacing) rule. It adds support for trailing comma in a types parameters list. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "comma-spacing": "off", - "@typescript-eslint/comma-spacing": ["error"] -} -``` - -## Options - -See [`eslint/comma-spacing` options](https://eslint.org/docs/rules/comma-spacing#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/comma-spacing.md) - - diff --git a/packages/eslint-plugin/docs/rules/consistent-generic-constructors.md b/packages/eslint-plugin/docs/rules/consistent-generic-constructors.md index e62ba44bbb91..08839a56adaf 100644 --- a/packages/eslint-plugin/docs/rules/consistent-generic-constructors.md +++ b/packages/eslint-plugin/docs/rules/consistent-generic-constructors.md @@ -14,28 +14,15 @@ const map = new Map(); This rule ensures that type arguments appear consistently on one side of the declaration. -## Options - -```jsonc -{ - "rules": { - "@typescript-eslint/consistent-generic-constructors": [ - "error", - "constructor" - ] - } -} -``` - -This rule takes a string option: - -- If it's set to `constructor` (default), type arguments that **only** appear on the type annotation are disallowed. -- If it's set to `type-annotation`, type arguments that **only** appear on the constructor are disallowed. - ## Rule Details The rule never reports when there are type parameters on both sides, or neither sides of the declaration. It also doesn't report if the names of the type annotation and the constructor don't match. +## Options + +- `constructor` _(default)_: type arguments that **only** appear on the type annotation are disallowed. +- `type-annotation`: type arguments that **only** appear on the constructor are disallowed. + ### `constructor` diff --git a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md index 56c22fec4db7..709425faee9e 100644 --- a/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md +++ b/packages/eslint-plugin/docs/rules/consistent-indexed-object-style.md @@ -16,34 +16,24 @@ type Foo = { type Foo = Record; ``` -## Options - -- `"record"`: Set to `"record"` to only allow the `Record` type. Set to `"index-signature"` to only allow index signatures. (Defaults to `"record"`) - -For example: - -```json -{ - "@typescript-eslint/consistent-indexed-object-style": [ - "error", - "index-signature" - ] -} -``` - ## Rule Details This rule enforces a consistent way to define records. -### `record` +## Options + +- `"record"` _(default)_: only allow the `Record` type. +- `"index-signature"`: only allow index signatures. -Examples of code with `record` option. +### `record` #### ❌ Incorrect ```ts +/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "record"] */ + interface Foo { [key: string]: unknown; } @@ -56,24 +46,28 @@ type Foo = { #### ✅ Correct ```ts +/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "record"] */ + type Foo = Record; ``` ### `index-signature` -Examples of code with `index-signature` option. - #### ❌ Incorrect ```ts +/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "index-signature"] */ + type Foo = Record; ``` #### ✅ Correct ```ts +/* eslint @typescript-eslint/consistent-indexed-object-style: ["error", "index-signature"] */ + interface Foo { [key: string]: unknown; } diff --git a/packages/eslint-plugin/docs/rules/consistent-type-assertions.md b/packages/eslint-plugin/docs/rules/consistent-type-assertions.md index bb624e83b9d6..1bfdf7d5f896 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-assertions.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-assertions.md @@ -10,26 +10,10 @@ Type assertions are also commonly referred as "type casting" in TypeScript (even In addition to ensuring that type assertions are written in a consistent way, this rule also helps make your codebase more type-safe. -`const` assertions, [introduced in TypeScript 3.4](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions), is always allowed by this rule. Examples of it include `let x = "hello" as const;` and `let x = "hello";`. +[`const` assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) are always allowed by this rule. Examples of them include `let x = "hello" as const;` and `let x = "hello";`. ## Options -```ts -type Options = - | { - assertionStyle: 'as' | 'angle-bracket'; - objectLiteralTypeAssertions: 'allow' | 'allow-as-parameter' | 'never'; - } - | { - assertionStyle: 'never'; - }; - -const defaultOptions: Options = { - assertionStyle: 'as', - objectLiteralTypeAssertions: 'allow', -}; -``` - ### `assertionStyle` This option defines the expected assertion style. Valid values for `assertionStyle` are: @@ -52,7 +36,7 @@ The const assertion `const x = { foo: 1 } as const`, introduced in TypeScript 3. Assertions to `any` are also ignored by this option. -Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }` +Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'never' }`: @@ -80,7 +64,7 @@ function foo(): T { -Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'allow-as-parameter' }` +Examples of code for `{ assertionStyle: 'as', objectLiteralTypeAssertions: 'allow-as-parameter' }`: diff --git a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md index 625bb7ba4935..d14948db9e1e 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-definitions.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-definitions.md @@ -20,35 +20,26 @@ interface T2 { ## Options -This rule accepts one string option: - -- `"interface"`: enforce using `interface`s for object type definitions. +- `"interface"` _(default)_: enforce using `interface`s for object type definitions. - `"type"`: enforce using `type`s for object type definitions. -For example: - -```jsonc -{ - // Use type for object definitions - "@typescript-eslint/consistent-type-definitions": ["error", "type"] -} -``` - ### `interface` -Examples of code with `interface` option. - #### ❌ Incorrect ```ts +/* eslint @typescript-eslint/consistent-type-definitions: ["error", "interface"] */ + type T = { x: number }; ``` #### ✅ Correct ```ts +/* eslint @typescript-eslint/consistent-type-definitions: ["error", "interface"] */ + type T = string; type Foo = string | {}; @@ -59,13 +50,13 @@ interface T { ### `type` -Examples of code with `type` option. - #### ❌ Incorrect ```ts +/* eslint @typescript-eslint/consistent-type-definitions: ["error", "type"] */ + interface T { x: number; } @@ -74,6 +65,8 @@ interface T { #### ✅ Correct ```ts +/* eslint @typescript-eslint/consistent-type-definitions: ["error", "type"] */ + type T = { x: number }; ``` diff --git a/packages/eslint-plugin/docs/rules/consistent-type-exports.md b/packages/eslint-plugin/docs/rules/consistent-type-exports.md index 5383a1225b10..dae0818672d4 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-exports.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-exports.md @@ -2,14 +2,12 @@ > > See **https://typescript-eslint.io/rules/consistent-type-exports** for documentation. -TypeScript 3.8 added support for type-only exports. - Type-only exports allow you to specify that 1 or more named exports are exported as type-only. This allows transpilers to drop exports without knowing the types of the dependencies. ## Rule Details -This rule aims to standardize the use of type exports style across a codebase. +This rule aims to standardize the use of type exports style. Given a class `Button`, and an interface `ButtonProps`, examples of code: @@ -21,11 +19,13 @@ Given a class `Button`, and an interface `ButtonProps`, examples of code: interface ButtonProps { onClick: () => void; } + class Button implements ButtonProps { onClick() { console.log('button!'); } } + export { Button, ButtonProps }; ``` @@ -46,16 +46,6 @@ export type { ButtonProps }; ## Options -```ts -interface Options { - fixMixedExportsWithInlineTypeSpecifier?: boolean; -} - -const defaultOptions: Options = { - fixMixedExportsWithInlineTypeSpecifier: false, -}; -``` - ### `fixMixedExportsWithInlineTypeSpecifier` When this is set to true, the rule will autofix "mixed" export cases using TS 4.5's "inline type specifier". @@ -106,6 +96,5 @@ export { Button, type ButtonProps } from 'some-library'; ## When Not To Use It -- If you are using a TypeScript version less than 3.8, then you will not be able to use this rule as type exports are not supported. - If you specifically want to use both export kinds for stylistic reasons, you can disable this rule. - If you use `--isolatedModules` the compiler would error if a type is not re-exported using `export type`. If you also don't wish to enforce one style over the other, you can disable this rule. diff --git a/packages/eslint-plugin/docs/rules/consistent-type-imports.md b/packages/eslint-plugin/docs/rules/consistent-type-imports.md index be63fff55516..c00a96e4a12d 100644 --- a/packages/eslint-plugin/docs/rules/consistent-type-imports.md +++ b/packages/eslint-plugin/docs/rules/consistent-type-imports.md @@ -2,27 +2,14 @@ > > See **https://typescript-eslint.io/rules/consistent-type-imports** for documentation. -TypeScript 3.8 added support for type-only imports. Type-only imports allow you to specify that an import can only be used in a type location, allowing certain optimizations within compilers. ## Rule Details -This rule aims to standardize the use of type imports style across the codebase. +This rule aims to standardize the use of type imports style. ## Options -```ts -type Options = { - prefer: 'type-imports' | 'no-type-imports'; - disallowTypeAnnotations: boolean; -}; - -const defaultOptions: Options = { - prefer: 'type-imports', - disallowTypeAnnotations: true, -}; -``` - ### `prefer` This option defines the expected import kind for type-only imports. Valid values for `prefer` are: @@ -50,10 +37,10 @@ const x: Bar = 1; ### `disallowTypeAnnotations` -If `true`, type imports in type annotations (`import()`) is not allowed. +If `true`, type imports in type annotations (`import()`) are not allowed. Default is `true`. -Examples of **incorrect** code with `{disallowTypeAnnotations: true}`. +Examples of **incorrect** code with `{disallowTypeAnnotations: true}`: ```ts type T = import('Foo').Foo; @@ -62,5 +49,4 @@ const x: import('Bar') = 1; ## When Not To Use It -- If you are not using TypeScript 3.8 (or greater), then you will not be able to use this rule, as type-only imports are not allowed. - If you specifically want to use both import kinds for stylistic reasons, you can disable this rule. diff --git a/packages/eslint-plugin/docs/rules/default-param-last.md b/packages/eslint-plugin/docs/rules/default-param-last.md index 3de8f8c8cd7a..f58bac76fdd1 100644 --- a/packages/eslint-plugin/docs/rules/default-param-last.md +++ b/packages/eslint-plugin/docs/rules/default-param-last.md @@ -12,7 +12,7 @@ It adds support for optional parameters. ### ❌ Incorrect ```ts -/* eslint @typescript-eslint/default-param-last: ["error"] */ +/* eslint @typescript-eslint/default-param-last: "error" */ function f(a = 0, b: number) {} function f(a: number, b = 0, c: number) {} @@ -28,7 +28,7 @@ class Foo { ### ✅ Correct ```ts -/* eslint @typescript-eslint/default-param-last: ["error"] */ +/* eslint @typescript-eslint/default-param-last: "error" */ function f(a = 0) {} function f(a: number, b = 0) {} @@ -42,23 +42,3 @@ class Foo { constructor(public a, private b?: number) {} } ``` - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "default-param-last": "off", - "@typescript-eslint/default-param-last": ["error"] -} -``` - -## Options - -See [`eslint/default-param-last` options](https://eslint.org/docs/rules/default-param-last#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/default-param-last.md) - - diff --git a/packages/eslint-plugin/docs/rules/dot-notation.md b/packages/eslint-plugin/docs/rules/dot-notation.md index e0c7b390e5ad..7cb86db23914 100644 --- a/packages/eslint-plugin/docs/rules/dot-notation.md +++ b/packages/eslint-plugin/docs/rules/dot-notation.md @@ -10,19 +10,8 @@ It adds: - Support for optionally ignoring computed `private` and/or `protected` member access. - Compatibility with TypeScript's `noPropertyAccessFromIndexSignature` option. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "dot-notation": "off", - "@typescript-eslint/dot-notation": ["error"] -} -``` - ## Options -See [`eslint/dot-notation`](https://eslint.org/docs/rules/dot-notation#options) options. This rule adds the following options: ```ts @@ -31,6 +20,7 @@ interface Options extends BaseDotNotationOptions { allowProtectedClassPropertyAccess?: boolean; allowIndexSignaturePropertyAccess?: boolean; } + const defaultOptions: Options = { ...baseDotNotationDefaultOptions, allowPrivateClassPropertyAccess: false, @@ -43,7 +33,7 @@ If the TypeScript compiler option `noPropertyAccessFromIndexSignature` is set to ### `allowPrivateClassPropertyAccess` -Example of a correct code when `allowPrivateClassPropertyAccess` is set to `true` +Example of a correct code when `allowPrivateClassPropertyAccess` is set to `true`: ```ts class X { @@ -56,7 +46,7 @@ x['priv_prop'] = 123; ### `allowProtectedClassPropertyAccess` -Example of a correct code when `allowProtectedClassPropertyAccess` is set to `true` +Example of a correct code when `allowProtectedClassPropertyAccess` is set to `true`: ```ts class X { @@ -69,7 +59,7 @@ x['protected_prop'] = 123; ### `allowIndexSignaturePropertyAccess` -Example of correct code when `allowIndexSignaturePropertyAccess` is set to `true` +Example of correct code when `allowIndexSignaturePropertyAccess` is set to `true`: ```ts class X { diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index d42e793a5cb2..b6513db65b72 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -108,7 +108,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. // enable the rule specifically for TypeScript files "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { - "@typescript-eslint/explicit-function-return-type": ["error"] + "@typescript-eslint/explicit-function-return-type": "error" } } ] diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md index 98f297000bd5..c321bf76c328 100644 --- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md @@ -52,7 +52,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. // enable the rule specifically for TypeScript files "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { - "@typescript-eslint/explicit-member-accessibility": ["error"] + "@typescript-eslint/explicit-member-accessibility": "error" } } ] diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md index 9aa84b23a7c7..eba5310c0482 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md @@ -123,7 +123,7 @@ If you are working on a codebase within which you lint non-TypeScript code (i.e. // enable the rule specifically for TypeScript files "files": ["*.ts", "*.mts", "*.cts", "*.tsx"], "rules": { - "@typescript-eslint/explicit-module-boundary-types": ["error"] + "@typescript-eslint/explicit-module-boundary-types": "error" } } ] diff --git a/packages/eslint-plugin/docs/rules/func-call-spacing.md b/packages/eslint-plugin/docs/rules/func-call-spacing.md index 315e53882409..a304bb5a0573 100644 --- a/packages/eslint-plugin/docs/rules/func-call-spacing.md +++ b/packages/eslint-plugin/docs/rules/func-call-spacing.md @@ -13,7 +13,7 @@ It adds support for generic type parameters on function calls. { // note you must disable the base rule as it can report incorrect errors "func-call-spacing": "off", - "@typescript-eslint/func-call-spacing": ["error"] + "@typescript-eslint/func-call-spacing": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/indent.md b/packages/eslint-plugin/docs/rules/indent.md index 063087231a5d..3f8810e7ba21 100644 --- a/packages/eslint-plugin/docs/rules/indent.md +++ b/packages/eslint-plugin/docs/rules/indent.md @@ -17,7 +17,7 @@ It adds support for TypeScript nodes. { // note you must disable the base rule as it can report incorrect errors "indent": "off", - "@typescript-eslint/indent": ["error"] + "@typescript-eslint/indent": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/init-declarations.md b/packages/eslint-plugin/docs/rules/init-declarations.md index 3569bd70602a..7d090540c24d 100644 --- a/packages/eslint-plugin/docs/rules/init-declarations.md +++ b/packages/eslint-plugin/docs/rules/init-declarations.md @@ -13,7 +13,7 @@ It adds support for TypeScript's `declare` variables. { // note you must disable the base rule as it can report incorrect errors "init-declarations": "off", - "@typescript-eslint/init-declarations": ["error"] + "@typescript-eslint/init-declarations": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index 6bf0de5e1870..bce66e27dd7b 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -13,7 +13,7 @@ This version adds support for generic type parameters on function calls. { // note you must disable the base rule as it can report incorrect errors "keyword-spacing": "off", - "@typescript-eslint/keyword-spacing": ["error"] + "@typescript-eslint/keyword-spacing": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/lines-between-class-members.md b/packages/eslint-plugin/docs/rules/lines-between-class-members.md index 2d9de3a73ce7..fa77cebfc2dc 100644 --- a/packages/eslint-plugin/docs/rules/lines-between-class-members.md +++ b/packages/eslint-plugin/docs/rules/lines-between-class-members.md @@ -17,7 +17,7 @@ See the [ESLint documentation](https://eslint.org/docs/rules/lines-between-class { // note you must disable the base rule as it can report incorrect errors "lines-between-class-members": "off", - "@typescript-eslint/lines-between-class-members": ["error"] + "@typescript-eslint/lines-between-class-members": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-array-constructor.md b/packages/eslint-plugin/docs/rules/no-array-constructor.md index 6251ddf53dc8..09ac6c5f1979 100644 --- a/packages/eslint-plugin/docs/rules/no-array-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-array-constructor.md @@ -36,7 +36,7 @@ new Array(someOtherArray.length); { // note you must disable the base rule as it can report incorrect errors "no-array-constructor": "off", - "@typescript-eslint/no-array-constructor": ["error"] + "@typescript-eslint/no-array-constructor": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md index 32e6c5dfdfba..07346ccb3152 100644 --- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md +++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md @@ -13,7 +13,7 @@ It adds support for TypeScript's method overload definitions. { // note you must disable the base rule as it can report incorrect errors "no-dupe-class-members": "off", - "@typescript-eslint/no-dupe-class-members": ["error"] + "@typescript-eslint/no-dupe-class-members": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md index 613043bedb4f..0ee781203cfc 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md @@ -17,7 +17,7 @@ This version adds support for type-only import and export. { // note you must disable the base rule as it can report incorrect errors "no-duplicate-imports": "off", - "@typescript-eslint/no-duplicate-imports": ["error"] + "@typescript-eslint/no-duplicate-imports": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md index 121db4ff8786..40004a958e86 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-function.md +++ b/packages/eslint-plugin/docs/rules/no-empty-function.md @@ -15,7 +15,7 @@ One example of valid TypeScript specific code that would otherwise trigger the ` { // note you must disable the base rule as it can report incorrect errors "no-empty-function": "off", - "@typescript-eslint/no-empty-function": ["error"] + "@typescript-eslint/no-empty-function": "error" } ``` @@ -100,7 +100,7 @@ class Foo extends Base { { // note you must disable the base rule as it can report incorrect errors "no-empty-function": "off", - "@typescript-eslint/no-empty-function": ["error"] + "@typescript-eslint/no-empty-function": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-extra-parens.md b/packages/eslint-plugin/docs/rules/no-extra-parens.md index 8bd5ac2c7d68..b8d6df0d34ab 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-parens.md +++ b/packages/eslint-plugin/docs/rules/no-extra-parens.md @@ -13,7 +13,7 @@ It adds support for TypeScript type assertions. { // note you must disable the base rule as it can report incorrect errors "no-extra-parens": "off", - "@typescript-eslint/no-extra-parens": ["error"] + "@typescript-eslint/no-extra-parens": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-extra-semi.md b/packages/eslint-plugin/docs/rules/no-extra-semi.md index 0b94c91de590..e2bbf065ff14 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-semi.md +++ b/packages/eslint-plugin/docs/rules/no-extra-semi.md @@ -13,7 +13,7 @@ It adds support for class properties. { // note you must disable the base rule as it can report incorrect errors "no-extra-semi": "off", - "@typescript-eslint/no-extra-semi": ["error"] + "@typescript-eslint/no-extra-semi": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-implied-eval.md b/packages/eslint-plugin/docs/rules/no-implied-eval.md index 5cd9a9113a5d..144d958bb5c7 100644 --- a/packages/eslint-plugin/docs/rules/no-implied-eval.md +++ b/packages/eslint-plugin/docs/rules/no-implied-eval.md @@ -100,7 +100,7 @@ setTimeout(Foo.fn, 100); { // note you must disable the base rule as it can report incorrect errors "no-implied-eval": "off", - "@typescript-eslint/no-implied-eval": ["error"] + "@typescript-eslint/no-implied-eval": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-invalid-this.md b/packages/eslint-plugin/docs/rules/no-invalid-this.md index 22e7de7260bf..92480b8be043 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-this.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-this.md @@ -13,7 +13,7 @@ It adds support for TypeScript's `this` parameters. { // note you must disable the base rule as it can report incorrect errors "no-invalid-this": "off", - "@typescript-eslint/no-invalid-this": ["error"] + "@typescript-eslint/no-invalid-this": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-loop-func.md b/packages/eslint-plugin/docs/rules/no-loop-func.md index 906ab28e856a..0f984f7e40bb 100644 --- a/packages/eslint-plugin/docs/rules/no-loop-func.md +++ b/packages/eslint-plugin/docs/rules/no-loop-func.md @@ -13,7 +13,7 @@ It adds support for TypeScript types. { // note you must disable the base rule as it can report incorrect errors "no-loop-func": "off", - "@typescript-eslint/no-loop-func": ["error"] + "@typescript-eslint/no-loop-func": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md index bf0ed85f39d3..3252ad1ed850 100644 --- a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md +++ b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md @@ -14,7 +14,7 @@ Note that this rule requires ESLint v7. { // note you must disable the base rule as it can report incorrect errors "no-loss-of-precision": "off", - "@typescript-eslint/no-loss-of-precision": ["error"] + "@typescript-eslint/no-loss-of-precision": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-redeclare.md b/packages/eslint-plugin/docs/rules/no-redeclare.md index 4ebaba2ee5ee..9b10f6e2a264 100644 --- a/packages/eslint-plugin/docs/rules/no-redeclare.md +++ b/packages/eslint-plugin/docs/rules/no-redeclare.md @@ -13,7 +13,7 @@ It adds support for TypeScript function overloads, and declaration merging. { // note you must disable the base rule as it can report incorrect errors "no-redeclare": "off", - "@typescript-eslint/no-redeclare": ["error"] + "@typescript-eslint/no-redeclare": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-restricted-imports.md b/packages/eslint-plugin/docs/rules/no-restricted-imports.md index 89f615c194e2..a2a7d8d7ab6b 100644 --- a/packages/eslint-plugin/docs/rules/no-restricted-imports.md +++ b/packages/eslint-plugin/docs/rules/no-restricted-imports.md @@ -12,7 +12,7 @@ This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/d { // note you must disable the base rule as it can report incorrect errors "no-restricted-imports": "off", - "@typescript-eslint/no-restricted-imports": ["error"] + "@typescript-eslint/no-restricted-imports": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-shadow.md b/packages/eslint-plugin/docs/rules/no-shadow.md index 3da0a6bc6fbd..09aecfd0f4f9 100644 --- a/packages/eslint-plugin/docs/rules/no-shadow.md +++ b/packages/eslint-plugin/docs/rules/no-shadow.md @@ -13,7 +13,7 @@ It adds support for TypeScript's `this` parameters and global augmentation, and { // note you must disable the base rule as it can report incorrect errors "no-shadow": "off", - "@typescript-eslint/no-shadow": ["error"] + "@typescript-eslint/no-shadow": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-throw-literal.md b/packages/eslint-plugin/docs/rules/no-throw-literal.md index a95aeb1a06b5..c8b208691b4c 100644 --- a/packages/eslint-plugin/docs/rules/no-throw-literal.md +++ b/packages/eslint-plugin/docs/rules/no-throw-literal.md @@ -91,7 +91,7 @@ throw new CustomError(); { // note you must disable the base rule as it can report incorrect errors "no-throw-literal": "off", - "@typescript-eslint/no-throw-literal": ["error"] + "@typescript-eslint/no-throw-literal": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-unused-expressions.md b/packages/eslint-plugin/docs/rules/no-unused-expressions.md index 2e6a002ba51c..162e008796f4 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-expressions.md +++ b/packages/eslint-plugin/docs/rules/no-unused-expressions.md @@ -13,7 +13,7 @@ It adds support for optional call expressions `x?.()`, and directive in module d { // note you must disable the base rule as it can report incorrect errors "no-unused-expressions": "off", - "@typescript-eslint/no-unused-expressions": ["error"] + "@typescript-eslint/no-unused-expressions": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-unused-vars.md b/packages/eslint-plugin/docs/rules/no-unused-vars.md index 4902c1e72592..50319a8b5df8 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-vars.md +++ b/packages/eslint-plugin/docs/rules/no-unused-vars.md @@ -13,7 +13,7 @@ It adds support for TypeScript features, such as types. { // note you must disable the base rule as it can report incorrect errors "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error"] + "@typescript-eslint/no-unused-vars": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-use-before-define.md b/packages/eslint-plugin/docs/rules/no-use-before-define.md index dfc9c354d49d..517586274703 100644 --- a/packages/eslint-plugin/docs/rules/no-use-before-define.md +++ b/packages/eslint-plugin/docs/rules/no-use-before-define.md @@ -13,7 +13,7 @@ It adds support for `type`, `interface` and `enum` declarations. { // note you must disable the base rule as it can report incorrect errors "no-use-before-define": "off", - "@typescript-eslint/no-use-before-define": ["error"] + "@typescript-eslint/no-use-before-define": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/no-useless-constructor.md b/packages/eslint-plugin/docs/rules/no-useless-constructor.md index 8892c1c9e29e..9fc4daa8ec79 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-useless-constructor.md @@ -17,7 +17,7 @@ It adds support for: { // note you must disable the base rule as it can report incorrect errors "no-useless-constructor": "off", - "@typescript-eslint/no-useless-constructor": ["error"] + "@typescript-eslint/no-useless-constructor": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/object-curly-spacing.md b/packages/eslint-plugin/docs/rules/object-curly-spacing.md index 31f878363b19..829c97deb95d 100644 --- a/packages/eslint-plugin/docs/rules/object-curly-spacing.md +++ b/packages/eslint-plugin/docs/rules/object-curly-spacing.md @@ -13,7 +13,7 @@ It adds support for TypeScript's object types. { // note you must disable the base rule as it can report incorrect errors "object-curly-spacing": "off", - "@typescript-eslint/object-curly-spacing": ["error"] + "@typescript-eslint/object-curly-spacing": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/quotes.md b/packages/eslint-plugin/docs/rules/quotes.md index 61cadea2047a..c09215bc24b4 100644 --- a/packages/eslint-plugin/docs/rules/quotes.md +++ b/packages/eslint-plugin/docs/rules/quotes.md @@ -13,7 +13,7 @@ It adds support for TypeScript features which allow quoted names, but not backti { // note you must disable the base rule as it can report incorrect errors "quotes": "off", - "@typescript-eslint/quotes": ["error"] + "@typescript-eslint/quotes": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/semi.md b/packages/eslint-plugin/docs/rules/semi.md index 0c37c9f4baa8..bb268d85dce8 100644 --- a/packages/eslint-plugin/docs/rules/semi.md +++ b/packages/eslint-plugin/docs/rules/semi.md @@ -17,7 +17,7 @@ See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-styl { // note you must disable the base rule as it can report incorrect errors "semi": "off", - "@typescript-eslint/semi": ["error"] + "@typescript-eslint/semi": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/space-before-blocks.md b/packages/eslint-plugin/docs/rules/space-before-blocks.md index bb2ec8e4b890..1896fe2e3ddd 100644 --- a/packages/eslint-plugin/docs/rules/space-before-blocks.md +++ b/packages/eslint-plugin/docs/rules/space-before-blocks.md @@ -39,7 +39,7 @@ In case a more specific options object is passed these blocks will follow `class { // note you must disable the base rule as it can report incorrect errors "space-before-blocks": "off", - "@typescript-eslint/space-before-blocks": ["error"] + "@typescript-eslint/space-before-blocks": "error" } ``` diff --git a/packages/eslint-plugin/docs/rules/space-before-function-paren.md b/packages/eslint-plugin/docs/rules/space-before-function-paren.md index 80ab4ffc6a0d..72ba03a822e2 100644 --- a/packages/eslint-plugin/docs/rules/space-before-function-paren.md +++ b/packages/eslint-plugin/docs/rules/space-before-function-paren.md @@ -13,7 +13,7 @@ It adds support for generic type parameters on function calls. { // note you must disable the base rule as it can report incorrect errors "space-before-function-paren": "off", - "@typescript-eslint/space-before-function-paren": ["error"] + "@typescript-eslint/space-before-function-paren": "error" } ``` diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index ff9d48080abe..2618225b5990 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -104,19 +104,18 @@ export default util.createRule({ }, schema: [ { - $definitions: { + definitions: { arrayOption: { enum: ['array', 'generic', 'array-simple'], - tsType: 'ArrayOption', }, }, properties: { default: { - $ref: '#/$definitions/arrayOption', - description: 'The array type expected for mutable cases.', + $ref: '#/definitions/arrayOption', + description: 'The array type expected for mutable cases...', }, readonly: { - $ref: '#/$definitions/arrayOption', + $ref: '#/definitions/arrayOption', description: 'The array type expected for readonly cases. If omitted, the value for `default` will be used.', }, diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 1239f0db0c5e..e8857c21eb45 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -40,7 +40,7 @@ export default util.createRule<[Options], MessageIds>({ }, schema: [ { - $definitions: { + definitions: { directiveConfigSchema: { oneOf: [ { @@ -62,11 +62,11 @@ export default util.createRule<[Options], MessageIds>({ type: 'object', properties: { 'ts-expect-error': { - $ref: '#/$definitions/directiveConfigSchema', + $ref: '#/definitions/directiveConfigSchema', }, - 'ts-ignore': { $ref: '#/$definitions/directiveConfigSchema' }, - 'ts-nocheck': { $ref: '#/$definitions/directiveConfigSchema' }, - 'ts-check': { $ref: '#/$definitions/directiveConfigSchema' }, + 'ts-ignore': { $ref: '#/definitions/directiveConfigSchema' }, + 'ts-nocheck': { $ref: '#/definitions/directiveConfigSchema' }, + 'ts-check': { $ref: '#/definitions/directiveConfigSchema' }, minimumDescriptionLength: { type: 'number', default: defaultMinimumDescriptionLength, diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 16b73f2cf5b2..3f0e150a818c 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -154,7 +154,12 @@ export default util.createRule({ }, ], }, - defaultOptions: [{}], + defaultOptions: [ + { + extendDefaults: true, + types: defaultTypes, + }, + ], create(context, [options]) { const extendDefaults = options.extendDefaults ?? true; const customTypes = options.types ?? {}; diff --git a/packages/utils/src/eslint-utils/applyDefault.ts b/packages/utils/src/eslint-utils/applyDefault.ts index b0dbdfeb461c..85cd3b3653be 100644 --- a/packages/utils/src/eslint-utils/applyDefault.ts +++ b/packages/utils/src/eslint-utils/applyDefault.ts @@ -22,7 +22,6 @@ function applyDefault( // For avoiding the type error // `This expression is not callable. Type 'unknown' has no call signatures.ts(2349)` - // @ts-ignore (options as unknown[]).forEach((opt: unknown, i: number) => { if (userOptions[i] !== undefined) { const userOpt = userOptions[i]; diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index d588bb83cd3e..9e2f0adbf694 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -8,7 +8,7 @@ import * as tseslintParser from '@typescript-eslint/parser'; import * as eslintPlugin from '@typescript-eslint/eslint-plugin'; import { EOL } from 'os'; -const generatedRuleDocs: Plugin = () => { +export const generatedRuleDocs: Plugin = () => { return async (root, file) => { if (file.stem == null) { return; @@ -62,68 +62,84 @@ const generatedRuleDocs: Plugin = () => { // 4. Add a description of how to use / options for the rule const optionLevel = meta.docs.recommended === 'error' ? 'error' : 'warn'; + let optionsH2Index = parent.children.findIndex( + createH2TextFilter('Options'), + ); if (meta.docs.extendsBaseRule) { - const howToUseH2Index = parent.children.findIndex( + let howToUseH2Index = parent.children.findIndex( createH2TextFilter('How to Use'), ); - parent.children.splice( - howToUseH2Index + 1, - 0, - { - lang: 'jsonc', - type: 'code', - meta: 'title=".eslintrc.cjs"', - value: `module.exports = { - // note you must disable the base rule as it can report incorrect errors - "${file.stem}": "off", - "@typescript-eslint/${file.stem}": "${optionLevel}" -};`, - } as mdast.Code, - { + if (howToUseH2Index === -1) { + parent.children.splice(optionsH2Index, 0, { children: [ { type: 'text', - value: 'Options', + value: 'How to Use', }, ], depth: 2, type: 'heading', - } as mdast.Heading, - { + } as mdast.Heading); + howToUseH2Index = optionsH2Index; + optionsH2Index += 1; + } + + parent.children.splice(howToUseH2Index + 1, 0, { + lang: 'jsonc', + type: 'code', + meta: 'title=".eslintrc.cjs"', + value: `module.exports = { + // note you must disable the base rule as it can report incorrect errors + "${file.stem}": "off", + "@typescript-eslint/${file.stem}": "${optionLevel}" +};`, + } as mdast.Code); + + const optionsParagraph = { + children: [ + { + value: 'See ', + type: 'text', + }, + { + children: [ + { + type: 'inlineCode', + value: `eslint/${file.stem}`, + }, + { + type: 'text', + value: ' options', + }, + ], + type: 'link', + url: `https://eslint.org/docs/rules/${file.stem}#options`, + }, + { + type: 'text', + value: '.', + }, + ], + type: 'paragraph', + } as mdast.Paragraph; + + if (optionsH2Index === -1) { + parent.children.splice(howToUseH2Index + 2, 0, { children: [ { - value: 'See ', type: 'text', - }, - { - children: [ - { - type: 'inlineCode', - value: `eslint/${file.stem}`, - }, - { - type: 'text', - value: ' options', - }, - ], - type: 'link', - url: `https://eslint.org/docs/rules/${file.stem}#options`, - }, - { - type: 'text', - value: '.', + value: 'Options', }, ], - type: 'paragraph', - } as mdast.Paragraph, - // todo: add more? - ); + depth: 2, + type: 'heading', + optionsParagraph, + } as mdast.Heading); + } else { + parent.children.splice(optionsH2Index + 2, 0, optionsParagraph); + } } else { - let optionsH2Index = parent.children.findIndex( - createH2TextFilter('Options'), - ); - if (optionsH2Index === -1) { const whenNotToUseItH2Index = parent.children.findIndex( createH2TextFilter('When Not To Use It'), @@ -203,7 +219,7 @@ const generatedRuleDocs: Plugin = () => { declareExternallyReferenced: true, }, ) - ).replace(/^export /g, ''), + ).replace(/^export /gm, ''), format( `const defaultOptions: Options = ${JSON.stringify( rule.defaultOptions, @@ -228,9 +244,6 @@ const generatedRuleDocs: Plugin = () => { 'Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md)', } as unist.Node); } - - // TODO: find & use library that converts text to markdown ast - // (that'll fix the not applying issue) }; }; @@ -248,5 +261,3 @@ function createH2TextFilter( node.children[0].type === 'text' && node.children[0].value === text; } - -export { generatedRuleDocs }; From 005f0c65acea34763e618a0bd4cb211950dfa017 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 15:02:55 -0400 Subject: [PATCH 07/26] Through explicit-module-boundary-types --- .../rules/explicit-function-return-type.md | 32 --------------- .../rules/explicit-member-accessibility.md | 23 ----------- .../rules/explicit-module-boundary-types.md | 40 ------------------- .../rules/explicit-function-return-type.ts | 22 +++++++--- .../rules/explicit-member-accessibility.ts | 32 +++++++++++---- .../rules/explicit-module-boundary-types.ts | 16 +++++++- 6 files changed, 57 insertions(+), 108 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index b6513db65b72..00389fc3f48b 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -61,38 +61,6 @@ class Test { } ``` -## Options - -The rule accepts an options object with the following properties: - -```ts -type Options = { - // if true, only functions which are part of a declaration will be checked - allowExpressions?: boolean; - // if true, type annotations are also allowed on the variable of a function expression rather than on the function directly - allowTypedFunctionExpressions?: boolean; - // if true, functions immediately returning another function expression will not be checked - allowHigherOrderFunctions?: boolean; - // if true, arrow functions immediately returning a `as const` value will not be checked - allowDirectConstAssertionInArrowFunctions?: boolean; - // if true, concise arrow functions that start with the void keyword will not be checked - allowConciseArrowFunctionExpressionsStartingWithVoid?: boolean; - /** - * An array of function/method names that will not have their arguments or their return values checked. - */ - allowedNames?: string[]; -}; - -const defaults = { - allowExpressions: false, - allowTypedFunctionExpressions: true, - allowHigherOrderFunctions: true, - allowDirectConstAssertionInArrowFunctions: true, - allowConciseArrowFunctionExpressionsStartingWithVoid: false, - allowedNames: [], -}; -``` - ### Configuring in a mixed JS/TS codebase If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. diff --git a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md index c321bf76c328..791515fb971e 100644 --- a/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md +++ b/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md @@ -14,29 +14,6 @@ which properties. ## Options -```ts -type AccessibilityLevel = - | 'explicit' // require an accessor (including public) - | 'no-public' // don't require public - | 'off'; // don't check - -type Options = { - accessibility?: AccessibilityLevel; - ignoredMethodNames?: string[]; - overrides?: { - accessors?: AccessibilityLevel; - constructors?: AccessibilityLevel; - methods?: AccessibilityLevel; - properties?: AccessibilityLevel; - parameterProperties?: AccessibilityLevel; - }; -}; - -const defaultOptions: Options = { - accessibility: 'explicit', -}; -``` - ### Configuring in a mixed JS/TS codebase If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. diff --git a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md index eba5310c0482..556b6a3d3205 100644 --- a/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md +++ b/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md @@ -68,46 +68,6 @@ class Test { ## Options -The rule accepts an options object with the following properties: - -```ts -type Options = { - /** - * If true, the rule will not report for arguments that are explicitly typed as `any` - */ - allowArgumentsExplicitlyTypedAsAny?: boolean; - /** - * If true, body-less arrow functions that return an `as const` type assertion will not - * require an explicit return value annotation. - * You must still type the parameters of the function. - */ - allowDirectConstAssertionInArrowFunctions?: boolean; - /** - * An array of function/method names that will not have their arguments or their return values checked. - */ - allowedNames?: string[]; - /** - * If true, functions immediately returning another function expression will not - * require an explicit return value annotation. - * You must still type the parameters of the function. - */ - allowHigherOrderFunctions?: boolean; - /** - * If true, type annotations are also allowed on the variable of a function expression - * rather than on the function arguments/return value directly. - */ - allowTypedFunctionExpressions?: boolean; -}; - -const defaults = { - allowArgumentsExplicitlyTypedAsAny: false, - allowDirectConstAssertionInArrowFunctions: true, - allowedNames: [], - allowHigherOrderFunctions: true, - allowTypedFunctionExpressions: true, -}; -``` - ### Configuring in a mixed JS/TS codebase If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files. diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index 1f69834d4784..9e5a377ee5fc 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -34,26 +34,38 @@ export default util.createRule({ { type: 'object', properties: { - allowExpressions: { + allowConciseArrowFunctionExpressionsStartingWithVoid: { + description: + 'Whether to allow arrow functions that start with the `void` keyword.', type: 'boolean', }, - allowTypedFunctionExpressions: { + allowExpressions: { + description: + 'Whether to ignore function expressions (functions which are not part of a declaration).', type: 'boolean', }, allowHigherOrderFunctions: { + description: + 'Whether to ignore functions immediately returning another function expression.', type: 'boolean', }, - allowDirectConstAssertionInArrowFunctions: { + allowTypedFunctionExpressions: { + description: + 'Whether to ignore type annotations on the variable of function expressions.', type: 'boolean', }, - allowConciseArrowFunctionExpressionsStartingWithVoid: { + allowDirectConstAssertionInArrowFunctions: { + description: + 'Whether to ignore arrow functions immediately returning a `as const` value.', type: 'boolean', }, allowedNames: { - type: 'array', + description: + 'An array of function/method names that will not have their arguments or return values checked.', items: { type: 'string', }, + type: 'array', }, }, additionalProperties: false, diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index b67221aee54f..40ad832b1322 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -27,7 +27,22 @@ type Options = [Config]; type MessageIds = 'unwantedPublicAccessibility' | 'missingAccessibility'; -const accessibilityLevel = { enum: ['explicit', 'no-public', 'off'] }; +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', @@ -48,17 +63,20 @@ export default util.createRule({ }, schema: [ { + definitions: { + accessibilityLevel, + }, type: 'object', properties: { - accessibility: accessibilityLevel, + accessibility: { $ref: '#/definitions/accessibilityLevel' }, overrides: { type: 'object', properties: { - accessors: accessibilityLevel, - constructors: accessibilityLevel, - methods: accessibilityLevel, - properties: accessibilityLevel, - parameterProperties: accessibilityLevel, + accessors: { $ref: '#/definitions/accessibilityLevel' }, + constructors: { $ref: '#/definitions/accessibilityLevel' }, + methods: { $ref: '#/definitions/accessibilityLevel' }, + properties: { $ref: '#/definitions/accessibilityLevel' }, + parameterProperties: { $ref: '#/definitions/accessibilityLevel' }, }, additionalProperties: false, diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index 3f9f50086ccf..a3c414203544 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -50,21 +50,35 @@ export default util.createRule({ type: 'object', 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.', + 'You must still type the parameters of the function.', + ].join('\n'), type: 'boolean', }, allowedNames: { - type: 'array', + 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.', + 'You must still type the parameters of the function.', + ].join('\n'), type: 'boolean', }, allowTypedFunctionExpressions: { + description: + 'Whether to ignore type annotations on the variable of a function expresion.', type: 'boolean', }, // DEPRECATED - To be removed in next major From 6cb1909d77aca72e650ff9a07bc8fcbf02bc205b Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 16:50:10 -0400 Subject: [PATCH 08/26] rip, ban-types defaults --- .../eslint-plugin/docs/rules/ban-types.md | 53 +++++++++++++++++++ packages/eslint-plugin/src/rules/ban-types.ts | 7 +-- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index 807cfeeab43e..0b4d244c50d5 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -74,6 +74,59 @@ The default options suggest using `Record`; this was a stylisti ::: +
+Default Options + +```ts +const defaultTypes = { + String: { + message: 'Use string instead', + fixWith: 'string', + }, + Boolean: { + message: 'Use boolean instead', + fixWith: 'boolean', + }, + Number: { + message: 'Use number instead', + fixWith: 'number', + }, + Symbol: { + message: 'Use symbol instead', + fixWith: 'symbol', + }, + BigInt: { + message: 'Use bigint instead', + fixWith: 'bigint', + }, + Function: { + message: [ + 'The `Function` type accepts any function-like value.', + 'It provides no type safety when calling the function, which can be a common source of bugs.', + 'It also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.', + 'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.', + ].join('\n'), + }, + // object typing + Object: { + message: [ + 'The `Object` type actually means "any non-nullish value", so it is marginally better than `unknown`.', + '- If you want a type meaning "any object", you probably want `Record` instead.', + '- If you want a type meaning "any value", you probably want `unknown` instead.', + ].join('\n'), + }, + '{}': { + message: [ + '`{}` actually means "any non-nullish value".', + '- If you want a type meaning "any object", you probably want `Record` instead.', + '- If you want a type meaning "any value", you probably want `unknown` instead.', + ].join('\n'), + }, +}; +``` + +
+ ### `types` An object whose keys are the types you want to ban, and the values are error messages. diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 3f0e150a818c..16b73f2cf5b2 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -154,12 +154,7 @@ export default util.createRule({ }, ], }, - defaultOptions: [ - { - extendDefaults: true, - types: defaultTypes, - }, - ], + defaultOptions: [{}], create(context, [options]) { const extendDefaults = options.extendDefaults ?? true; const customTypes = options.types ?? {}; From 8f160f4cc5f2f0edad98a8f2a06708552d92bb40 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 17:28:07 -0400 Subject: [PATCH 09/26] Cleaner separation for adding headers --- .../eslint-plugin/docs/rules/brace-style.md | 10 -- .../docs/rules/func-call-spacing.md | 20 --- packages/eslint-plugin/docs/rules/indent.md | 26 +--- .../website/plugins/generated-rule-docs.ts | 117 +++++++++--------- 4 files changed, 61 insertions(+), 112 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/brace-style.md b/packages/eslint-plugin/docs/rules/brace-style.md index 6515a39f40a6..03456ed8837f 100644 --- a/packages/eslint-plugin/docs/rules/brace-style.md +++ b/packages/eslint-plugin/docs/rules/brace-style.md @@ -6,13 +6,3 @@ This rule extends the base [`eslint/brace-style`](https://eslint.org/docs/rules/brace-style) rule. It adds support for `enum`, `interface`, `namespace` and `module` declarations. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "brace-style": "off", - "@typescript-eslint/brace-style": "error" -} -``` diff --git a/packages/eslint-plugin/docs/rules/func-call-spacing.md b/packages/eslint-plugin/docs/rules/func-call-spacing.md index a304bb5a0573..bda7b6a39b99 100644 --- a/packages/eslint-plugin/docs/rules/func-call-spacing.md +++ b/packages/eslint-plugin/docs/rules/func-call-spacing.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing) rule. It adds support for generic type parameters on function calls. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "func-call-spacing": "off", - "@typescript-eslint/func-call-spacing": "error" -} -``` - -## Options - -See [`eslint/func-call-spacing` options](https://eslint.org/docs/rules/func-call-spacing#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/func-call-spacing.md) - - diff --git a/packages/eslint-plugin/docs/rules/indent.md b/packages/eslint-plugin/docs/rules/indent.md index 3f8810e7ba21..c55ff60cdb6c 100644 --- a/packages/eslint-plugin/docs/rules/indent.md +++ b/packages/eslint-plugin/docs/rules/indent.md @@ -4,29 +4,13 @@ ## Warning -PLEASE READ THIS ISSUE BEFORE USING THIS RULE [#1824](https://github.com/typescript-eslint/typescript-eslint/issues/1824) +:::warning + +Please read [Issue #1824: Problems with the indent rule](https://github.com/typescript-eslint/typescript-eslint/issues/1824) before using this rule! + +::: ## Rule Details This rule extends the base [`eslint/indent`](https://eslint.org/docs/rules/indent) rule. It adds support for TypeScript nodes. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "indent": "off", - "@typescript-eslint/indent": "error" -} -``` - -## Options - -See [`eslint/indent` options](https://eslint.org/docs/rules/indent#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/indent.md) - - diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 9e2f0adbf694..c88da29f6277 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/explicit-function-return-type */ import type * as unist from 'unist'; import * as mdast from 'mdast'; import { format } from 'prettier'; @@ -60,43 +61,63 @@ export const generatedRuleDocs: Plugin = () => { }; parent.children.splice(attributesH2Index, 0, attributesNode); - // 4. Add a description of how to use / options for the rule - const optionLevel = meta.docs.recommended === 'error' ? 'error' : 'warn'; - let optionsH2Index = parent.children.findIndex( - createH2TextFilter('Options'), - ); - if (meta.docs.extendsBaseRule) { + // 4. Make sure the appropriate headers exist to place content under + const { howToUseH2Index, optionsH2Index } = (() => { let howToUseH2Index = parent.children.findIndex( createH2TextFilter('How to Use'), ); + let optionsH2Index = parent.children.findIndex( + createH2TextFilter('Options'), + ); + + let whenNotToUseItH2Index = parent.children.findIndex( + createH2TextFilter('When Not To Use It'), + ); + + if (meta.docs.extendsBaseRule) { + if (howToUseH2Index === -1) { + howToUseH2Index = + whenNotToUseItH2Index === -1 + ? parent.children.length + : ++whenNotToUseItH2Index; + parent.children.splice(howToUseH2Index, 0, { + children: [ + { + type: 'text', + value: 'How to Use', + }, + ], + depth: 2, + type: 'heading', + } as mdast.Heading); + } + } - if (howToUseH2Index === -1) { + if (optionsH2Index === -1) { + optionsH2Index = + whenNotToUseItH2Index === -1 + ? parent.children.length + : ++whenNotToUseItH2Index; parent.children.splice(optionsH2Index, 0, { children: [ { type: 'text', - value: 'How to Use', + value: 'Options', }, ], depth: 2, type: 'heading', } as mdast.Heading); - howToUseH2Index = optionsH2Index; - optionsH2Index += 1; } - parent.children.splice(howToUseH2Index + 1, 0, { - lang: 'jsonc', - type: 'code', - meta: 'title=".eslintrc.cjs"', - value: `module.exports = { - // note you must disable the base rule as it can report incorrect errors - "${file.stem}": "off", - "@typescript-eslint/${file.stem}": "${optionLevel}" -};`, - } as mdast.Code); + return { howToUseH2Index, optionsH2Index }; + })(); - const optionsParagraph = { + // 5. Add a description of how to use / options for the rule + const optionLevel = meta.docs.recommended === 'error' ? 'error' : 'warn'; + + if (meta.docs.extendsBaseRule) { + parent.children.splice(optionsH2Index + 1, 0, { children: [ { value: 'See ', @@ -122,46 +143,20 @@ export const generatedRuleDocs: Plugin = () => { }, ], type: 'paragraph', - } as mdast.Paragraph; + } as mdast.Paragraph); - if (optionsH2Index === -1) { - parent.children.splice(howToUseH2Index + 2, 0, { - children: [ - { - type: 'text', - value: 'Options', - }, - ], - depth: 2, - type: 'heading', - optionsParagraph, - } as mdast.Heading); - } else { - parent.children.splice(optionsH2Index + 2, 0, optionsParagraph); - } + parent.children.splice(howToUseH2Index + 1, 0, { + lang: 'jsonc', + type: 'code', + meta: 'title=".eslintrc.cjs"', + value: `module.exports = { + // note you must disable the base rule as it can report incorrect errors + "${file.stem}": "off", + "@typescript-eslint/${file.stem}": "${optionLevel}" +};`, + } as mdast.Code); } else { - if (optionsH2Index === -1) { - const whenNotToUseItH2Index = parent.children.findIndex( - createH2TextFilter('When Not To Use It'), - ); - optionsH2Index = - whenNotToUseItH2Index === -1 - ? parent.children.length - 1 - : whenNotToUseItH2Index; - - parent.children.splice(optionsH2Index, 0, { - children: [ - { - type: 'text', - value: 'Options', - }, - ], - depth: 2, - type: 'heading', - } as mdast.Heading); - } - - parent.children.splice(optionsH2Index + 1, 0, { + parent.children.splice(optionsH2Index, 0, { lang: 'jsonc', type: 'code', meta: 'title=".eslintrc.cjs"', @@ -173,7 +168,7 @@ export const generatedRuleDocs: Plugin = () => { } as mdast.Code); if (meta.schema.length === 0) { - parent.children.splice(optionsH2Index + 2, 0, { + parent.children.splice(optionsH2Index + 1, 0, { children: [ { type: 'text', @@ -236,7 +231,7 @@ export const generatedRuleDocs: Plugin = () => { } } - // 5. Add a notice about coming from ESLint core for extension rules + // 6. Add a notice about coming from ESLint core for extension rules if (meta.docs.extendsBaseRule) { parent.children.push({ type: 'jsx', From 20f277c69e13060cdcae0c1b45c3b10f02664618 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 17:28:20 -0400 Subject: [PATCH 10/26] ...I meant headings From 6e49529c356b51a560bd9940191b8518ca0b43f7 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 29 Jul 2022 19:27:18 -0400 Subject: [PATCH 11/26] Finished specifically base rule extensions --- .../eslint-plugin/docs/rules/dot-notation.md | 6 --- .../docs/rules/init-declarations.md | 20 -------- .../docs/rules/keyword-spacing.md | 20 -------- .../docs/rules/lines-between-class-members.md | 24 +--------- .../docs/rules/no-array-constructor.md | 20 -------- .../docs/rules/no-dupe-class-members.md | 20 -------- .../docs/rules/no-duplicate-imports.md | 25 ---------- .../docs/rules/no-empty-function.md | 27 ----------- .../docs/rules/no-extra-parens.md | 20 -------- .../eslint-plugin/docs/rules/no-extra-semi.md | 20 -------- .../docs/rules/no-implied-eval.md | 16 ------- .../docs/rules/no-invalid-this.md | 24 ---------- .../eslint-plugin/docs/rules/no-loop-func.md | 20 -------- .../docs/rules/no-loss-of-precision.md | 17 ------- .../docs/rules/no-magic-numbers.md | 22 --------- .../eslint-plugin/docs/rules/no-redeclare.md | 17 ------- .../docs/rules/no-restricted-imports.md | 11 ----- .../eslint-plugin/docs/rules/no-shadow.md | 17 ------- .../docs/rules/no-throw-literal.md | 46 ++++++++----------- .../docs/rules/no-unused-expressions.md | 20 -------- .../docs/rules/no-unused-vars.md | 20 -------- .../docs/rules/no-use-before-define.md | 21 --------- .../docs/rules/no-useless-constructor.md | 22 +-------- .../docs/rules/object-curly-spacing.md | 20 -------- .../rules/padding-line-between-statements.md | 33 ++----------- packages/eslint-plugin/docs/rules/quotes.md | 20 -------- .../eslint-plugin/docs/rules/return-await.md | 10 ---- packages/eslint-plugin/docs/rules/semi.md | 20 -------- .../docs/rules/space-before-blocks.md | 24 ++-------- .../docs/rules/space-before-function-paren.md | 20 -------- .../docs/rules/space-infix-ops.md | 22 +-------- .../website/plugins/generated-rule-docs.ts | 20 ++++++-- 32 files changed, 46 insertions(+), 618 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/dot-notation.md b/packages/eslint-plugin/docs/rules/dot-notation.md index 7cb86db23914..f1fea931f0a1 100644 --- a/packages/eslint-plugin/docs/rules/dot-notation.md +++ b/packages/eslint-plugin/docs/rules/dot-notation.md @@ -71,9 +71,3 @@ x['hello'] = 123; ``` If the TypeScript compiler option `noPropertyAccessFromIndexSignature` is set to `true`, then the above code is always allowed, even if `allowIndexSignaturePropertyAccess` is `false`. - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/dot-notation.md) - - diff --git a/packages/eslint-plugin/docs/rules/init-declarations.md b/packages/eslint-plugin/docs/rules/init-declarations.md index 7d090540c24d..6e9ec6c388df 100644 --- a/packages/eslint-plugin/docs/rules/init-declarations.md +++ b/packages/eslint-plugin/docs/rules/init-declarations.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/init-declarations`](https://eslint.org/docs/rules/init-declarations) rule. It adds support for TypeScript's `declare` variables. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "init-declarations": "off", - "@typescript-eslint/init-declarations": "error" -} -``` - -## Options - -See [`eslint/init-declarations` options](https://eslint.org/docs/rules/init-declarations#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/init-declarations.md) - - diff --git a/packages/eslint-plugin/docs/rules/keyword-spacing.md b/packages/eslint-plugin/docs/rules/keyword-spacing.md index bce66e27dd7b..2c28da368aa8 100644 --- a/packages/eslint-plugin/docs/rules/keyword-spacing.md +++ b/packages/eslint-plugin/docs/rules/keyword-spacing.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing) rule. This version adds support for generic type parameters on function calls. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "keyword-spacing": "off", - "@typescript-eslint/keyword-spacing": "error" -} -``` - -## Options - -See [`eslint/keyword-spacing` options](https://eslint.org/docs/rules/keyword-spacing#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/keyword-spacing.md) - - diff --git a/packages/eslint-plugin/docs/rules/lines-between-class-members.md b/packages/eslint-plugin/docs/rules/lines-between-class-members.md index fa77cebfc2dc..102157a6b704 100644 --- a/packages/eslint-plugin/docs/rules/lines-between-class-members.md +++ b/packages/eslint-plugin/docs/rules/lines-between-class-members.md @@ -2,30 +2,16 @@ > > See **https://typescript-eslint.io/rules/lines-between-class-members** for documentation. -This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member. This rule require or disallow an empty line between class members. +This rule improves readability by enforcing lines between class members. It will not check empty lines before the first member and after the last member. This rule will require or disallow an empty line between class members. ## Rule Details This rule extends the base [`eslint/lines-between-class-members`](https://eslint.org/docs/rules/lines-between-class-members) rule. It adds support for ignoring overload methods in a class. -See the [ESLint documentation](https://eslint.org/docs/rules/lines-between-class-members) for more details on the `lines-between-class-members` rule. - -## Rule Changes - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "lines-between-class-members": "off", - "@typescript-eslint/lines-between-class-members": "error" -} -``` - -In addition to the options supported by the `lines-between-class-members` rule in ESLint core, the rule adds the following options: - ## Options -This rule has a string option and an object option. +In addition to the options supported by the `lines-between-class-members` rule in ESLint core, the rule adds the following options: - Object option: @@ -71,9 +57,3 @@ class foo { qux() {} } ``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/lines-between-class-members.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-array-constructor.md b/packages/eslint-plugin/docs/rules/no-array-constructor.md index 09ac6c5f1979..f7ee74d68cb3 100644 --- a/packages/eslint-plugin/docs/rules/no-array-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-array-constructor.md @@ -29,23 +29,3 @@ new Array(x, y, z); Array(500); new Array(someOtherArray.length); ``` - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-array-constructor": "off", - "@typescript-eslint/no-array-constructor": "error" -} -``` - -## Options - -See [`eslint/no-array-constructor` options](https://eslint.org/docs/rules/no-array-constructor#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-array-constructor.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md index 07346ccb3152..eb8f222c12af 100644 --- a/packages/eslint-plugin/docs/rules/no-dupe-class-members.md +++ b/packages/eslint-plugin/docs/rules/no-dupe-class-members.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-dupe-class-members`](https://eslint.org/docs/rules/no-dupe-class-members) rule. It adds support for TypeScript's method overload definitions. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-dupe-class-members": "off", - "@typescript-eslint/no-dupe-class-members": "error" -} -``` - -## Options - -See [`eslint/no-dupe-class-members` options](https://eslint.org/docs/rules/no-dupe-class-members#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-dupe-class-members.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md index 0ee781203cfc..66dff212a733 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-imports.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-imports.md @@ -5,28 +5,3 @@ ## DEPRECATED This rule has been deprecated in favour of the [`import/no-duplicates`](https://github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md) rule. - -## Rule Details - -This rule extends the base [`eslint/no-duplicate-imports`](https://eslint.org/docs/rules/no-duplicate-imports) rule. -This version adds support for type-only import and export. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-duplicate-imports": "off", - "@typescript-eslint/no-duplicate-imports": "error" -} -``` - -## Options - -See [`eslint/no-duplicate-imports` options](https://eslint.org/docs/rules/no-duplicate-imports#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-duplicate-imports.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-empty-function.md b/packages/eslint-plugin/docs/rules/no-empty-function.md index 40004a958e86..8e12a5932ff5 100644 --- a/packages/eslint-plugin/docs/rules/no-empty-function.md +++ b/packages/eslint-plugin/docs/rules/no-empty-function.md @@ -9,19 +9,8 @@ It adds support for handling TypeScript specific code that would otherwise trigg One example of valid TypeScript specific code that would otherwise trigger the `no-empty-function` rule is the use of [parameter properties](https://www.typescriptlang.org/docs/handbook/classes.html#parameter-properties) in constructor functions. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-empty-function": "off", - "@typescript-eslint/no-empty-function": "error" -} -``` - ## Options -See [`eslint/no-empty-function` options](https://eslint.org/docs/rules/no-empty-function#options). This rule adds the following options: ```ts @@ -93,19 +82,3 @@ class Foo extends Base { protected override greet(): void {} } ``` - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-empty-function": "off", - "@typescript-eslint/no-empty-function": "error" -} -``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-empty-function.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-extra-parens.md b/packages/eslint-plugin/docs/rules/no-extra-parens.md index b8d6df0d34ab..4b12845a3d0f 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-parens.md +++ b/packages/eslint-plugin/docs/rules/no-extra-parens.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-extra-parens`](https://eslint.org/docs/rules/no-extra-parens) rule. It adds support for TypeScript type assertions. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-extra-parens": "off", - "@typescript-eslint/no-extra-parens": "error" -} -``` - -## Options - -See [`eslint/no-extra-parens` options](https://eslint.org/docs/rules/no-extra-parens#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-extra-parens.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-extra-semi.md b/packages/eslint-plugin/docs/rules/no-extra-semi.md index e2bbf065ff14..cf0b8b11e708 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-semi.md +++ b/packages/eslint-plugin/docs/rules/no-extra-semi.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-extra-semi`](https://eslint.org/docs/rules/no-extra-semi) rule. It adds support for class properties. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-extra-semi": "off", - "@typescript-eslint/no-extra-semi": "error" -} -``` - -## Options - -See [`eslint/no-extra-semi` options](https://eslint.org/docs/rules/no-extra-semi#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-extra-semi.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-implied-eval.md b/packages/eslint-plugin/docs/rules/no-implied-eval.md index 144d958bb5c7..349e57e37b6c 100644 --- a/packages/eslint-plugin/docs/rules/no-implied-eval.md +++ b/packages/eslint-plugin/docs/rules/no-implied-eval.md @@ -94,22 +94,6 @@ class Foo { setTimeout(Foo.fn, 100); ``` -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-implied-eval": "off", - "@typescript-eslint/no-implied-eval": "error" -} -``` - ## When Not To Use It If you want to allow `new Function()` or `setTimeout()`, `setInterval()`, `setImmediate()` and `execScript()` with string arguments, then you can safely disable this rule. - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-implied-eval.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-invalid-this.md b/packages/eslint-plugin/docs/rules/no-invalid-this.md index 92480b8be043..8bc5ead0fb99 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-this.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-this.md @@ -6,27 +6,3 @@ This rule extends the base [`eslint/no-invalid-this`](https://eslint.org/docs/rules/no-invalid-this) rule. It adds support for TypeScript's `this` parameters. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-invalid-this": "off", - "@typescript-eslint/no-invalid-this": "error" -} -``` - -## Options - -See [`eslint/no-invalid-this` options](https://eslint.org/docs/rules/no-invalid-this#options). - -## When Not To Use It - -When you are indifferent as to how your variables are initialized. - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-invalid-this.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-loop-func.md b/packages/eslint-plugin/docs/rules/no-loop-func.md index 0f984f7e40bb..b3d595c0a581 100644 --- a/packages/eslint-plugin/docs/rules/no-loop-func.md +++ b/packages/eslint-plugin/docs/rules/no-loop-func.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-loop-func`](https://eslint.org/docs/rules/no-loop-func) rule. It adds support for TypeScript types. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-loop-func": "off", - "@typescript-eslint/no-loop-func": "error" -} -``` - -## Options - -See [`eslint/no-loop-func` options](https://eslint.org/docs/rules/no-loop-func#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-loop-func.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md index 3252ad1ed850..1b052207cac6 100644 --- a/packages/eslint-plugin/docs/rules/no-loss-of-precision.md +++ b/packages/eslint-plugin/docs/rules/no-loss-of-precision.md @@ -6,20 +6,3 @@ This rule extends the base [`eslint/no-loss-of-precision`](https://eslint.org/docs/rules/no-loss-of-precision) rule. It adds support for [numeric separators](https://github.com/tc39/proposal-numeric-separator). -Note that this rule requires ESLint v7. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-loss-of-precision": "off", - "@typescript-eslint/no-loss-of-precision": "error" -} -``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-loss-of-precision.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-magic-numbers.md b/packages/eslint-plugin/docs/rules/no-magic-numbers.md index b352b892ffcf..85aece5f0e81 100644 --- a/packages/eslint-plugin/docs/rules/no-magic-numbers.md +++ b/packages/eslint-plugin/docs/rules/no-magic-numbers.md @@ -11,24 +11,8 @@ It adds support for: - `enum` members (`enum Foo { bar = 1 }`), - `readonly` class properties (`class Foo { readonly bar = 1 }`). -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-magic-numbers": "off", - "@typescript-eslint/no-magic-numbers": [ - "error", - { - /* options */ - } - ] -} -``` - ## Options -See [`eslint/no-magic-numbers` options](https://eslint.org/docs/rules/no-magic-numbers#options). This rule adds the following options: ```ts @@ -141,9 +125,3 @@ Examples of **correct** code for the `{ "ignoreTypeIndexes": true }` option: type Foo = Bar[0]; type Baz = Parameters[2]; ``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-magic-numbers.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-redeclare.md b/packages/eslint-plugin/docs/rules/no-redeclare.md index 9b10f6e2a264..98608eae80b8 100644 --- a/packages/eslint-plugin/docs/rules/no-redeclare.md +++ b/packages/eslint-plugin/docs/rules/no-redeclare.md @@ -7,19 +7,8 @@ This rule extends the base [`eslint/no-redeclare`](https://eslint.org/docs/rules/no-redeclare) rule. It adds support for TypeScript function overloads, and declaration merging. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-redeclare": "off", - "@typescript-eslint/no-redeclare": "error" -} -``` - ## Options -See [`eslint/no-redeclare` options](https://eslint.org/docs/rules/no-redeclare#options). This rule adds the following options: ```ts @@ -78,9 +67,3 @@ type something = string; // eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type const something = 2; ``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-redeclare.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-restricted-imports.md b/packages/eslint-plugin/docs/rules/no-restricted-imports.md index a2a7d8d7ab6b..3e7fcd11260f 100644 --- a/packages/eslint-plugin/docs/rules/no-restricted-imports.md +++ b/packages/eslint-plugin/docs/rules/no-restricted-imports.md @@ -6,19 +6,8 @@ This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-restricted-imports": "off", - "@typescript-eslint/no-restricted-imports": "error" -} -``` - ## Options -See [`eslint/no-restricted-imports` options](https://eslint.org/docs/rules/no-restricted-imports#options). This rule adds the following options: ### `allowTypeImports` diff --git a/packages/eslint-plugin/docs/rules/no-shadow.md b/packages/eslint-plugin/docs/rules/no-shadow.md index 09aecfd0f4f9..359345e24efc 100644 --- a/packages/eslint-plugin/docs/rules/no-shadow.md +++ b/packages/eslint-plugin/docs/rules/no-shadow.md @@ -7,19 +7,8 @@ This rule extends the base [`eslint/no-shadow`](https://eslint.org/docs/rules/no-shadow) rule. It adds support for TypeScript's `this` parameters and global augmentation, and adds options for TypeScript features. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-shadow": "off", - "@typescript-eslint/no-shadow": "error" -} -``` - ## Options -See [`eslint/no-shadow` options](https://eslint.org/docs/rules/no-shadow#options). This rule adds the following options: ```ts @@ -85,9 +74,3 @@ Examples of **correct** code with `{ ignoreFunctionTypeParameterNameValueShadow: const test = 1; type Func = (test: string) => typeof test; ``` - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-shadow.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-throw-literal.md b/packages/eslint-plugin/docs/rules/no-throw-literal.md index c8b208691b4c..a5af7e961c38 100644 --- a/packages/eslint-plugin/docs/rules/no-throw-literal.md +++ b/packages/eslint-plugin/docs/rules/no-throw-literal.md @@ -85,34 +85,26 @@ class CustomError extends Error { throw new CustomError(); ``` -## How to Use +## Options -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-throw-literal": "off", - "@typescript-eslint/no-throw-literal": "error" -} -``` +This rule adds the following options: -### Options - -```jsonc -{ - "@typescript-eslint/no-throw-literal": [ - "error", - { - "allowThrowingAny": true, // Default is to allow throwing values of type any - "allowThrowingUnknown": true // Default is to allow throwing values of type unknown - } - ] +```ts +interface Options extends BaseNoShadowOptions { + /** + * Whether to always allow throwing values typed as `any`. + */ + allowThrowingAny?: boolean; + + /** + * Whether to always allow throwing values typed as `unknown`. + */ + allowThrowingUnknown?: boolean; } -``` - ---- - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-throw-literal.md) - - +const defaultOptions: Options = { + ...baseNoShadowDefaultOptions, + allowThrowingAny: false, + allowThrowingUnknown: false, +}; +``` diff --git a/packages/eslint-plugin/docs/rules/no-unused-expressions.md b/packages/eslint-plugin/docs/rules/no-unused-expressions.md index 162e008796f4..6be24392a9f7 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-expressions.md +++ b/packages/eslint-plugin/docs/rules/no-unused-expressions.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-unused-expressions`](https://eslint.org/docs/rules/no-unused-expressions) rule. It adds support for optional call expressions `x?.()`, and directive in module declarations. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-unused-expressions": "off", - "@typescript-eslint/no-unused-expressions": "error" -} -``` - -## Options - -See [`eslint/no-unused-expressions` options](https://eslint.org/docs/rules/no-unused-expressions#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-unused-expressions.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-unused-vars.md b/packages/eslint-plugin/docs/rules/no-unused-vars.md index 50319a8b5df8..5c7cc29e8b12 100644 --- a/packages/eslint-plugin/docs/rules/no-unused-vars.md +++ b/packages/eslint-plugin/docs/rules/no-unused-vars.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/no-unused-vars`](https://eslint.org/docs/rules/no-unused-vars) rule. It adds support for TypeScript features, such as types. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": "error" -} -``` - -## Options - -See [`eslint/no-unused-vars` options](https://eslint.org/docs/rules/no-unused-vars#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-unused-vars.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-use-before-define.md b/packages/eslint-plugin/docs/rules/no-use-before-define.md index 517586274703..ca080ffad45e 100644 --- a/packages/eslint-plugin/docs/rules/no-use-before-define.md +++ b/packages/eslint-plugin/docs/rules/no-use-before-define.md @@ -7,19 +7,8 @@ This rule extends the base [`eslint/no-use-before-define`](https://eslint.org/docs/rules/no-use-before-define) rule. It adds support for `type`, `interface` and `enum` declarations. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-use-before-define": "off", - "@typescript-eslint/no-use-before-define": "error" -} -``` - ## Options -See [`eslint/no-use-before-define` options](https://eslint.org/docs/rules/no-use-before-define#options). This rule adds the following options: ```ts @@ -102,13 +91,3 @@ type StringOrNumber = string | number; let var2: Enum; enum Enum {} ``` - -### Other Options - -See [`eslint/no-use-before-define` options](https://eslint.org/docs/rules/no-use-before-define#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-use-before-define.md) - - diff --git a/packages/eslint-plugin/docs/rules/no-useless-constructor.md b/packages/eslint-plugin/docs/rules/no-useless-constructor.md index 9fc4daa8ec79..4abf62d0fa53 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-constructor.md +++ b/packages/eslint-plugin/docs/rules/no-useless-constructor.md @@ -11,27 +11,7 @@ It adds support for: - `public` constructors when there is no superclass, - constructors with only parameter properties. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-useless-constructor": "off", - "@typescript-eslint/no-useless-constructor": "error" -} -``` - -## Options - -See [`eslint/no-useless-constructor` options](https://eslint.org/docs/rules/no-useless-constructor#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/no-useless-constructor.md) - - - -## Caveat +### Caveat This lint rule will report on constructors whose sole purpose is to change visibility of a parent constructor. See [discussion on this rule's lack of type information](https://github.com/typescript-eslint/typescript-eslint/issues/3820#issuecomment-917821240) for context. diff --git a/packages/eslint-plugin/docs/rules/object-curly-spacing.md b/packages/eslint-plugin/docs/rules/object-curly-spacing.md index 829c97deb95d..472b017d4ebf 100644 --- a/packages/eslint-plugin/docs/rules/object-curly-spacing.md +++ b/packages/eslint-plugin/docs/rules/object-curly-spacing.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing) rule. It adds support for TypeScript's object types. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "object-curly-spacing": "off", - "@typescript-eslint/object-curly-spacing": "error" -} -``` - -## Options - -See [`eslint/object-curly-spacing` options](https://eslint.org/docs/rules/object-curly-spacing#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/object-curly-spacing.md) - - diff --git a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md index 69951c378524..5e1920a905a0 100644 --- a/packages/eslint-plugin/docs/rules/padding-line-between-statements.md +++ b/packages/eslint-plugin/docs/rules/padding-line-between-statements.md @@ -5,30 +5,17 @@ ## Rule Details This rule extends the base [`eslint/padding-line-between-statements`](https://eslint.org/docs/rules/padding-line-between-statements) rule. +It adds support for TypeScript constructs such as `interface` and `type`. -**It adds support for TypeScript constructs such as `interface` and `type`.** +## Options -## How to Use +In addition to options provided by ESLint, `interface` and `type` can be used as statement types. -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "padding-line-between-statements": "off", - "@typescript-eslint/padding-line-between-statements": [ - "error", - { - "blankLine": "always", - "prev": "var", - "next": "return" - } - ] -} -``` +For example, to add blank lines before interfaces and type definitions: ```jsonc { // Example - Add blank lines before interface and type definitions. - // note you must disable the base rule as it can report incorrect errors "padding-line-between-statements": "off", "@typescript-eslint/padding-line-between-statements": [ "error", @@ -41,16 +28,4 @@ This rule extends the base [`eslint/padding-line-between-statements`](https://es } ``` -## Options - -See [`eslint/padding-line-between-statements` options](https://eslint.org/docs/rules/padding-line-between-statements#options). - -In addition to options provided by ESLint, `interface` and `type` can be used as statement types. - **Note:** ESLint `cjs-export` and `cjs-import` statement types are renamed to `exports` and `require` respectively. - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/padding-line-between-statements.md) - - diff --git a/packages/eslint-plugin/docs/rules/quotes.md b/packages/eslint-plugin/docs/rules/quotes.md index c09215bc24b4..4b81076ee471 100644 --- a/packages/eslint-plugin/docs/rules/quotes.md +++ b/packages/eslint-plugin/docs/rules/quotes.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/quotes`](https://eslint.org/docs/rules/quotes) rule. It adds support for TypeScript features which allow quoted names, but not backtick quoted names. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "quotes": "off", - "@typescript-eslint/quotes": "error" -} -``` - -## Options - -See [`eslint/quotes` options](https://eslint.org/docs/rules/quotes#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/quotes.md) - - diff --git a/packages/eslint-plugin/docs/rules/return-await.md b/packages/eslint-plugin/docs/rules/return-await.md index 1aa62401ae49..4c739c6fb910 100644 --- a/packages/eslint-plugin/docs/rules/return-await.md +++ b/packages/eslint-plugin/docs/rules/return-await.md @@ -9,16 +9,6 @@ Returning an awaited promise can make sense for better stack trace information a This rule builds on top of the [`eslint/no-return-await`](https://eslint.org/docs/rules/no-return-await) rule. It expands upon the base rule to add support for optionally requiring `return await` in certain cases. -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "no-return-await": "off", - "@typescript-eslint/return-await": "error" -} -``` - ## Options ```ts diff --git a/packages/eslint-plugin/docs/rules/semi.md b/packages/eslint-plugin/docs/rules/semi.md index bb268d85dce8..b149ec584b7a 100644 --- a/packages/eslint-plugin/docs/rules/semi.md +++ b/packages/eslint-plugin/docs/rules/semi.md @@ -10,23 +10,3 @@ This rule extends the base [`eslint/semi`](https://eslint.org/docs/rules/semi) r It adds support for TypeScript features that require semicolons. See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-style.md) rule, which allows you to specify the delimiter for `type` and `interface` members. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "semi": "off", - "@typescript-eslint/semi": "error" -} -``` - -## Options - -See [`eslint/semi` options](https://eslint.org/docs/rules/semi#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/semi.md) - - diff --git a/packages/eslint-plugin/docs/rules/space-before-blocks.md b/packages/eslint-plugin/docs/rules/space-before-blocks.md index 1896fe2e3ddd..bdb59f78e6e3 100644 --- a/packages/eslint-plugin/docs/rules/space-before-blocks.md +++ b/packages/eslint-plugin/docs/rules/space-before-blocks.md @@ -5,7 +5,9 @@ ## Rule Details This rule extends the base [`eslint/space-before-blocks`](https://eslint.org/docs/rules/space-before-blocks) rule. -It adds support for interfaces and enums: +It adds support for interfaces and enums. + + ### ❌ Incorrect @@ -31,24 +33,6 @@ interface State { } ``` -In case a more specific options object is passed these blocks will follow `classes` configuration option. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "space-before-blocks": "off", - "@typescript-eslint/space-before-blocks": "error" -} -``` - ## Options -See [`eslint/space-before-blocks` options](https://eslint.org/docs/rules/space-before-blocks#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/space-before-blocks.md) - - +In case a more specific options object is passed these blocks will follow `classes` configuration option. diff --git a/packages/eslint-plugin/docs/rules/space-before-function-paren.md b/packages/eslint-plugin/docs/rules/space-before-function-paren.md index 72ba03a822e2..cde123ec2d69 100644 --- a/packages/eslint-plugin/docs/rules/space-before-function-paren.md +++ b/packages/eslint-plugin/docs/rules/space-before-function-paren.md @@ -6,23 +6,3 @@ This rule extends the base [`eslint/space-before-function-paren`](https://eslint.org/docs/rules/space-before-function-paren) rule. It adds support for generic type parameters on function calls. - -## How to Use - -```jsonc -{ - // note you must disable the base rule as it can report incorrect errors - "space-before-function-paren": "off", - "@typescript-eslint/space-before-function-paren": "error" -} -``` - -## Options - -See [`eslint/space-before-function-paren` options](https://eslint.org/docs/rules/space-before-function-paren#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/space-before-function-paren.md) - - diff --git a/packages/eslint-plugin/docs/rules/space-infix-ops.md b/packages/eslint-plugin/docs/rules/space-infix-ops.md index e791420b6530..e49ba5af9e01 100644 --- a/packages/eslint-plugin/docs/rules/space-infix-ops.md +++ b/packages/eslint-plugin/docs/rules/space-infix-ops.md @@ -3,30 +3,10 @@ > See **https://typescript-eslint.io/rules/space-infix-ops** for documentation. This rule extends the base [`eslint/space-infix-ops`](https://eslint.org/docs/rules/space-infix-ops) rule. - -It also add support for enum members +It adds support for enum members. ```ts enum MyEnum { KEY = 'value', } ``` - -## How to Use - -```jsonc -{ - "space-infix-ops": "off", - "@typescript-eslint/space-infix-ops": ["error", { "int32Hint": false }] -} -``` - -## Options - -See [`eslint/space-infix-ops` options](https://eslint.org/docs/rules/space-infix-ops#options). - - - -Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/space-infix-ops.md) - - diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index c88da29f6277..23838c8264fd 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -76,10 +76,20 @@ export const generatedRuleDocs: Plugin = () => { if (meta.docs.extendsBaseRule) { if (howToUseH2Index === -1) { - howToUseH2Index = - whenNotToUseItH2Index === -1 - ? parent.children.length - : ++whenNotToUseItH2Index; + if (optionsH2Index !== -1) { + howToUseH2Index = optionsH2Index; + optionsH2Index += 1; + + if (whenNotToUseItH2Index !== -1) { + whenNotToUseItH2Index += 1; + } + } else { + howToUseH2Index = + whenNotToUseItH2Index === -1 + ? parent.children.length + : ++whenNotToUseItH2Index; + } + parent.children.splice(howToUseH2Index, 0, { children: [ { @@ -150,7 +160,7 @@ export const generatedRuleDocs: Plugin = () => { type: 'code', meta: 'title=".eslintrc.cjs"', value: `module.exports = { - // note you must disable the base rule as it can report incorrect errors + // Note: you must disable the base rule as it can report incorrect errors "${file.stem}": "off", "@typescript-eslint/${file.stem}": "${optionLevel}" };`, From cabf242664f98e40fed66a0128db91064cbd4211 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 31 Jul 2022 23:07:14 -0400 Subject: [PATCH 12/26] Fix unit test, and enable debug cypress logging --- .github/workflows/ci.yml | 2 + packages/eslint-plugin/tests/docs.test.ts | 59 +---------------------- 2 files changed, 3 insertions(+), 58 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6363babb0df5..33d39c3487a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -197,6 +197,8 @@ jobs: - name: Cypress run uses: cypress-io/github-action@v2 with: + env: + DEBUG: '@cypress/github-action' project: ./packages/website start: yarn start diff --git a/packages/eslint-plugin/tests/docs.test.ts b/packages/eslint-plugin/tests/docs.test.ts index 7ab1095f4ad0..e963b30394f5 100644 --- a/packages/eslint-plugin/tests/docs.test.ts +++ b/packages/eslint-plugin/tests/docs.test.ts @@ -1,5 +1,4 @@ import fs from 'fs'; -import { JSONSchema4 } from 'json-schema'; import path from 'path'; import { marked } from 'marked'; @@ -18,22 +17,8 @@ function parseMarkdownFile(filePath: string): marked.TokensList { }); } -function isEmptySchema(schema: JSONSchema4 | JSONSchema4[]): boolean { - return Array.isArray(schema) - ? schema.length === 0 - : Object.keys(schema).length === 0; -} - type TokenType = marked.Token['type']; -function tokenAs( - token: marked.Token, - type: Type, -): marked.Token & { type: Type } { - expect(token.type).toBe(type); - return token as marked.Token & { type: Type }; -} - function tokenIs( token: marked.Token, type: Type, @@ -63,7 +48,7 @@ describe('Validating rule docs', () => { expect(files.sort()).toEqual(ruleFiles); }); - for (const [ruleName, rule] of rulesData) { + for (const [ruleName] of rulesData) { describe(ruleName, () => { const filePath = path.join(docsRoot, `${ruleName}.md`); @@ -91,48 +76,6 @@ describe('Validating rule docs', () => { expect(header.text).toBe(titleCase(header.text)), ); }); - - it(`Options in ${ruleName}.md must match the rule meta`, () => { - // TODO(#4365): We don't yet enforce formatting for all rules. - if ( - !isEmptySchema(rule.meta.schema) || - !rule.meta.docs?.recommended || - rule.meta.docs.extendsBaseRule - ) { - return; - } - - const tokens = parseMarkdownFile(filePath); - - const optionsIndex = tokens.findIndex( - token => tokenIsH2(token) && token.text === 'Options', - ); - expect(optionsIndex).toBeGreaterThan(0); - - const codeBlock = tokenAs(tokens[optionsIndex + 1], 'code'); - tokenAs(tokens[optionsIndex + 2], 'space'); - const descriptionBlock = tokenAs(tokens[optionsIndex + 3], 'paragraph'); - - expect(codeBlock).toMatchObject({ - lang: 'jsonc', - text: ` -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/${ruleName}": "${ - rule.meta.docs.recommended === 'strict' - ? 'warn' - : rule.meta.docs.recommended - }" - } -} - `.trim(), - type: 'code', - }); - expect(descriptionBlock).toMatchObject({ - text: 'This rule is not configurable.', - }); - }); }); } }); From 16e188327d97e99f4715889ce48fef62dd93a0d6 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 31 Jul 2022 23:21:04 -0400 Subject: [PATCH 13/26] Fix deprecation notices, and ci.yml env indent --- .github/workflows/ci.yml | 6 +++--- packages/eslint-plugin/docs/rules/camelcase.md | 4 +++- packages/eslint-plugin/docs/rules/no-duplicate-imports.md | 3 ++- packages/eslint-plugin/docs/rules/no-implicit-any-catch.md | 5 +++++ .../eslint-plugin/docs/rules/no-parameter-properties.md | 5 +++++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33d39c3487a8..da8852d75751 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,11 +194,11 @@ jobs: - name: Install Cypress run: yarn cypress install - - name: Cypress run + - env: + DEBUG: '@cypress/github-action' + name: Cypress run uses: cypress-io/github-action@v2 with: - env: - DEBUG: '@cypress/github-action' project: ./packages/website start: yarn start diff --git a/packages/eslint-plugin/docs/rules/camelcase.md b/packages/eslint-plugin/docs/rules/camelcase.md index cea28224965f..1b3c0e893183 100644 --- a/packages/eslint-plugin/docs/rules/camelcase.md +++ b/packages/eslint-plugin/docs/rules/camelcase.md @@ -1,7 +1,9 @@ -## DEPRECATED +:::danger Deprecated This rule has been deprecated in favour of the [`naming-convention`](./naming-convention.md) rule. +::: + - - ```ts try { // ... @@ -78,8 +62,6 @@ try { } ``` - - ## When Not To Use It If you are not using TypeScript 4.0 (or greater), then you will not be able to use this rule, annotations on catch clauses is not supported. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md index 80142fe65380..77957a852704 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md @@ -50,30 +50,10 @@ if (someStringBoolean === true) { ## Options -The rule accepts an options object with the following properties. - -```ts -type Options = { - // if false, comparisons between a nullable boolean variable to `true` will be checked and fixed - allowComparingNullableBooleansToTrue?: boolean; - // if false, comparisons between a nullable boolean variable to `false` will be checked and fixed - allowComparingNullableBooleansToFalse?: boolean; -}; -``` - -### Defaults - This rule always checks comparisons between a boolean variable and a boolean literal. Comparisons between nullable boolean variables and boolean literals are **not** checked by default. -```ts -const defaults = { - allowComparingNullableBooleansToTrue: true, - allowComparingNullableBooleansToFalse: true, -}; -``` - ### `allowComparingNullableBooleansToTrue` Examples of code for this rule with `{ allowComparingNullableBooleansToTrue: false }`: diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md index 2594184ea02b..ea448989bf80 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md @@ -70,20 +70,6 @@ function bar(arg?: string | null) { ## Options -```ts -type Options = { - // if true, the rule will ignore constant loop conditions - allowConstantLoopConditions?: boolean; - // if true, the rule will not error when running with a tsconfig that has strictNullChecks turned **off** - allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean; -}; - -const defaultOptions: Options = { - allowConstantLoopConditions: false, - allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false, -}; -``` - ### `allowConstantLoopConditions` Example of correct code for `{ allowConstantLoopConditions: true }`: diff --git a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md index d4b006c1d70f..a7a232f302c0 100644 --- a/packages/eslint-plugin/docs/rules/require-array-sort-compare.md +++ b/packages/eslint-plugin/docs/rules/require-array-sort-compare.md @@ -54,21 +54,6 @@ userDefinedType.sort(); ## Options -The rule accepts an options object with the following properties: - -```ts -type Options = { - /** - * If true, an array which all elements are string is ignored. - */ - ignoreStringArrays?: boolean; -}; - -const defaults = { - ignoreStringArrays: false, -}; -``` - ### `ignoreStringArrays` Examples of code for this rule with `{ ignoreStringArrays: true }`: diff --git a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md index 5b984f0b21c5..e133cedd2183 100644 --- a/packages/eslint-plugin/docs/rules/restrict-plus-operands.md +++ b/packages/eslint-plugin/docs/rules/restrict-plus-operands.md @@ -24,22 +24,6 @@ var foo = 1n + 1n; ## Options -The rule accepts an options object with the following properties: - -```ts -type Options = { - // if true, check compound assignments (`+=`) - checkCompoundAssignments?: boolean; - // if true, 'any' itself and `string`,`bigint`, `number` is allowed. - allowAny?: boolean; -}; - -const defaults = { - checkCompoundAssignments: false, - allowAny: false, -}; -``` - ### `checkCompoundAssignments` Examples of code for this rule with `{ checkCompoundAssignments: true }`: @@ -94,9 +78,3 @@ var fn = (a: any, b: number) => a + b; ``` ## How to Use - -```json -{ - "@typescript-eslint/restrict-plus-operands": "error" -} -``` diff --git a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md index 37423d23abc4..e1b38de23ce4 100644 --- a/packages/eslint-plugin/docs/rules/restrict-template-expressions.md +++ b/packages/eslint-plugin/docs/rules/restrict-template-expressions.md @@ -31,31 +31,6 @@ const msg3 = `stringWithKindProp = ${stringWithKindProp}`; ## Options -The rule accepts an options object with the following properties: - -```ts -type Options = { - // if true, also allow number type in template expressions - allowNumber?: boolean; - // if true, also allow boolean type in template expressions - allowBoolean?: boolean; - // if true, also allow any in template expressions - allowAny?: boolean; - // if true, also allow null and undefined in template expressions - allowNullish?: boolean; - // if true, also allow RegExp in template expressions - allowRegExp?: boolean; -}; - -const defaults = { - allowNumber: true, - allowBoolean: false, - allowAny: false, - allowNullish: false, - allowRegExp: false, -}; -``` - ### `allowNumber` Examples of additional **correct** code for this rule with `{ allowNumber: true }`: diff --git a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md index 0e02b686b87e..00352146aa03 100644 --- a/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md +++ b/packages/eslint-plugin/docs/rules/sort-type-union-intersection-members.md @@ -91,49 +91,6 @@ type T4 = ## Options -```ts -type Options = { - // true to check intersection types, false otherwise - checkIntersections?: boolean; - // true to check union types, false otherwise - checkUnions?: boolean; - // the ordering of the groups - groupOrder?: ( - | 'conditional' - | 'function' - | 'import' - | 'intersection' - | 'keyword' - | 'literal' - | 'named' - | 'object' - | 'operator' - | 'tuple' - | 'union' - | 'nullish' - )[]; -}; - -const defaultOptions: Options = { - checkIntersections: true, - checkUnions: true, - groupOrder: [ - 'named', - 'keyword', - 'operator', - 'literal', - 'function', - 'import', - 'conditional', - 'object', - 'tuple', - 'intersection', - 'union', - 'nullish', - ], -}; -``` - ### `groupOrder` Each member of the type is placed into a group, and then the rule sorts alphabetically within each group. diff --git a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md index a86e8146ba6f..ba851bf89401 100644 --- a/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md +++ b/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md @@ -85,29 +85,6 @@ const foo = (arg: any) => (Boolean(arg) ? 1 : 0); ## Options -```ts -type Options = { - allowString?: boolean; - allowNumber?: boolean; - allowNullableObject?: boolean; - allowNullableBoolean?: boolean; - allowNullableString?: boolean; - allowNullableNumber?: boolean; - allowAny?: boolean; -}; - -const defaultOptions: Options = { - allowString: true, - allowNumber: true, - allowNullableObject: true, - allowNullableBoolean: false, - allowNullableString: false, - allowNullableNumber: false, - allowAny: false, - allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing: false, -}; -``` - ### `allowString` Allows `string` in a boolean context. diff --git a/packages/eslint-plugin/docs/rules/triple-slash-reference.md b/packages/eslint-plugin/docs/rules/triple-slash-reference.md index ce73a33d5942..4ff58fb083e6 100644 --- a/packages/eslint-plugin/docs/rules/triple-slash-reference.md +++ b/packages/eslint-plugin/docs/rules/triple-slash-reference.md @@ -46,20 +46,6 @@ import foo = require('foo'); ## Options -```ts -type Options = { - lib?: 'always' | 'never'; - path?: 'always' | 'never'; - types?: 'always' | 'never' | 'prefer-import'; -}; - -const defaultOptions: Options = { - lib: 'always', - path: 'never', - types: 'prefer-import', -}; -``` - ## When To Use It If you want to ban use of one or all of the triple slash reference directives, or any time you might use triple-slash type reference directives and ES6 import declarations in the same file. diff --git a/packages/eslint-plugin/docs/rules/typedef.md b/packages/eslint-plugin/docs/rules/typedef.md index 8976c5211974..e256c673304b 100644 --- a/packages/eslint-plugin/docs/rules/typedef.md +++ b/packages/eslint-plugin/docs/rules/typedef.md @@ -18,11 +18,15 @@ class ContainsText { } ``` -**_Note:_** requiring type annotations unnecessarily can be cumbersome to maintain and generally reduces code readability. +:::caution + +Requiring type annotations unnecessarily can be cumbersome to maintain and generally reduces code readability. TypeScript is often better at inferring types than easily written type annotations would allow. **Instead of enabling `typedef`, it is generally recommended to use the `--noImplicitAny` and `--strictPropertyInitialization` compiler options to enforce type annotations only when useful.** +::: + ## Rule Details This rule can enforce type annotations in locations regardless of whether they're required. @@ -32,30 +36,6 @@ This is typically used to maintain consistency for element types that sometimes ## Options -```ts -type Options = { - arrayDestructuring?: boolean; - arrowParameter?: boolean; - memberVariableDeclaration?: boolean; - objectDestructuring?: boolean; - parameter?: boolean; - propertyDeclaration?: boolean; - variableDeclaration?: boolean; - variableDeclarationIgnoreFunction?: boolean; -}; - -const defaultOptions: Options = { - arrayDestructuring: false, - arrowParameter: false, - memberVariableDeclaration: false, - objectDestructuring: false, - parameter: false, - propertyDeclaration: false, - variableDeclaration: false, - variableDeclarationIgnoreFunction: false, -}; -``` - For example, with the following configuration: ```json diff --git a/packages/eslint-plugin/docs/rules/unbound-method.md b/packages/eslint-plugin/docs/rules/unbound-method.md index b42e274ec59b..5ec384f35152 100644 --- a/packages/eslint-plugin/docs/rules/unbound-method.md +++ b/packages/eslint-plugin/docs/rules/unbound-method.md @@ -9,7 +9,7 @@ If you're working with `jest`, you can use [`eslint-plugin-jest`'s version of th ## Rule Details -Examples of code for this rule +Examples of code for this rule with the default options: @@ -72,10 +72,6 @@ const { double } = arith; ## Options -The rule accepts an options object with the following property: - -- `ignoreStatic` to not check whether `static` methods are correctly bound - ### `ignoreStatic` Examples of **correct** code for this rule with `{ ignoreStatic: true }`: diff --git a/packages/eslint-plugin/docs/rules/unified-signatures.md b/packages/eslint-plugin/docs/rules/unified-signatures.md index 290c3f337399..d744012caa16 100644 --- a/packages/eslint-plugin/docs/rules/unified-signatures.md +++ b/packages/eslint-plugin/docs/rules/unified-signatures.md @@ -6,22 +6,6 @@ This rule aims to keep the source code as maintainable as possible by reducing the amount of overloads. -## Options - -```ts -type Options = { - ignoreDifferentlyNamedParameters?: boolean; -}; - -const defaultOptions: Options = { - ignoreDifferentlyNamedParameters: false, -}; -``` - -The rule accepts an options object with the following property: - -- `ignoreDifferentlyNamedParameters`: whether two parameters with different names at the same index should be considered different even if their types are the same. - Examples of code for this rule with the default options: @@ -75,3 +59,5 @@ function f(b: string): void; function f(...a: number[]): void; function f(...a: string[]): void; ``` + +## Options diff --git a/packages/eslint-plugin/src/rules/no-explicit-any.ts b/packages/eslint-plugin/src/rules/no-explicit-any.ts index e0e8bfd2b9cf..6dbe8f2643fb 100644 --- a/packages/eslint-plugin/src/rules/no-explicit-any.ts +++ b/packages/eslint-plugin/src/rules/no-explicit-any.ts @@ -33,9 +33,12 @@ export default util.createRule({ 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', }, }, diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index f280780ef89c..6bd2ba910377 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -25,15 +25,23 @@ export default util.createRule({ 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', }, }, diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index c59d0f08a6ef..93008e46bf21 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -36,8 +36,15 @@ export default util.createRule({ { type: 'object', properties: { - ignoreVoid: { type: 'boolean' }, - ignoreIIFE: { type: 'boolean' }, + ignoreVoid: { + description: 'Whether to ignore `void` expressions.', + type: 'boolean', + }, + ignoreIIFE: { + description: + 'Whether to ignore async IIFEs (Immediately Invocated Function Expressions).', + type: 'boolean', + }, }, additionalProperties: false, }, diff --git a/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts b/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts index b48d68fde451..e6d4255dd854 100644 --- a/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts +++ b/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts @@ -35,6 +35,8 @@ export default util.createRule({ additionalProperties: false, properties: { allowExplicitAny: { + description: + 'Whehter to disallow specifying `: any` as the error type as well. See also `no-explicit-any`.', type: 'boolean', }, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts index d135b3dd18a9..592f2d03c024 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts @@ -56,9 +56,13 @@ export default util.createRule({ type: 'object', properties: { allowComparingNullableBooleansToTrue: { + description: + 'Whether to allow comparisons between nullable boolean variables and `true`.', type: 'boolean', }, allowComparingNullableBooleansToFalse: { + description: + 'Whether to allow comparisons between nullable boolean variables and `false`.', type: 'boolean', }, }, diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index df6580be86a6..865fc959743c 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -98,9 +98,13 @@ export default createRule({ type: 'object', 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', }, }, diff --git a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts index 5354c87afa64..26cc035acfda 100644 --- a/packages/eslint-plugin/src/rules/require-array-sort-compare.ts +++ b/packages/eslint-plugin/src/rules/require-array-sort-compare.ts @@ -32,6 +32,8 @@ export default util.createRule({ type: 'object', properties: { ignoreStringArrays: { + description: + 'Whether to ignore arrays in which all elements are strings.', type: 'boolean', }, }, diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 3884dec24dd0..c72579b5fafd 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -42,9 +42,11 @@ export default util.createRule({ additionalProperties: false, properties: { checkCompoundAssignments: { + description: 'Whether to check compound assignments such as `+=`.', type: 'boolean', }, allowAny: { + description: 'Whether to allow `any` typed values.', type: 'boolean', }, }, diff --git a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts index 0140c3dc0d47..fb4e7bb7bea7 100644 --- a/packages/eslint-plugin/src/rules/restrict-template-expressions.ts +++ b/packages/eslint-plugin/src/rules/restrict-template-expressions.ts @@ -31,11 +31,31 @@ export default util.createRule({ { type: 'object', properties: { - allowNumber: { type: 'boolean' }, - allowBoolean: { type: 'boolean' }, - allowAny: { type: 'boolean' }, - allowNullish: { type: 'boolean' }, - allowRegExp: { type: 'boolean' }, + allowNumber: { + description: + 'Whether to allow `number` typed values in template expressions.', + type: 'boolean', + }, + allowBoolean: { + description: + 'Whether to allow `boolean` typed values in template expressions.', + type: 'boolean', + }, + allowAny: { + description: + 'Whether to allow `any` typed values in template expressions.', + type: 'boolean', + }, + allowNullish: { + description: + 'Whether to allow `nullish` typed values in template expressions.', + type: 'boolean', + }, + allowRegExp: { + description: + 'Whether to allow `regexp` typed values in template expressions.', + type: 'boolean', + }, }, }, ], diff --git a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts index f96c4677506d..201c411afee8 100644 --- a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts +++ b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts @@ -121,12 +121,15 @@ export default util.createRule({ type: 'object', 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.', type: 'array', items: { type: 'string', diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index 2c62881e81b1..2151cd7b3e86 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -142,6 +142,8 @@ export default util.createRule({ type: 'object', properties: { ignoreStatic: { + description: + 'Whether to skip checking whether `static` methods are correctly bound.', type: 'boolean', }, }, diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index dc1f683ee35b..ec502b5661a1 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -81,6 +81,8 @@ export default util.createRule({ 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', }, }, From dcfb4643f4edc4156fb63890db961eb642ba9ac8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 00:04:49 -0400 Subject: [PATCH 17/26] naming-convention, I give up --- packages/website/plugins/generated-rule-docs.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 9f83d43f4b49..cddcc1aca18c 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -9,6 +9,14 @@ import * as tseslintParser from '@typescript-eslint/parser'; import * as eslintPlugin from '@typescript-eslint/eslint-plugin'; import { EOL } from 'os'; +/** + * Rules whose options schema generate annoyingly complex schemas. + * + * @remarks These need to be typed in manually in their .md docs file. + * @todo Get these schemas printing nicely in their .md docs files! + */ +const COMPLICATED_RULE_OPTIONS = new Set(['naming-convention']); + export const generatedRuleDocs: Plugin = () => { return async (root, file) => { if (file.stem == null) { @@ -187,7 +195,7 @@ export const generatedRuleDocs: Plugin = () => { ], type: 'paragraph', } as mdast.Paragraph); - } else { + } else if (!COMPLICATED_RULE_OPTIONS.has(file.stem)) { const optionsSchema = meta.schema instanceof Array ? meta.schema[0] : meta.schema; From 6724746b57cc14dee841f864954b6e9fb5d53ff7 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 00:07:17 -0400 Subject: [PATCH 18/26] Aha, a missing lint rule --- packages/website/plugins/generated-rule-docs.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index cddcc1aca18c..e2ef920e501d 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/explicit-function-return-type */ import type * as unist from 'unist'; import * as mdast from 'mdast'; import { format } from 'prettier'; @@ -70,7 +69,7 @@ export const generatedRuleDocs: Plugin = () => { parent.children.splice(attributesH2Index, 0, attributesNode); // 4. Make sure the appropriate headers exist to place content under - const { howToUseH2Index, optionsH2Index } = (() => { + const [howToUseH2Index, optionsH2Index] = ((): [number, number] => { let howToUseH2Index = parent.children.findIndex( createH2TextFilter('How to Use'), ); @@ -128,7 +127,7 @@ export const generatedRuleDocs: Plugin = () => { } as mdast.Heading); } - return { howToUseH2Index, optionsH2Index }; + return [howToUseH2Index, optionsH2Index]; })(); // 5. Add a description of how to use / options for the rule From e86e0b701c18b7a6eb58e5ac50a8976676118614 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 00:33:12 -0400 Subject: [PATCH 19/26] member-ordering, I give up on you too --- .../rules/no-confusing-non-null-assertion.md | 13 --------- .../docs/rules/no-duplicate-enum-values.md | 13 --------- .../docs/rules/no-dynamic-delete.md | 13 --------- .../docs/rules/no-extra-non-null-assertion.md | 13 --------- .../docs/rules/no-for-in-array.md | 13 --------- .../docs/rules/no-inferrable-types.md | 26 ++--------------- .../docs/rules/no-invalid-void-type.md | 12 -------- .../docs/rules/no-misused-new.md | 13 --------- ...no-non-null-asserted-nullish-coalescing.md | 13 --------- .../no-non-null-asserted-optional-chain.md | 13 --------- .../docs/rules/no-non-null-assertion.md | 13 --------- .../rules/no-redundant-type-constituents.md | 13 --------- .../docs/rules/no-require-imports.md | 13 --------- .../eslint-plugin/docs/rules/no-this-alias.md | 16 ---------- .../docs/rules/no-unnecessary-qualifier.md | 13 --------- .../rules/no-unnecessary-type-arguments.md | 13 --------- .../rules/no-unnecessary-type-constraint.md | 13 --------- .../docs/rules/no-unsafe-argument.md | 13 --------- .../docs/rules/no-unsafe-assignment.md | 13 --------- .../docs/rules/no-unsafe-call.md | 13 --------- .../docs/rules/no-unsafe-member-access.md | 13 --------- .../docs/rules/no-unsafe-return.md | 13 --------- .../docs/rules/no-useless-empty-export.md | 13 --------- .../docs/rules/no-var-requires.md | 13 --------- .../non-nullable-type-assertion-style.md | 13 --------- .../docs/rules/prefer-as-const.md | 13 --------- .../docs/rules/prefer-enum-initializers.md | 13 --------- .../eslint-plugin/docs/rules/prefer-for-of.md | 13 --------- .../docs/rules/prefer-function-type.md | 13 --------- .../docs/rules/prefer-includes.md | 13 --------- .../docs/rules/prefer-namespace-keyword.md | 13 --------- .../docs/rules/prefer-optional-chain.md | 13 --------- .../rules/prefer-readonly-parameter-types.md | 13 --------- .../rules/prefer-reduce-type-parameter.md | 13 --------- .../docs/rules/prefer-regexp-exec.md | 13 --------- .../docs/rules/prefer-return-this-type.md | 13 --------- .../rules/prefer-string-starts-ends-with.md | 13 --------- .../docs/rules/prefer-ts-expect-error.md | 13 --------- .../docs/rules/promise-function-async.md | 29 ------------------- .../docs/rules/switch-exhaustiveness-check.md | 13 --------- .../docs/rules/triple-slash-reference.md | 6 ++-- .../docs/rules/type-annotation-spacing.md | 14 ++------- .../docs/rules/unbound-method.md | 13 --------- .../docs/rules/unified-signatures.md | 4 +++ .../eslint-plugin/src/rules/no-this-alias.ts | 4 +++ .../src/rules/promise-function-async.ts | 4 +++ .../website/plugins/generated-rule-docs.ts | 22 ++++++++++++-- 47 files changed, 39 insertions(+), 579 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md index f77d111bc8c8..0f1c676f1242 100644 --- a/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-confusing-non-null-assertion.md @@ -41,19 +41,6 @@ const isEqualsBar = foo.bar == 'hello'; const isEqualsNum = (1 + foo.num!) == 2; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-confusing-non-null-assertion": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about this confusion, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md b/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md index 3e284d3eec62..131a15f95e61 100644 --- a/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md +++ b/packages/eslint-plugin/docs/rules/no-duplicate-enum-values.md @@ -41,16 +41,3 @@ enum E { B = 'B' } ``` - -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-duplicate-enum-values": "warn" - } -} -``` - -This rule is not configurable. diff --git a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md index 7c6090f812f8..270be31c7a16 100644 --- a/packages/eslint-plugin/docs/rules/no-dynamic-delete.md +++ b/packages/eslint-plugin/docs/rules/no-dynamic-delete.md @@ -40,19 +40,6 @@ delete container[7]; delete container['-Infinity']; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-dynamic-delete": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It When you know your keys are safe to delete, this rule can be unnecessary. diff --git a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md index 6c7068b693b0..0115f993754e 100644 --- a/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md @@ -45,16 +45,3 @@ function foo(bar?: { n: number }) { return bar?.n; } ``` - -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-extra-non-null-assertion": "error" - } -} -``` - -This rule is not configurable. diff --git a/packages/eslint-plugin/docs/rules/no-for-in-array.md b/packages/eslint-plugin/docs/rules/no-for-in-array.md index 29d0c2548a48..f7223ae7106d 100644 --- a/packages/eslint-plugin/docs/rules/no-for-in-array.md +++ b/packages/eslint-plugin/docs/rules/no-for-in-array.md @@ -39,19 +39,6 @@ for (const x in { a: 3, b: 4, c: 5 }) { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-for-in-array": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you want to iterate through a loop using the indices in an array as strings, you can turn off this rule. diff --git a/packages/eslint-plugin/docs/rules/no-inferrable-types.md b/packages/eslint-plugin/docs/rules/no-inferrable-types.md index 73fcfd7ae520..7989933af0d9 100644 --- a/packages/eslint-plugin/docs/rules/no-inferrable-types.md +++ b/packages/eslint-plugin/docs/rules/no-inferrable-types.md @@ -9,29 +9,7 @@ Explicit types where they can be easily inferred may add unnecessary verbosity. This rule disallows explicit type declarations on parameters, variables and properties where the type can be easily inferred from its value. -## Options - -This rule accepts the following options: - -```ts -interface Options { - ignoreParameters?: boolean; - ignoreProperties?: boolean; -} -``` - -### Default - -The default options are: - -```json -{ - "ignoreParameters": false, - "ignoreProperties": false -} -``` - -With these options, the following patterns are: +Examples of code with the default options: @@ -121,6 +99,8 @@ function fn(a: number, b: boolean, c: string) {} +## Options + ### `ignoreParameters` When set to true, the following pattern is considered valid: diff --git a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md index 0b4f93385225..63a140ac593d 100644 --- a/packages/eslint-plugin/docs/rules/no-invalid-void-type.md +++ b/packages/eslint-plugin/docs/rules/no-invalid-void-type.md @@ -57,18 +57,6 @@ type stillVoid = void | never; ## Options -```ts -interface Options { - allowInGenericTypeArguments?: boolean | string[]; - allowAsThisParameter?: boolean; -} - -const defaultOptions: Options = { - allowInGenericTypeArguments: true, - allowAsThisParameter: false, -}; -``` - ### `allowInGenericTypeArguments` This option lets you control if `void` can be used as a valid value for generic type parameters. diff --git a/packages/eslint-plugin/docs/rules/no-misused-new.md b/packages/eslint-plugin/docs/rules/no-misused-new.md index b79af1f3eb3b..eaaed567f430 100644 --- a/packages/eslint-plugin/docs/rules/no-misused-new.md +++ b/packages/eslint-plugin/docs/rules/no-misused-new.md @@ -33,16 +33,3 @@ interface I { new (): C; } ``` - -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-misused-new": "error" - } -} -``` - -This rule is not configurable. diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md index b9008a8f78c7..e92e132db1ae 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-nullish-coalescing.md @@ -45,19 +45,6 @@ let x: string; x! ?? ''; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-non-null-asserted-nullish-coalescing": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are not using TypeScript 3.7 (or greater), then you will not need to use this rule, as the nullish coalescing operator is not supported. diff --git a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md index aff4d5b47c41..79052199a862 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md @@ -44,19 +44,6 @@ foo?.bar!(); foo?.bar!().baz; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-non-null-asserted-optional-chain": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are not using TypeScript 3.7 (or greater), then you will not need to use this rule, as the operator is not supported. diff --git a/packages/eslint-plugin/docs/rules/no-non-null-assertion.md b/packages/eslint-plugin/docs/rules/no-non-null-assertion.md index 0eb9b4970c58..94f753269ffd 100644 --- a/packages/eslint-plugin/docs/rules/no-non-null-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-non-null-assertion.md @@ -32,19 +32,6 @@ const foo: Foo = getFoo(); const includesBaz: boolean = foo.bar?.includes('baz') ?? false; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-non-null-assertion": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about strict null-checking, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md b/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md index cbfde25358fd..7e1005c958c2 100644 --- a/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md +++ b/packages/eslint-plugin/docs/rules/no-redundant-type-constituents.md @@ -66,19 +66,6 @@ type IntersectionStringLiteral = 'foo'; type ReturnUnionNever = () => string | never; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-redundant-type-constituents": "warn" - } -} -``` - -This rule is not configurable. - ## Limitations This rule plays it safe and only works with bottom types, top types, and comparing literal types to primitive types. diff --git a/packages/eslint-plugin/docs/rules/no-require-imports.md b/packages/eslint-plugin/docs/rules/no-require-imports.md index 0a3ddd5d2f9f..7997d87662d7 100644 --- a/packages/eslint-plugin/docs/rules/no-require-imports.md +++ b/packages/eslint-plugin/docs/rules/no-require-imports.md @@ -31,19 +31,6 @@ import lib9 = lib2.anotherSubImport; import lib10 from 'lib10'; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-require-imports": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about TypeScript module syntax, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-this-alias.md b/packages/eslint-plugin/docs/rules/no-this-alias.md index 3433ae28eb0c..d45bcbbe36b1 100644 --- a/packages/eslint-plugin/docs/rules/no-this-alias.md +++ b/packages/eslint-plugin/docs/rules/no-this-alias.md @@ -35,22 +35,6 @@ Examples of **correct** code for this rule: (see the rationale above) -## Options - -You can pass an object option: - -```jsonc -{ - "@typescript-eslint/no-this-alias": [ - "error", - { - "allowDestructuring": false, // Disallow `const { props, state } = this`; true by default - "allowedNames": ["self"] // Allow `const self = this`; `[]` by default - } - ] -} -``` - ## When Not To Use It If you need to assign `this` to variables, you shouldn’t use this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md index 31905c485f4d..e6fbad4bf233 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md @@ -76,19 +76,6 @@ namespace X { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unnecessary-qualifier": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about having unneeded namespace or enum qualifiers, then you don't need to use this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md index 6f15d1493753..58d08d27a5e3 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md @@ -53,16 +53,3 @@ class D extends C {} interface I {} class Impl implements I {} ``` - -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unnecessary-type-arguments": "warn" - } -} -``` - -This rule is not configurable. diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md index 4cd813ec0d6d..5014dff45a69 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-constraint.md @@ -56,19 +56,6 @@ const Quux = () => {}; function Quuz() {} ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unnecessary-type-constraint": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about the specific styles of your type constraints, or never use them in the first place, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md index 15e1c82e7ff6..c93c9d951196 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-argument.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-argument.md @@ -71,19 +71,6 @@ declare function foo(arg1: unknown, arg2: Set, arg3: unknown[]): void; foo(1 as any, new Set(), [] as any[]); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unsafe-argument": "error" - } -} -``` - -This rule is not configurable. - ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md index 309d0b13d2e8..efa1ff5a3a92 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-assignment.md @@ -74,19 +74,6 @@ const x: unknown[] = y as any[]; const x: Set = y as Set; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unsafe-assignment": "error" - } -} -``` - -This rule is not configurable. - ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.md b/packages/eslint-plugin/docs/rules/no-unsafe-call.md index 103aa55e7b23..a5435fff5727 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.md @@ -48,19 +48,6 @@ new Map(); String.raw`foo`; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unsafe-call": "error" - } -} -``` - -This rule is not configurable. - ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md index c90028aa6643..896d0c5d7062 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-member-access.md @@ -54,19 +54,6 @@ arr[idx]; arr[idx++]; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unsafe-member-access": "error" - } -} -``` - -This rule is not configurable. - ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-return.md b/packages/eslint-plugin/docs/rules/no-unsafe-return.md index d2e5a36f309c..4952af4cf844 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-return.md +++ b/packages/eslint-plugin/docs/rules/no-unsafe-return.md @@ -91,19 +91,6 @@ function foo2(): unknown[] { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-unsafe-return": "error" - } -} -``` - -This rule is not configurable. - ## Related To - [`no-explicit-any`](./no-explicit-any.md) diff --git a/packages/eslint-plugin/docs/rules/no-useless-empty-export.md b/packages/eslint-plugin/docs/rules/no-useless-empty-export.md index 1687bfacc91b..5990df0c6aee 100644 --- a/packages/eslint-plugin/docs/rules/no-useless-empty-export.md +++ b/packages/eslint-plugin/docs/rules/no-useless-empty-export.md @@ -37,16 +37,3 @@ export const value = 'Hello, world!'; ```ts import 'some-other-module'; ``` - -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-useless-empty-export": "warn" - } -} -``` - -This rule is not configurable. diff --git a/packages/eslint-plugin/docs/rules/no-var-requires.md b/packages/eslint-plugin/docs/rules/no-var-requires.md index 247535b011e9..800d02f08bfd 100644 --- a/packages/eslint-plugin/docs/rules/no-var-requires.md +++ b/packages/eslint-plugin/docs/rules/no-var-requires.md @@ -26,19 +26,6 @@ require('foo'); import foo from 'foo'; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/no-var-requires": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about TypeScript module syntax, then you will not need this rule. diff --git a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md index 486f464d77e1..ab638754511f 100644 --- a/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md +++ b/packages/eslint-plugin/docs/rules/non-nullable-type-assertion-style.md @@ -28,19 +28,6 @@ const definitely = maybe!; const alsoDefinitely = maybe!; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/non-nullable-type-assertion-style": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't mind having unnecessarily verbose type casts, you can avoid this rule. diff --git a/packages/eslint-plugin/docs/rules/prefer-as-const.md b/packages/eslint-plugin/docs/rules/prefer-as-const.md index ce6de3345444..741dd5fca897 100644 --- a/packages/eslint-plugin/docs/rules/prefer-as-const.md +++ b/packages/eslint-plugin/docs/rules/prefer-as-const.md @@ -31,19 +31,6 @@ let foo = { bar: 'baz' }; -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-as-const": "error" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are using TypeScript < 3.4 diff --git a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md index c16f00bc8641..a142ce178f8b 100644 --- a/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md +++ b/packages/eslint-plugin/docs/rules/prefer-enum-initializers.md @@ -71,19 +71,6 @@ enum Color { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-enum-initializers": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't care about `enum`s having implicit values you can safely disable this rule. diff --git a/packages/eslint-plugin/docs/rules/prefer-for-of.md b/packages/eslint-plugin/docs/rules/prefer-for-of.md index 575e45b39e15..fb28afd3f3a8 100644 --- a/packages/eslint-plugin/docs/rules/prefer-for-of.md +++ b/packages/eslint-plugin/docs/rules/prefer-for-of.md @@ -38,19 +38,6 @@ for (let i = 0; i < arr.length; i++) { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-for-of": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you transpile for browsers that do not support for-of loops, you may wish to use traditional for loops that produce more compact code. diff --git a/packages/eslint-plugin/docs/rules/prefer-function-type.md b/packages/eslint-plugin/docs/rules/prefer-function-type.md index 8c0e9de2b5ca..d1f8e555ed61 100644 --- a/packages/eslint-plugin/docs/rules/prefer-function-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-function-type.md @@ -78,19 +78,6 @@ interface Overloaded { type Intersection = ((data: string) => number) & ((id: number) => string); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-function-type": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you specifically want to use an interface or type literal with a single call signature for stylistic reasons, you can disable this rule. diff --git a/packages/eslint-plugin/docs/rules/prefer-includes.md b/packages/eslint-plugin/docs/rules/prefer-includes.md index 3eec29ab8923..cbff00116920 100644 --- a/packages/eslint-plugin/docs/rules/prefer-includes.md +++ b/packages/eslint-plugin/docs/rules/prefer-includes.md @@ -70,19 +70,6 @@ userDefined.includes(value); mismatchExample.indexOf(value) >= 0; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-includes": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't want to suggest `includes`, you can safely turn this rule off. diff --git a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md index bc7b601934d2..a6d6274c5cc3 100644 --- a/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md +++ b/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md @@ -13,19 +13,6 @@ This rule aims to standardize the way modules are declared. If you are using the ES2015 module syntax, then you will not need this rule. -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-namespace-keyword": "error" - } -} -``` - -This rule is not configurable. - ## Further Reading - [Modules](https://www.typescriptlang.org/docs/handbook/modules.html) diff --git a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md index 730842c1512d..7f57df05a35d 100644 --- a/packages/eslint-plugin/docs/rules/prefer-optional-chain.md +++ b/packages/eslint-plugin/docs/rules/prefer-optional-chain.md @@ -85,19 +85,6 @@ foo?.a?.b?.c?.d?.e; **Note:** there are a few edge cases where this rule will false positive. Use your best judgement when evaluating reported errors. -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-optional-chain": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are not using TypeScript 3.7 (or greater), then you will not be able to use this rule, as the operator is not supported. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md index 022b4e841bc9..a68c8c5c48e4 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly-parameter-types.md @@ -127,19 +127,6 @@ interface Foo { ## Options -```ts -interface Options { - checkParameterProperties?: boolean; - ignoreInferredTypes?: boolean; -} - -const defaultOptions: Options = { - checkParameterProperties: true, - ignoreInferredTypes: false, - treatMethodsAsReadonly: false, -}; -``` - ### `checkParameterProperties` This option allows you to enable or disable the checking of parameter properties. diff --git a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md index 5db156aa47f2..4760f2c996a6 100644 --- a/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md +++ b/packages/eslint-plugin/docs/rules/prefer-reduce-type-parameter.md @@ -51,19 +51,6 @@ Examples of code for this rule: ); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-reduce-type-parameter": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't want to use typechecking in your linting, you can't use this rule. diff --git a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md index a487ea3d3e24..5a66ffe97c85 100644 --- a/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md +++ b/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md @@ -42,19 +42,6 @@ const search = /thing/; search.exec(text); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-regexp-exec": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you prefer consistent use of `String#match` for both, with `g` flag and without it, you can turn this rule off. diff --git a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md index 0581d81ad02b..e8d836a7c27f 100644 --- a/packages/eslint-plugin/docs/rules/prefer-return-this-type.md +++ b/packages/eslint-plugin/docs/rules/prefer-return-this-type.md @@ -93,19 +93,6 @@ class Derived extends Base { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-return-this-type": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't use method chaining or explicit return values, you can safely turn this rule off. diff --git a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md index 2be24df3c21b..af6176cccd6c 100644 --- a/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md +++ b/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md @@ -44,19 +44,6 @@ foo.startsWith('bar'); foo.endsWith('bar'); ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-string-starts-ends-with": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you don't mind that style, you can turn this rule off safely. diff --git a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md index bfcaad11b0ab..0919c1ae6a2c 100644 --- a/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md +++ b/packages/eslint-plugin/docs/rules/prefer-ts-expect-error.md @@ -62,19 +62,6 @@ const isOptionEnabled = (key: string): boolean => { }; ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/prefer-ts-expect-error": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If you are **NOT** using TypeScript 3.9 (or greater), then you will not be able to use this rule, as the directive is not supported diff --git a/packages/eslint-plugin/docs/rules/promise-function-async.md b/packages/eslint-plugin/docs/rules/promise-function-async.md index 424536ee5f24..e140a333ac10 100644 --- a/packages/eslint-plugin/docs/rules/promise-function-async.md +++ b/packages/eslint-plugin/docs/rules/promise-function-async.md @@ -36,32 +36,3 @@ async function functionReturnsPromise() { return Promise.resolve('value'); } ``` - -## Options - -Options may be provided as an object with: - -- `allowAny` to indicate that `any` or `unknown` shouldn't be considered Promises (`true` by default). -- `allowedPromiseNames` to indicate any extra names of classes or interfaces to be considered Promises when returned. - -In addition, each of the following properties may be provided, and default to `true`: - -- `checkArrowFunctions` -- `checkFunctionDeclarations` -- `checkFunctionExpressions` -- `checkMethodDeclarations` - -```json -{ - "@typescript-eslint/promise-function-async": [ - "error", - { - "allowedPromiseNames": ["Thenable"], - "checkArrowFunctions": true, - "checkFunctionDeclarations": true, - "checkFunctionExpressions": true, - "checkMethodDeclarations": true - } - ] -} -``` diff --git a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md index cfe2ef234a46..2509366385da 100644 --- a/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md +++ b/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md @@ -106,19 +106,6 @@ switch (day) { } ``` -## Options - -```jsonc -// .eslintrc.json -{ - "rules": { - "@typescript-eslint/switch-exhaustiveness-check": "warn" - } -} -``` - -This rule is not configurable. - ## When Not To Use It If program doesn't have union types with many parts. Downside of this rule is the need for type information, so it's slower than regular rules. diff --git a/packages/eslint-plugin/docs/rules/triple-slash-reference.md b/packages/eslint-plugin/docs/rules/triple-slash-reference.md index 4ff58fb083e6..ea082dfd5c33 100644 --- a/packages/eslint-plugin/docs/rules/triple-slash-reference.md +++ b/packages/eslint-plugin/docs/rules/triple-slash-reference.md @@ -2,9 +2,11 @@ > > See **https://typescript-eslint.io/rules/triple-slash-reference** for documentation. +## Rule Details + Use of triple-slash reference type directives is discouraged in favor of the newer `import` style. This rule allows you to ban use of `/// `, `/// `, or `/// ` directives. -## Rule Details +## Options With `{ "path": "never", "types": "never", "lib": "never" }` options set, the following will all be **incorrect** usage: @@ -44,8 +46,6 @@ import * as foo from 'foo'; import foo = require('foo'); ``` -## Options - ## When To Use It If you want to ban use of one or all of the triple slash reference directives, or any time you might use triple-slash type reference directives and ES6 import declarations in the same file. diff --git a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md index 7adc9fd0e59e..1ed509686cf7 100644 --- a/packages/eslint-plugin/docs/rules/type-annotation-spacing.md +++ b/packages/eslint-plugin/docs/rules/type-annotation-spacing.md @@ -37,21 +37,11 @@ This rule aims to enforce specific spacing patterns around type annotations and ## Options -This rule has an object option: - -- `"before": false`, (default for colon) disallows spaces before the colon/arrow. -- `"before": true`, (default for arrow) requires a space before the colon/arrow. -- `"after": true`, (default) requires a space after the colon/arrow. -- `"after": false`, disallows spaces after the colon/arrow. -- `"overrides"`, overrides the default options for type annotations with `colon` (e.g. `const foo: string`) and function types with `arrow` (e.g. `type Foo = () => {}`). Additionally allows granular overrides for `variable` (`const foo: string`),`parameter` (`function foo(bar: string) {...}`),`property` (`interface Foo { bar: string }`) and `returnType` (`function foo(): string {...}`) annotations. - -### defaults - Examples of code for this rule with no options at all: -#### ❌ Incorrect +### ❌ Incorrect ```ts @@ -80,7 +70,7 @@ type Foo = () =>{}; type Foo = ()=> {}; ``` -#### ✅ Correct +### ✅ Correct ```ts diff --git a/packages/eslint-plugin/docs/rules/unbound-method.md b/packages/eslint-plugin/docs/rules/unbound-method.md index 5ec384f35152..f25614281ed1 100644 --- a/packages/eslint-plugin/docs/rules/unbound-method.md +++ b/packages/eslint-plugin/docs/rules/unbound-method.md @@ -89,19 +89,6 @@ const { log } = OtherClass; log(); ``` -## Example - -```json -{ - "@typescript-eslint/unbound-method": [ - "error", - { - "ignoreStatic": true - } - ] -} -``` - ## When Not To Use It If your code intentionally waits to bind methods after use, such as by passing a `scope: this` along with the method, you can disable this rule. diff --git a/packages/eslint-plugin/docs/rules/unified-signatures.md b/packages/eslint-plugin/docs/rules/unified-signatures.md index d744012caa16..b57a8113c999 100644 --- a/packages/eslint-plugin/docs/rules/unified-signatures.md +++ b/packages/eslint-plugin/docs/rules/unified-signatures.md @@ -32,6 +32,10 @@ function x(x: number | string): void; function y(...x: number[]): void; ``` +## Options + +### `ignoreDifferentlyNamedParameters` + Examples of code for this rule with `ignoreDifferentlyNamedParameters`: diff --git a/packages/eslint-plugin/src/rules/no-this-alias.ts b/packages/eslint-plugin/src/rules/no-this-alias.ts index 5750b8209b11..9df6f8d0a01f 100644 --- a/packages/eslint-plugin/src/rules/no-this-alias.ts +++ b/packages/eslint-plugin/src/rules/no-this-alias.ts @@ -23,9 +23,13 @@ export default util.createRule({ 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;`.', type: 'array', items: { type: 'string', diff --git a/packages/eslint-plugin/src/rules/promise-function-async.ts b/packages/eslint-plugin/src/rules/promise-function-async.ts index b1ade7bf01b7..8f81a0f8b2a2 100644 --- a/packages/eslint-plugin/src/rules/promise-function-async.ts +++ b/packages/eslint-plugin/src/rules/promise-function-async.ts @@ -37,9 +37,13 @@ export default util.createRule({ type: 'object', 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.', type: 'array', items: { type: 'string', diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index e2ef920e501d..e8472665fa2d 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -14,7 +14,10 @@ import { EOL } from 'os'; * @remarks These need to be typed in manually in their .md docs file. * @todo Get these schemas printing nicely in their .md docs files! */ -const COMPLICATED_RULE_OPTIONS = new Set(['naming-convention']); +const COMPLICATED_RULE_OPTIONS = new Set([ + 'member-ordering', + 'naming-convention', +]); export const generatedRuleDocs: Plugin = () => { return async (root, file) => { @@ -254,8 +257,21 @@ export const generatedRuleDocs: Plugin = () => { children: [ { type: 'text', - value: - 'Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md).', + value: 'Taken with ❤️ ', + }, + { + children: [ + { + type: 'text', + value: 'from ESLint core', + }, + ], + type: 'link', + url: 'https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md', + }, + { + type: 'text', + value: '.', }, ], type: 'paragraph', From 8ac1a5b3c9119a35811ffef008b5987cbbe2cac0 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 00:38:50 -0400 Subject: [PATCH 20/26] Several more docs automations --- packages/eslint-plugin/docs/rules/no-namespace.md | 15 ++++----------- .../eslint-plugin/docs/rules/no-type-alias.md | 12 ------------ .../eslint-plugin/docs/rules/prefer-readonly.md | 2 -- packages/eslint-plugin/src/rules/no-namespace.ts | 4 ++++ packages/eslint-plugin/src/rules/no-type-alias.ts | 9 +++++++++ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-namespace.md b/packages/eslint-plugin/docs/rules/no-namespace.md index f59c865c5b7d..4c2779b210ba 100644 --- a/packages/eslint-plugin/docs/rules/no-namespace.md +++ b/packages/eslint-plugin/docs/rules/no-namespace.md @@ -11,16 +11,7 @@ This rule still allows the use of TypeScript module declarations to describe ext This rule aims to standardize the way modules are declared. -## Options - -This rule, in its default state, does not require any argument. If you would like to enable one -or more of the following you may pass an object with the options set as follows: - -- `allowDeclarations` set to `true` will allow you to `declare` custom TypeScript modules and namespaces (Default: `false`). -- `allowDefinitionFiles` set to `true` will allow you to `declare` and use custom TypeScript modules and namespaces - inside definition files (Default: `true`). - -Examples of code for the default `{ "allowDeclarations": false, "allowDefinitionFiles": true }` options: +Examples of code with the default options: @@ -44,9 +35,11 @@ declare module 'foo' {} +## Options + ### `allowDeclarations` -Examples of code for the `{ "allowDeclarations": true }` option: +Examples of code with the `{ "allowDeclarations": true }` option: diff --git a/packages/eslint-plugin/docs/rules/no-type-alias.md b/packages/eslint-plugin/docs/rules/no-type-alias.md index e2b95b917382..a327f1e92887 100644 --- a/packages/eslint-plugin/docs/rules/no-type-alias.md +++ b/packages/eslint-plugin/docs/rules/no-type-alias.md @@ -81,18 +81,6 @@ and simplified types (primitives, tuples, unions, intersections, etc). ## Options -This rule, in its default state, does not require any argument. If you would like to enable one -or more of the following you may pass an object with the options set as follows: - -- `allowAliases` set to `"always"` will allow you to do aliasing (Defaults to `"never"`). -- `allowCallbacks` set to `"always"` will allow you to use type aliases with callbacks (Defaults to `"never"`) -- `allowConditionalTypes` set to `"always"` will allow you to use type aliases with conditional types (Defaults to `"never"`) -- `allowConstructors` set to `"always"` will allow you to use type aliases with constructors (Defaults to `"never"`) -- `allowLiterals` set to `"always"` will allow you to use type aliases with literal objects (Defaults to `"never"`) -- `allowMappedTypes` set to `"always"` will allow you to use type aliases as mapping tools (Defaults to `"never"`) -- `allowTupleTypes` set to `"always"` will allow you to use type aliases with tuples (Defaults to `"never"`) -- `allowGenerics` set to `"always"` will allow you to use type aliases with generics (Defaults to `"never"`) - ### `allowAliases` This applies to primitive types and reference types. diff --git a/packages/eslint-plugin/docs/rules/prefer-readonly.md b/packages/eslint-plugin/docs/rules/prefer-readonly.md index e21f26a278ba..5ddf81ee43fd 100644 --- a/packages/eslint-plugin/docs/rules/prefer-readonly.md +++ b/packages/eslint-plugin/docs/rules/prefer-readonly.md @@ -52,8 +52,6 @@ class Container { ## Options -This rule, in its default state, does not require any argument. - ### `onlyInlineLambdas` You may pass `"onlyInlineLambdas": true` as a rule option within an object to restrict checking only to members immediately assigned a lambda value. diff --git a/packages/eslint-plugin/src/rules/no-namespace.ts b/packages/eslint-plugin/src/rules/no-namespace.ts index 2a840fda3143..ac306e6b299c 100644 --- a/packages/eslint-plugin/src/rules/no-namespace.ts +++ b/packages/eslint-plugin/src/rules/no-namespace.ts @@ -26,9 +26,13 @@ export default util.createRule({ type: 'object', 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', }, }, diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index ba656ea4124a..69742eb61032 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -60,27 +60,36 @@ export default util.createRule({ type: 'object', properties: { allowAliases: { + description: 'Whether to allow direct one-to-one type aliases.', enum: enumValues, }, allowCallbacks: { + description: 'Whether to allow type aliases for callbacks.', enum: ['always', 'never'], }, allowConditionalTypes: { + description: 'Whether to allow type aliases for conditional types.', enum: ['always', 'never'], }, allowConstructors: { + description: 'Whether to allow type aliases with constructors.', enum: ['always', 'never'], }, allowLiterals: { + description: + 'Whether to allow type aliases with object literal types.', enum: enumValues, }, allowMappedTypes: { + description: 'Whether to allow type aliases with mapped types.', enum: enumValues, }, allowTupleTypes: { + description: 'Whether to allow type aliases with tuple types.', enum: enumValues, }, allowGenerics: { + description: 'Whether to allow type aliases with generic types.', enum: ['always', 'never'], }, }, From ba912c3d25fb5f57f9bdb989b182f5322066201a Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 00:59:07 -0400 Subject: [PATCH 21/26] Fixed options index --- .../src/rules/parameter-properties.ts | 23 +++++++++++-------- .../website/plugins/generated-rule-docs.ts | 4 +++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/src/rules/parameter-properties.ts b/packages/eslint-plugin/src/rules/parameter-properties.ts index 58d834088977..a2f6fcb8009f 100644 --- a/packages/eslint-plugin/src/rules/parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/parameter-properties.ts @@ -38,20 +38,25 @@ export default util.createRule({ }, schema: [ { + definitions: { + modifier: { + enum: [ + 'readonly', + 'private', + 'protected', + 'public', + 'private readonly', + 'protected readonly', + 'public readonly', + ], + }, + }, type: 'object', properties: { allow: { type: 'array', items: { - enum: [ - 'readonly', - 'private', - 'protected', - 'public', - 'private readonly', - 'protected readonly', - 'public readonly', - ], + $ref: '#/definitions/modifier', }, minItems: 1, }, diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index e8472665fa2d..adc78c2f1c41 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -117,7 +117,7 @@ export const generatedRuleDocs: Plugin = () => { optionsH2Index = whenNotToUseItH2Index === -1 ? parent.children.length - : ++whenNotToUseItH2Index; + : whenNotToUseItH2Index++; parent.children.splice(optionsH2Index, 0, { children: [ { @@ -128,6 +128,8 @@ export const generatedRuleDocs: Plugin = () => { depth: 2, type: 'heading', } as mdast.Heading); + + optionsH2Index += 1; } return [howToUseH2Index, optionsH2Index]; From 26f7a69fa39ed7ecb1ba57b8ccd1d2ffe3392c99 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 01:02:41 -0400 Subject: [PATCH 22/26] Also above Related To --- .../docs/rules/no-unnecessary-type-assertion.md | 4 ++-- .../src/rules/no-unnecessary-type-assertion.ts | 1 + packages/website/plugins/generated-rule-docs.ts | 10 +++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md index b8e91cf74c49..b28eabf30d5d 100644 --- a/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md +++ b/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md @@ -61,9 +61,9 @@ function foo(x: number | undefined): number { ## Options -This rule optionally takes an object with a single property `typesToIgnore`, which can be set to a list of type names to ignore. +### `typesToIgnore` -For example, with `@typescript-eslint/no-unnecessary-type-assertion: ["error", { typesToIgnore: ['Foo'] }]`, the following is **correct** code": +With `@typescript-eslint/no-unnecessary-type-assertion: ["error", { typesToIgnore: ['Foo'] }]`, the following is **correct** code": ```ts type Foo = 3; diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index d9ef180abd5f..59e257b9e0bf 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -37,6 +37,7 @@ export default util.createRule({ type: 'object', properties: { typesToIgnore: { + description: 'A list of type names to ignore.', type: 'array', items: { type: 'string', diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index adc78c2f1c41..44835680a8c8 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -79,7 +79,9 @@ export const generatedRuleDocs: Plugin = () => { let optionsH2Index = parent.children.findIndex( createH2TextFilter('Options'), ); - + let relatedToH2Index = parent.children.findIndex( + createH2TextFilter('Related To'), + ); let whenNotToUseItH2Index = parent.children.findIndex( createH2TextFilter('When Not To Use It'), ); @@ -116,8 +118,10 @@ export const generatedRuleDocs: Plugin = () => { if (optionsH2Index === -1) { optionsH2Index = whenNotToUseItH2Index === -1 - ? parent.children.length - : whenNotToUseItH2Index++; + ? relatedToH2Index === -1 + ? parent.children.length + : relatedToH2Index + : whenNotToUseItH2Index; parent.children.splice(optionsH2Index, 0, { children: [ { From 50078b7e57e8662984d55ee4638ce1d3f958cc45 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 01:05:39 -0400 Subject: [PATCH 23/26] Aha, jsx working --- packages/website/plugins/generated-rule-docs.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/website/plugins/generated-rule-docs.ts b/packages/website/plugins/generated-rule-docs.ts index 44835680a8c8..29906807c038 100644 --- a/packages/website/plugins/generated-rule-docs.ts +++ b/packages/website/plugins/generated-rule-docs.ts @@ -79,7 +79,7 @@ export const generatedRuleDocs: Plugin = () => { let optionsH2Index = parent.children.findIndex( createH2TextFilter('Options'), ); - let relatedToH2Index = parent.children.findIndex( + const relatedToH2Index = parent.children.findIndex( createH2TextFilter('Related To'), ); let whenNotToUseItH2Index = parent.children.findIndex( @@ -261,23 +261,28 @@ export const generatedRuleDocs: Plugin = () => { if (meta.docs.extendsBaseRule) { parent.children.push({ children: [ + { + type: 'jsx', + value: '', + }, { type: 'text', value: 'Taken with ❤️ ', }, { + type: 'link', + title: null, + url: `https://github.com/eslint/eslint/blob/main/docs/rules/${file.stem}.md`, children: [ { type: 'text', value: 'from ESLint core', }, ], - type: 'link', - url: 'https://github.com/eslint/eslint/blob/main/docs/rules/require-await.md', }, { - type: 'text', - value: '.', + type: 'jsx', + value: '', }, ], type: 'paragraph', From b0910d48738125493530e00a6a0d1557a23450fe Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 1 Aug 2022 08:56:22 -0400 Subject: [PATCH 24/26] Thanks lint - correct no-inferrable-types headings --- packages/eslint-plugin/docs/rules/no-inferrable-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-inferrable-types.md b/packages/eslint-plugin/docs/rules/no-inferrable-types.md index 7989933af0d9..26928ebe5376 100644 --- a/packages/eslint-plugin/docs/rules/no-inferrable-types.md +++ b/packages/eslint-plugin/docs/rules/no-inferrable-types.md @@ -13,7 +13,7 @@ Examples of code with the default options: -#### ❌ Incorrect +### ❌ Incorrect ```ts const a: bigint = 10n; @@ -54,7 +54,7 @@ class Foo { function fn(a: number = 5, b: boolean = true) {} ``` -#### ✅ Correct +### ✅ Correct ```ts const a = 10n; From 2bcade680f7c9f1a2895bbd037d2e9a6ce7c8c22 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 7 Aug 2022 09:40:04 -0400 Subject: [PATCH 25/26] Update packages/eslint-plugin/src/rules/no-implicit-any-catch.ts Co-authored-by: Brad Zacher --- packages/eslint-plugin/src/rules/no-implicit-any-catch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts b/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts index e6d4255dd854..3f26fefb98dc 100644 --- a/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts +++ b/packages/eslint-plugin/src/rules/no-implicit-any-catch.ts @@ -36,7 +36,7 @@ export default util.createRule({ properties: { allowExplicitAny: { description: - 'Whehter to disallow specifying `: any` as the error type as well. See also `no-explicit-any`.', + 'Whether to disallow specifying `: any` as the error type as well. See also `no-explicit-any`.', type: 'boolean', }, }, From 071901059eb3fc8c16792264dfd34f4c1a98fdd9 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 7 Aug 2022 09:41:53 -0400 Subject: [PATCH 26/26] Fix explicit-function-return-type --- .../eslint-plugin/docs/rules/explicit-function-return-type.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md index 00389fc3f48b..a80dd7100f21 100644 --- a/packages/eslint-plugin/docs/rules/explicit-function-return-type.md +++ b/packages/eslint-plugin/docs/rules/explicit-function-return-type.md @@ -61,6 +61,8 @@ class Test { } ``` +## Options + ### Configuring in a mixed JS/TS codebase If you are working on a codebase within which you lint non-TypeScript code (i.e. `.js`/`.mjs`/`.cjs`/`.jsx`), you should ensure that you should use [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files) to only enable the rule on `.ts`/`.mts`/`.cts`/`.tsx` files. If you don't, then you will get unfixable lint errors reported within `.js`/`.mjs`/`.cjs`/`.jsx` files.