diff --git a/packages/typescript-eslint/src/configs/all.ts b/packages/typescript-eslint/src/configs/all.ts index bbb13efe5df7..7a7b91aa92c7 100644 --- a/packages/typescript-eslint/src/configs/all.ts +++ b/packages/typescript-eslint/src/configs/all.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Enables each the rules provided as a part of typescript-eslint. Note that many rules are not applicable in all codebases, or are meant to be configured. + * @see {@link https://typescript-eslint.io/users/configs#all} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/base.ts b/packages/typescript-eslint/src/configs/base.ts index 30960f7b689c..6ad1eaa62b83 100644 --- a/packages/typescript-eslint/src/configs/base.ts +++ b/packages/typescript-eslint/src/configs/base.ts @@ -1,5 +1,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; +/** + * A minimal ruleset that sets only the required parser and plugin options needed to run typescript-eslint. + * We don't recommend using this directly; instead, extend from an earlier recommended rule. + * @see {@link https://typescript-eslint.io/users/configs#base} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/disable-type-checked.ts b/packages/typescript-eslint/src/configs/disable-type-checked.ts index 3d4ba4d97073..b9314ba78bc7 100644 --- a/packages/typescript-eslint/src/configs/disable-type-checked.ts +++ b/packages/typescript-eslint/src/configs/disable-type-checked.ts @@ -7,6 +7,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; +/** + * A utility ruleset that will disable type-aware linting and all type-aware rules available in our project. + * @see {@link https://typescript-eslint.io/users/configs#disable-type-checked} + */ export default ( _plugin: FlatConfig.Plugin, _parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/eslint-recommended.ts b/packages/typescript-eslint/src/configs/eslint-recommended.ts index 71431c296754..393ea051a6e0 100644 --- a/packages/typescript-eslint/src/configs/eslint-recommended.ts +++ b/packages/typescript-eslint/src/configs/eslint-recommended.ts @@ -5,6 +5,7 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; * This is a compatibility ruleset that: * - disables rules from eslint:recommended which are already handled by TypeScript. * - enables rules that make sense due to TS's typechecking / transpilation. + * @see {@link https://typescript-eslint.io/users/configs/#eslint-recommended} */ export default ( _plugin: FlatConfig.Plugin, diff --git a/packages/typescript-eslint/src/configs/recommended-type-checked-only.ts b/packages/typescript-eslint/src/configs/recommended-type-checked-only.ts index eab5d2487ee5..0e417f24e0a5 100644 --- a/packages/typescript-eslint/src/configs/recommended-type-checked-only.ts +++ b/packages/typescript-eslint/src/configs/recommended-type-checked-only.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * A version of `recommended` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#recommended-type-checked-only} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/recommended-type-checked.ts b/packages/typescript-eslint/src/configs/recommended-type-checked.ts index 993f7baa90ed..bb46e4cb4238 100644 --- a/packages/typescript-eslint/src/configs/recommended-type-checked.ts +++ b/packages/typescript-eslint/src/configs/recommended-type-checked.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Contains all of `recommended` along with additional recommended rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#recommended-type-checked} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/recommended.ts b/packages/typescript-eslint/src/configs/recommended.ts index 1e6be3251a08..f94d6606637d 100644 --- a/packages/typescript-eslint/src/configs/recommended.ts +++ b/packages/typescript-eslint/src/configs/recommended.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Recommended rules for code correctness that you can drop in without additional configuration. + * @see {@link https://typescript-eslint.io/users/configs#recommended} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/strict-type-checked-only.ts b/packages/typescript-eslint/src/configs/strict-type-checked-only.ts index d9e537868886..639b6a3164dd 100644 --- a/packages/typescript-eslint/src/configs/strict-type-checked-only.ts +++ b/packages/typescript-eslint/src/configs/strict-type-checked-only.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * A version of `strict` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#strict-type-checked-only} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/strict-type-checked.ts b/packages/typescript-eslint/src/configs/strict-type-checked.ts index 1e3ea1f54857..37d25c7c7922 100644 --- a/packages/typescript-eslint/src/configs/strict-type-checked.ts +++ b/packages/typescript-eslint/src/configs/strict-type-checked.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Contains all of `recommended`, `recommended-type-checked`, and `strict`, along with additional strict rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#strict-type-checked} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/strict.ts b/packages/typescript-eslint/src/configs/strict.ts index d6c5a37e9c54..0afa85b9f088 100644 --- a/packages/typescript-eslint/src/configs/strict.ts +++ b/packages/typescript-eslint/src/configs/strict.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Contains all of `recommended`, as well as additional strict rules that can also catch bugs. + * @see {@link https://typescript-eslint.io/users/configs#strict} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/stylistic-type-checked-only.ts b/packages/typescript-eslint/src/configs/stylistic-type-checked-only.ts index 39354a3cc759..2c132123f0ba 100644 --- a/packages/typescript-eslint/src/configs/stylistic-type-checked-only.ts +++ b/packages/typescript-eslint/src/configs/stylistic-type-checked-only.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * A version of `stylistic` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#stylistic-type-checked-only} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/stylistic-type-checked.ts b/packages/typescript-eslint/src/configs/stylistic-type-checked.ts index f1c1efaf2e10..22113f880802 100644 --- a/packages/typescript-eslint/src/configs/stylistic-type-checked.ts +++ b/packages/typescript-eslint/src/configs/stylistic-type-checked.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Contains all of `stylistic`, along with additional stylistic rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#stylistic-type-checked} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/configs/stylistic.ts b/packages/typescript-eslint/src/configs/stylistic.ts index cd165bf5bdac..26771ce80895 100644 --- a/packages/typescript-eslint/src/configs/stylistic.ts +++ b/packages/typescript-eslint/src/configs/stylistic.ts @@ -10,6 +10,10 @@ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'; import baseConfig from './base'; import eslintRecommendedConfig from './eslint-recommended'; +/** + * Rules considered to be best practice for modern TypeScript codebases, but that do not impact program logic. + * @see {@link https://typescript-eslint.io/users/configs#stylistic} + */ export default ( plugin: FlatConfig.Plugin, parser: FlatConfig.Parser, diff --git a/packages/typescript-eslint/src/index.ts b/packages/typescript-eslint/src/index.ts index 4786357f095a..1844a4eba1f1 100644 --- a/packages/typescript-eslint/src/index.ts +++ b/packages/typescript-eslint/src/index.ts @@ -53,18 +53,85 @@ const plugin: TSESLint.FlatConfig.Plugin = pluginBase as Omit< >; const configs = { + /** + * Enables each the rules provided as a part of typescript-eslint. Note that many rules are not applicable in all codebases, or are meant to be configured. + * @see {@link https://typescript-eslint.io/users/configs#all} + */ all: allConfig(plugin, parser), + + /** + * A minimal ruleset that sets only the required parser and plugin options needed to run typescript-eslint. + * We don't recommend using this directly; instead, extend from an earlier recommended rule. + * @see {@link https://typescript-eslint.io/users/configs#base} + */ base: baseConfig(plugin, parser), + + /** + * A utility ruleset that will disable type-aware linting and all type-aware rules available in our project. + * @see {@link https://typescript-eslint.io/users/configs#disable-type-checked} + */ disableTypeChecked: disableTypeCheckedConfig(plugin, parser), + + /** + * This is a compatibility ruleset that: + * - disables rules from eslint:recommended which are already handled by TypeScript. + * - enables rules that make sense due to TS's typechecking / transpilation. + * @see {@link https://typescript-eslint.io/users/configs/#eslint-recommended} + */ eslintRecommended: eslintRecommendedConfig(plugin, parser), + + /** + * Recommended rules for code correctness that you can drop in without additional configuration. + * @see {@link https://typescript-eslint.io/users/configs#recommended} + */ recommended: recommendedConfig(plugin, parser), + + /** + * Contains all of `recommended` along with additional recommended rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#recommended-type-checked} + */ recommendedTypeChecked: recommendedTypeCheckedConfig(plugin, parser), + + /** + * A version of `recommended` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#recommended-type-checked-only} + */ recommendedTypeCheckedOnly: recommendedTypeCheckedOnlyConfig(plugin, parser), + + /** + * Contains all of `recommended`, as well as additional strict rules that can also catch bugs. + * @see {@link https://typescript-eslint.io/users/configs#strict} + */ strict: strictConfig(plugin, parser), + + /** + * Contains all of `recommended`, `recommended-type-checked`, and `strict`, along with additional strict rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#strict-type-checked} + */ strictTypeChecked: strictTypeCheckedConfig(plugin, parser), + + /** + * A version of `strict` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#strict-type-checked-only} + */ strictTypeCheckedOnly: strictTypeCheckedOnlyConfig(plugin, parser), + + /** + * Rules considered to be best practice for modern TypeScript codebases, but that do not impact program logic. + * @see {@link https://typescript-eslint.io/users/configs#stylistic} + */ stylistic: stylisticConfig(plugin, parser), + + /** + * Contains all of `stylistic`, along with additional stylistic rules that require type information. + * @see {@link https://typescript-eslint.io/users/configs#stylistic-type-checked} + */ stylisticTypeChecked: stylisticTypeCheckedConfig(plugin, parser), + + /** + * A version of `stylistic` that only contains type-checked rules and disables of any corresponding core ESLint rules. + * @see {@link https://typescript-eslint.io/users/configs#stylistic-type-checked-only} + */ stylisticTypeCheckedOnly: stylisticTypeCheckedOnlyConfig(plugin, parser), }; diff --git a/tools/scripts/generate-configs.mts b/tools/scripts/generate-configs.mts index e11896bd47ff..cc105624be3b 100644 --- a/tools/scripts/generate-configs.mts +++ b/tools/scripts/generate-configs.mts @@ -169,13 +169,20 @@ async function main(): Promise { return config; } + interface WriteConfigSettings { + getConfig: () => LinterConfig; + name: string; + description: string; + } + /** - * Helper function writes configuration. + * Helper function that writes configuration. */ - async function writeConfig( - getConfig: () => LinterConfig, - name: string, - ): Promise { + async function writeConfig({ + description, + getConfig, + name, + }: WriteConfigSettings): Promise { const hyphens = '-'.repeat(35 - Math.ceil(name.length / 2)); console.log(chalk.blueBright(`\n${hyphens} ${name}.ts ${hyphens}`)); @@ -238,9 +245,14 @@ async function main(): Promise { flatConfig.languageOptions.parserOptions = config.parserOptions; } + const docComment = `/** + * ${description} + * @see {@link https://typescript-eslint.io/users/configs#${name}} + */`; const flatConfigJson = JSON.stringify(flatConfig); if (flatExtends.length > 0) { flatCode.push( + docComment, 'export default (plugin: FlatConfig.Plugin, parser: FlatConfig.Parser): FlatConfig.ConfigArray => [', ...flatExtends.map(ext => `${ext}(plugin, parser),`), flatConfigJson, @@ -248,6 +260,7 @@ async function main(): Promise { ); } else { flatCode.push( + docComment, `export default (_plugin: FlatConfig.Plugin, _parser: FlatConfig.Parser): FlatConfig.Config => (${flatConfigJson});`, ); } @@ -262,18 +275,21 @@ async function main(): Promise { } interface ExtendedConfigSettings { + description: string; name: string; ruleEntries: readonly RuleEntry[]; settings?: ConfigRuleSettings; } async function writeExtendedConfig({ + description, name, ruleEntries, settings, }: ExtendedConfigSettings): Promise { - await writeConfig( - () => ({ + await writeConfig({ + description, + getConfig: () => ({ extends: [...CLASSIC_EXTENDS], rules: ruleEntries.reduce( (config, entry) => reducer(config, entry, settings), @@ -281,7 +297,7 @@ async function main(): Promise { ), }), name, - ); + }); } function filterRuleEntriesTo( @@ -306,6 +322,8 @@ async function main(): Promise { } await writeExtendedConfig({ + description: + 'Enables each the rules provided as a part of typescript-eslint. Note that many rules are not applicable in all codebases, or are meant to be configured.', name: 'all', settings: { deprecated: 'exclude', @@ -314,6 +332,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Recommended rules for code correctness that you can drop in without additional configuration.', settings: { getOptions: createGetOptionsForLevel('recommended'), typeChecked: 'exclude', @@ -323,6 +343,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Contains all of `recommended` along with additional recommended rules that require type information.', name: 'recommended-type-checked', ruleEntries: filterRuleEntriesTo('recommended'), settings: { @@ -331,6 +353,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'A version of `recommended` that only contains type-checked rules and disables of any corresponding core ESLint rules.', settings: { getOptions: createGetOptionsForLevel('recommended'), typeChecked: 'include-only', @@ -340,6 +364,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Contains all of `recommended`, as well as additional strict rules that can also catch bugs. ', settings: { getOptions: createGetOptionsForLevel('strict'), typeChecked: 'exclude', @@ -349,6 +375,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Contains all of `recommended`, `recommended-type-checked`, and `strict`, along with additional strict rules that require type information.', settings: { getOptions: createGetOptionsForLevel('strict'), }, @@ -357,6 +385,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'A version of `strict` that only contains type-checked rules and disables of any corresponding core ESLint rules.', settings: { getOptions: createGetOptionsForLevel('strict'), typeChecked: 'include-only', @@ -366,6 +396,8 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Rules considered to be best practice for modern TypeScript codebases, but that do not impact program logic.', settings: { typeChecked: 'exclude', }, @@ -374,11 +406,15 @@ async function main(): Promise { }); await writeExtendedConfig({ + description: + 'Contains all of `stylistic`, along with additional stylistic rules that require type information.', name: 'stylistic-type-checked', ruleEntries: filterRuleEntriesTo('stylistic'), }); await writeExtendedConfig({ + description: + 'A version of `stylistic` that only contains type-checked rules and disables of any corresponding core ESLint rules.', settings: { typeChecked: 'include-only', }, @@ -386,8 +422,10 @@ async function main(): Promise { ruleEntries: filterRuleEntriesTo('stylistic'), }); - await writeConfig( - () => ({ + await writeConfig({ + description: + 'A utility ruleset that will disable type-aware linting and all type-aware rules available in our project.', + getConfig: () => ({ parserOptions: { project: false, program: null, @@ -403,8 +441,8 @@ async function main(): Promise { {}, ), }), - 'disable-type-checked', - ); + name: 'disable-type-checked', + }); } main().catch((error: unknown) => { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy