From 70a056afe1b0e3057085da2c9681b373dc81687c Mon Sep 17 00:00:00 2001 From: "david.marinho@codacy.com" Date: Wed, 15 Jan 2025 15:43:34 +0000 Subject: [PATCH 01/16] add-deprecated-rules --- ...ular-eslint_prefer-standalone-component.md | 298 ++++ ...ar-eslint_sort-ngmodule-metadata-arrays.md | 607 +++++++ .../@lwc_lwc_no-dupe-class-members.md | 45 + .../@typescript-eslint_block-spacing.md | 10 + .../@typescript-eslint_brace-style.md | 10 + .../@typescript-eslint_comma-dangle.md | 20 + .../@typescript-eslint_comma-spacing.md | 10 + .../@typescript-eslint_func-call-spacing.md | 10 + docs/description/@typescript-eslint_indent.md | 18 + .../@typescript-eslint_key-spacing.md | 10 + .../@typescript-eslint_keyword-spacing.md | 10 + ...@typescript-eslint_lines-around-comment.md | 25 + ...ript-eslint_lines-between-class-members.md | 53 + ...ypescript-eslint_member-delimiter-style.md | 166 ++ .../@typescript-eslint_no-extra-parens.md | 10 + .../@typescript-eslint_no-extra-semi.md | 12 + .../@typescript-eslint_no-throw-literal.md | 22 + .../@typescript-eslint_no-type-alias.md | 623 +++++++ ...ipt-eslint_no-useless-template-literals.md | 57 + ...@typescript-eslint_object-curly-spacing.md | 10 + ...-eslint_padding-line-between-statements.md | 33 + ...ypescript-eslint_prefer-ts-expect-error.md | 72 + docs/description/@typescript-eslint_quotes.md | 10 + docs/description/@typescript-eslint_semi.md | 12 + ...ypescript-eslint_sort-type-constituents.md | 202 +++ .../@typescript-eslint_space-before-blocks.md | 45 + ...ript-eslint_space-before-function-paren.md | 10 + .../@typescript-eslint_space-infix-ops.md | 16 + ...pescript-eslint_type-annotation-spacing.md | 327 ++++ docs/description/array-bracket-newline.md | 331 ++++ docs/description/array-bracket-spacing.md | 266 +++ docs/description/array-element-newline.md | 449 +++++ docs/description/arrow-parens.md | 254 +++ docs/description/arrow-spacing.md | 122 ++ docs/description/block-spacing.md | 99 ++ docs/description/brace-style.md | 431 +++++ docs/description/callback-return.md | 191 ++ docs/description/comma-dangle.md | 368 ++++ docs/description/comma-spacing.md | 162 ++ docs/description/comma-style.md | 191 ++ docs/description/computed-property-spacing.md | 210 +++ docs/description/description.json | 1428 ++++++++++++++- docs/description/dot-location.md | 104 ++ docs/description/eol-last.md | 60 + docs/description/func-call-spacing.md | 132 ++ .../function-call-argument-newline.md | 226 +++ docs/description/function-paren-newline.md | 385 ++++ .../functional_prefer-readonly-type.md | 228 +++ docs/description/generator-star-spacing.md | 234 +++ docs/description/global-require.md | 110 ++ docs/description/handle-callback-err.md | 97 ++ docs/description/id-blacklist.md | 7 + docs/description/implicit-arrow-linebreak.md | 119 ++ docs/description/import_imports-first.md | 9 + docs/description/indent-legacy.md | 676 +++++++ docs/description/indent.md | 1082 ++++++++++++ docs/description/jsx-a11y_accessible-emoji.md | 30 + docs/description/jsx-a11y_label-has-for.md | 130 ++ docs/description/jsx-a11y_no-onchange.md | 36 + docs/description/jsx-quotes.md | 92 + docs/description/key-spacing.md | 415 +++++ docs/description/keyword-spacing.md | 323 ++++ docs/description/linebreak-style.md | 106 ++ docs/description/lines-around-comment.md | 752 ++++++++ docs/description/lines-around-directive.md | 412 +++++ .../lines-between-class-members.md | 349 ++++ docs/description/max-len.md | 219 +++ docs/description/max-statements-per-line.md | 106 ++ docs/description/multiline-ternary.md | 197 +++ docs/description/n_no-hide-core-modules.md | 69 + docs/description/n_shebang.md | 19 + docs/description/new-parens.md | 80 + docs/description/newline-after-var.md | 163 ++ docs/description/newline-before-return.md | 127 ++ docs/description/newline-per-chained-call.md | 131 ++ docs/description/no-buffer-constructor.md | 57 + docs/description/no-catch-shadow.md | 85 + docs/description/no-confusing-arrow.md | 112 ++ docs/description/no-extra-parens.md | 432 +++++ docs/description/no-extra-semi.md | 81 + docs/description/no-floating-decimal.md | 56 + docs/description/no-mixed-operators.md | 219 +++ docs/description/no-mixed-requires.md | 150 ++ docs/description/no-mixed-spaces-and-tabs.md | 79 + docs/description/no-multi-spaces.md | 214 +++ docs/description/no-multiple-empty-lines.md | 158 ++ docs/description/no-native-reassign.md | 117 ++ docs/description/no-negated-in-lhs.md | 51 + docs/description/no-new-object.md | 68 + docs/description/no-new-require.md | 60 + docs/description/no-path-concat.md | 64 + docs/description/no-process-env.md | 50 + docs/description/no-process-exit.md | 62 + docs/description/no-restricted-modules.md | 133 ++ docs/description/no-return-await.md | 72 + docs/description/no-spaced-func.md | 41 + docs/description/no-sync.md | 81 + docs/description/no-tabs.md | 88 + docs/description/no-trailing-spaces.md | 85 + .../no-whitespace-before-property.md | 80 + .../nonblock-statement-body-position.md | 185 ++ docs/description/object-curly-newline.md | 606 +++++++ docs/description/object-curly-spacing.md | 191 ++ docs/description/object-property-newline.md | 285 +++ .../one-var-declaration-per-line.md | 108 ++ docs/description/operator-linebreak.md | 383 ++++ docs/description/padded-blocks.md | 555 ++++++ .../padding-line-between-statements.md | 331 ++++ docs/description/prefer-reflect.md | 414 +++++ docs/description/quote-props.md | 319 ++++ docs/description/quotes.md | 207 +++ .../react-perf_jsx-no-new-array-as-prop.md | 2 +- .../react_jsx-sort-default-props.md | 189 ++ .../react_jsx-space-before-closing.md | 59 + docs/description/require-jsdoc.md | 199 +++ docs/description/rest-spread-spacing.md | 159 ++ docs/description/rxjs_no-tap.md | 7 + docs/description/semi-spacing.md | 128 ++ docs/description/semi-style.md | 143 ++ docs/description/semi.md | 274 +++ docs/description/space-before-blocks.md | 262 +++ .../space-before-function-paren.md | 410 +++++ docs/description/space-in-parens.md | 383 ++++ docs/description/space-infix-ops.md | 92 + docs/description/space-unary-ops.md | 177 ++ docs/description/spaced-comment.md | 389 +++++ docs/description/switch-colon-spacing.md | 100 ++ docs/description/template-curly-spacing.md | 103 ++ docs/description/template-tag-spacing.md | 93 + docs/description/valid-jsdoc.md | 438 +++++ .../vue-scoped-css_require-scoped.md | 75 + docs/description/vue_component-tags-order.md | 201 +++ docs/description/vue_no-invalid-model-keys.md | 121 ++ .../vue_no-ref-object-destructure.md | 61 + .../vue_no-setup-props-destructure.md | 108 ++ .../description/vue_script-setup-uses-vars.md | 79 + docs/description/vue_v-on-function-call.md | 110 ++ .../vuejs-accessibility_no-onchange.md | 38 + docs/description/wrap-iife.md | 145 ++ docs/description/wrap-regex.md | 46 + docs/description/yield-star-spacing.md | 113 ++ .../all-patterns-typescript/patterns.xml | 160 ++ docs/multiple-tests/all-patterns/patterns.xml | 160 ++ docs/patterns.json | 1547 ++++++++++++++++- src/docGenerator.ts | 2 - 145 files changed, 27259 insertions(+), 73 deletions(-) create mode 100644 docs/description/@angular-eslint_prefer-standalone-component.md create mode 100644 docs/description/@angular-eslint_sort-ngmodule-metadata-arrays.md create mode 100644 docs/description/@lwc_lwc_no-dupe-class-members.md create mode 100644 docs/description/@typescript-eslint_block-spacing.md create mode 100644 docs/description/@typescript-eslint_brace-style.md create mode 100644 docs/description/@typescript-eslint_comma-dangle.md create mode 100644 docs/description/@typescript-eslint_comma-spacing.md create mode 100644 docs/description/@typescript-eslint_func-call-spacing.md create mode 100644 docs/description/@typescript-eslint_indent.md create mode 100644 docs/description/@typescript-eslint_key-spacing.md create mode 100644 docs/description/@typescript-eslint_keyword-spacing.md create mode 100644 docs/description/@typescript-eslint_lines-around-comment.md create mode 100644 docs/description/@typescript-eslint_lines-between-class-members.md create mode 100644 docs/description/@typescript-eslint_member-delimiter-style.md create mode 100644 docs/description/@typescript-eslint_no-extra-parens.md create mode 100644 docs/description/@typescript-eslint_no-extra-semi.md create mode 100644 docs/description/@typescript-eslint_no-throw-literal.md create mode 100644 docs/description/@typescript-eslint_no-type-alias.md create mode 100644 docs/description/@typescript-eslint_no-useless-template-literals.md create mode 100644 docs/description/@typescript-eslint_object-curly-spacing.md create mode 100644 docs/description/@typescript-eslint_padding-line-between-statements.md create mode 100644 docs/description/@typescript-eslint_prefer-ts-expect-error.md create mode 100644 docs/description/@typescript-eslint_quotes.md create mode 100644 docs/description/@typescript-eslint_semi.md create mode 100644 docs/description/@typescript-eslint_sort-type-constituents.md create mode 100644 docs/description/@typescript-eslint_space-before-blocks.md create mode 100644 docs/description/@typescript-eslint_space-before-function-paren.md create mode 100644 docs/description/@typescript-eslint_space-infix-ops.md create mode 100644 docs/description/@typescript-eslint_type-annotation-spacing.md create mode 100644 docs/description/array-bracket-newline.md create mode 100644 docs/description/array-bracket-spacing.md create mode 100644 docs/description/array-element-newline.md create mode 100644 docs/description/arrow-parens.md create mode 100644 docs/description/arrow-spacing.md create mode 100644 docs/description/block-spacing.md create mode 100644 docs/description/brace-style.md create mode 100644 docs/description/callback-return.md create mode 100644 docs/description/comma-dangle.md create mode 100644 docs/description/comma-spacing.md create mode 100644 docs/description/comma-style.md create mode 100644 docs/description/computed-property-spacing.md create mode 100644 docs/description/dot-location.md create mode 100644 docs/description/eol-last.md create mode 100644 docs/description/func-call-spacing.md create mode 100644 docs/description/function-call-argument-newline.md create mode 100644 docs/description/function-paren-newline.md create mode 100644 docs/description/functional_prefer-readonly-type.md create mode 100644 docs/description/generator-star-spacing.md create mode 100644 docs/description/global-require.md create mode 100644 docs/description/handle-callback-err.md create mode 100644 docs/description/id-blacklist.md create mode 100644 docs/description/implicit-arrow-linebreak.md create mode 100644 docs/description/import_imports-first.md create mode 100644 docs/description/indent-legacy.md create mode 100644 docs/description/indent.md create mode 100644 docs/description/jsx-a11y_accessible-emoji.md create mode 100644 docs/description/jsx-a11y_label-has-for.md create mode 100644 docs/description/jsx-a11y_no-onchange.md create mode 100644 docs/description/jsx-quotes.md create mode 100644 docs/description/key-spacing.md create mode 100644 docs/description/keyword-spacing.md create mode 100644 docs/description/linebreak-style.md create mode 100644 docs/description/lines-around-comment.md create mode 100644 docs/description/lines-around-directive.md create mode 100644 docs/description/lines-between-class-members.md create mode 100644 docs/description/max-len.md create mode 100644 docs/description/max-statements-per-line.md create mode 100644 docs/description/multiline-ternary.md create mode 100644 docs/description/n_no-hide-core-modules.md create mode 100644 docs/description/n_shebang.md create mode 100644 docs/description/new-parens.md create mode 100644 docs/description/newline-after-var.md create mode 100644 docs/description/newline-before-return.md create mode 100644 docs/description/newline-per-chained-call.md create mode 100644 docs/description/no-buffer-constructor.md create mode 100644 docs/description/no-catch-shadow.md create mode 100644 docs/description/no-confusing-arrow.md create mode 100644 docs/description/no-extra-parens.md create mode 100644 docs/description/no-extra-semi.md create mode 100644 docs/description/no-floating-decimal.md create mode 100644 docs/description/no-mixed-operators.md create mode 100644 docs/description/no-mixed-requires.md create mode 100644 docs/description/no-mixed-spaces-and-tabs.md create mode 100644 docs/description/no-multi-spaces.md create mode 100644 docs/description/no-multiple-empty-lines.md create mode 100644 docs/description/no-native-reassign.md create mode 100644 docs/description/no-negated-in-lhs.md create mode 100644 docs/description/no-new-object.md create mode 100644 docs/description/no-new-require.md create mode 100644 docs/description/no-path-concat.md create mode 100644 docs/description/no-process-env.md create mode 100644 docs/description/no-process-exit.md create mode 100644 docs/description/no-restricted-modules.md create mode 100644 docs/description/no-return-await.md create mode 100644 docs/description/no-spaced-func.md create mode 100644 docs/description/no-sync.md create mode 100644 docs/description/no-tabs.md create mode 100644 docs/description/no-trailing-spaces.md create mode 100644 docs/description/no-whitespace-before-property.md create mode 100644 docs/description/nonblock-statement-body-position.md create mode 100644 docs/description/object-curly-newline.md create mode 100644 docs/description/object-curly-spacing.md create mode 100644 docs/description/object-property-newline.md create mode 100644 docs/description/one-var-declaration-per-line.md create mode 100644 docs/description/operator-linebreak.md create mode 100644 docs/description/padded-blocks.md create mode 100644 docs/description/padding-line-between-statements.md create mode 100644 docs/description/prefer-reflect.md create mode 100644 docs/description/quote-props.md create mode 100644 docs/description/quotes.md create mode 100644 docs/description/react_jsx-sort-default-props.md create mode 100644 docs/description/react_jsx-space-before-closing.md create mode 100644 docs/description/require-jsdoc.md create mode 100644 docs/description/rest-spread-spacing.md create mode 100644 docs/description/rxjs_no-tap.md create mode 100644 docs/description/semi-spacing.md create mode 100644 docs/description/semi-style.md create mode 100644 docs/description/semi.md create mode 100644 docs/description/space-before-blocks.md create mode 100644 docs/description/space-before-function-paren.md create mode 100644 docs/description/space-in-parens.md create mode 100644 docs/description/space-infix-ops.md create mode 100644 docs/description/space-unary-ops.md create mode 100644 docs/description/spaced-comment.md create mode 100644 docs/description/switch-colon-spacing.md create mode 100644 docs/description/template-curly-spacing.md create mode 100644 docs/description/template-tag-spacing.md create mode 100644 docs/description/valid-jsdoc.md create mode 100644 docs/description/vue-scoped-css_require-scoped.md create mode 100644 docs/description/vue_component-tags-order.md create mode 100644 docs/description/vue_no-invalid-model-keys.md create mode 100644 docs/description/vue_no-ref-object-destructure.md create mode 100644 docs/description/vue_no-setup-props-destructure.md create mode 100644 docs/description/vue_script-setup-uses-vars.md create mode 100644 docs/description/vue_v-on-function-call.md create mode 100644 docs/description/vuejs-accessibility_no-onchange.md create mode 100644 docs/description/wrap-iife.md create mode 100644 docs/description/wrap-regex.md create mode 100644 docs/description/yield-star-spacing.md diff --git a/docs/description/@angular-eslint_prefer-standalone-component.md b/docs/description/@angular-eslint_prefer-standalone-component.md new file mode 100644 index 000000000..0032143a8 --- /dev/null +++ b/docs/description/@angular-eslint_prefer-standalone-component.md @@ -0,0 +1,298 @@ + + +
+ +# `@angular-eslint/prefer-standalone-component` + +## ⚠️ THIS RULE IS DEPRECATED + +Please use `@angular-eslint/prefer-standalone` instead. + +--- + +Ensures component `standalone` property is set to `true` in the component decorator + +- Type: suggestion +- 🔧 Supports autofix (`--fix`) + +
+ +## Rule Options + +The rule does not have any configuration options. + +
+ +## Usage Examples + +> The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit. + +
+ +
+❌ - Toggle examples of incorrect code for this rule + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@Component({}) +~~~~~~~~~~~~~~ +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@Component({ standalone: false }) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@Component({ +~~~~~~~~~~~~ +standalone: false, +~~~~~~~~~~~~~~~~~~ +template: '
' +~~~~~~~~~~~~~~~~~~~~~~~ +}) +~~ +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@Component({ +~~~~~~~~~~~~ +template: '
' +~~~~~~~~~~~~~~~~~~~~~~~ +}) +~~ +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@Component({ +~~~~~~~~~~~~ +selector: 'my-selector', +~~~~~~~~~~~~~~~~~~~~~~~ +template: '
' +~~~~~~~~~~~~~~~~~~~~~~~ +}) +~~ +class Test {} +``` + +
+ +
+ +--- + +
+ +
+✅ - Toggle examples of correct code for this rule + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@Component({ + standalone: true, +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@Component({ + standalone: true, + selector: 'test-selector' +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/prefer-standalone-component": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@Component({ + selector: 'test-selector', + standalone: true, + template: '
', + styleUrls: ['./test.css'] +}) +class Test {} +``` + +
+ +
diff --git a/docs/description/@angular-eslint_sort-ngmodule-metadata-arrays.md b/docs/description/@angular-eslint_sort-ngmodule-metadata-arrays.md new file mode 100644 index 000000000..2a38864a5 --- /dev/null +++ b/docs/description/@angular-eslint_sort-ngmodule-metadata-arrays.md @@ -0,0 +1,607 @@ + + +
+ +# `@angular-eslint/sort-ngmodule-metadata-arrays` + +## ⚠️ THIS RULE IS DEPRECATED + +--- + +Ensures ASC alphabetical order for `NgModule` metadata arrays for easy visual scanning + +- Type: suggestion +- 🔧 Supports autofix (`--fix`) + +
+ +## Rule Options + +The rule accepts an options object with the following properties: + +```ts +interface Options { + /** + * A string with a BCP 47 language tag. + * + * Default: `"en-US"` + */ + locale?: string; +} + +``` + +
+ +## Usage Examples + +> The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit. + +
+ +
+❌ - Toggle examples of incorrect code for this rule + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + imports: [aModule, bModule, DModule, cModule] + ~~~~~~~ +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + 'declarations': [ + AComponent, + cPipe, + bDirective, + ~~~~~~~~~~ + DComponent, + ], +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + ['exports']: [ + AComponent, + cPipe, + bDirective, + ~~~~~~~~~~ + DComponent, + ], +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + [`bootstrap`]: [ + AppModule2, + AppModule3, + AppModule1, + ~~~~~~~~~~ + ] +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + schemas: [ + A_SCHEMA, + C_SCHEMA, + B_SCHEMA, + ~~~~~~~~ + ] +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + providers: [ + AProvider, + { + provide: 'myprovider', + useClass: MyProvider, + }, + cProvider, + bProvider, + ~~~~~~~~~ + DProvider, + ] +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + bootstrap, + declarations: declarations, + providers: providers(), + schemas: [], + [imports]: [ + aModule, + bModule, + DModule, + cModule, + ~~~~~~~ + ], +}) +class Test {} +``` + +
+ +--- + +
+ +#### Custom Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error", + { + "locale": "cs-CZ" + } + ] + } +} +``` + +
+ +#### ❌ Invalid Code + +```ts +@NgModule({ + imports: [chModule, dModule] + ~~~~~~~ +}) +class Test {} +``` + +
+ +
+ +--- + +
+ +
+✅ - Toggle examples of correct code for this rule + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@NgModule() +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@NgModule({}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +const options = {}; +@NgModule(options) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@NgModule({ + bootstrap: [ + AppModule1, + AppModule2, + AppModule3, + ], + 'declarations': [ + AComponent, + bDirective, + cPipe, + DComponent, + VariableComponent, + ], + ['imports']: [ + _foo, + AModule, + bModule, + cModule, + DModule, + ], + [`providers`]: [ + AProvider, + { + provide: 'myprovider', + useClass: MyProvider, + }, + bProvider, + cProvider, + DProvider, + ], +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@Component({ + providers: [ + DeclarationD, + DeclarationA, + ] +}) +class Test {} +``` + +
+ +--- + +
+ +#### Default Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error" + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@NgModule({ + providers: [ + { + provide: 'myprovider', + useFactory: myProviderFactory, + deps: [TOKEN_Z, ClassX, ClassA, TOKEN_A], + }, + ], +}) +class Test {} +``` + +
+ +--- + +
+ +#### Custom Config + +```json +{ + "rules": { + "@angular-eslint/sort-ngmodule-metadata-arrays": [ + "error", + { + "locale": "cs-CZ" + } + ] + } +} +``` + +
+ +#### ✅ Valid Code + +```ts +@Component({ + providers: [ + DatepickerProvider, + ChipsProvider, + ] +}) +class Test {} +``` + +
+ +
diff --git a/docs/description/@lwc_lwc_no-dupe-class-members.md b/docs/description/@lwc_lwc_no-dupe-class-members.md new file mode 100644 index 000000000..c4f385c3a --- /dev/null +++ b/docs/description/@lwc_lwc_no-dupe-class-members.md @@ -0,0 +1,45 @@ +# Disallow duplicate class members (no-dupe-class-members) + +> ⚠️ This rule is deprecated. It can be replaced by ESLint builtin [no-dupe-class-members](https://eslint.org/docs/rules/no-dupe-class-members) rule. ⚠️ + +If there are declarations of the same name in class members, the last declaration overwrites other declarations silently. This can cause unexpected behaviors. This rule prevents usage of duplicate class members (fields and methods) on the same class. + +## Rule details + +Example of **incorrect** code: + +```js +class Foo { + bar() {} + bar() {} +} + +class Foo { + bar; + bar() {} +} + +class Foo { + bar; + get bar() {} +} +``` + +Example of **correct** code: + +```js +class Foo { + foo() {} + bar() {} +} + +class Foo { + foo; + bar() {} +} + +class Foo { + foo; + get bar() {} +} +``` diff --git a/docs/description/@typescript-eslint_block-spacing.md b/docs/description/@typescript-eslint_block-spacing.md new file mode 100644 index 000000000..9e6ac779d --- /dev/null +++ b/docs/description/@typescript-eslint_block-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Disallow or enforce spaces inside of blocks after opening block and before closing block.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/block-spacing** for documentation. + +This rule extends the base [`eslint/block-spacing`](https://eslint.org/docs/rules/block-spacing) rule. +This version adds support for TypeScript related blocks (interfaces, object type literals and enums). diff --git a/docs/description/@typescript-eslint_brace-style.md b/docs/description/@typescript-eslint_brace-style.md new file mode 100644 index 000000000..66f39643d --- /dev/null +++ b/docs/description/@typescript-eslint_brace-style.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent brace style for blocks.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/brace-style** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_comma-dangle.md b/docs/description/@typescript-eslint_comma-dangle.md new file mode 100644 index 000000000..80057954f --- /dev/null +++ b/docs/description/@typescript-eslint_comma-dangle.md @@ -0,0 +1,20 @@ +--- +description: 'Require or disallow trailing commas.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/comma-dangle** for documentation. + +This rule extends the base [`eslint/comma-dangle`](https://eslint.org/docs/rules/comma-dangle) rule. +It adds support for TypeScript syntax. + +See the [ESLint documentation](https://eslint.org/docs/rules/comma-dangle) for more details on the `comma-dangle` rule. + +## Options + +In addition to the options supported by the `comma-dangle` rule in ESLint core, the rule adds the following options: + +- `"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/docs/description/@typescript-eslint_comma-spacing.md b/docs/description/@typescript-eslint_comma-spacing.md new file mode 100644 index 000000000..ccbd46842 --- /dev/null +++ b/docs/description/@typescript-eslint_comma-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent spacing before and after commas.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/comma-spacing** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_func-call-spacing.md b/docs/description/@typescript-eslint_func-call-spacing.md new file mode 100644 index 000000000..d9acf9fa9 --- /dev/null +++ b/docs/description/@typescript-eslint_func-call-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Require or disallow spacing between function identifiers and their invocations.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/func-call-spacing** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_indent.md b/docs/description/@typescript-eslint_indent.md new file mode 100644 index 000000000..450b80783 --- /dev/null +++ b/docs/description/@typescript-eslint_indent.md @@ -0,0 +1,18 @@ +--- +description: 'Enforce consistent indentation.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/indent** for documentation. + +## Warning + +:::warning + +Please read [Issue #1824: Problems with the indent rule](https://github.com/typescript-eslint/typescript-eslint/issues/1824) before using this rule! + +::: + +This rule extends the base [`eslint/indent`](https://eslint.org/docs/rules/indent) rule. +It adds support for TypeScript nodes. diff --git a/docs/description/@typescript-eslint_key-spacing.md b/docs/description/@typescript-eslint_key-spacing.md new file mode 100644 index 000000000..4a0884d60 --- /dev/null +++ b/docs/description/@typescript-eslint_key-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent spacing between property names and type annotations in types and interfaces.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/key-spacing** for documentation. + +This rule extends the base [`eslint/key-spacing`](https://eslint.org/docs/rules/key-spacing) rule. +It adds support for type annotations on interfaces, classes and type literals properties. diff --git a/docs/description/@typescript-eslint_keyword-spacing.md b/docs/description/@typescript-eslint_keyword-spacing.md new file mode 100644 index 000000000..a57774b5b --- /dev/null +++ b/docs/description/@typescript-eslint_keyword-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent spacing before and after keywords.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/keyword-spacing** for documentation. + +This rule extends the base [`eslint/keyword-spacing`](https://eslint.org/docs/rules/keyword-spacing) rule. +It adds support for generic type parameters on function calls. diff --git a/docs/description/@typescript-eslint_lines-around-comment.md b/docs/description/@typescript-eslint_lines-around-comment.md new file mode 100644 index 000000000..33a04c78f --- /dev/null +++ b/docs/description/@typescript-eslint_lines-around-comment.md @@ -0,0 +1,25 @@ +--- +description: 'Require empty lines around comments.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/lines-around-comment** for documentation. + +This rule extends the base [`eslint/lines-around-comment`](https://eslint.org/docs/rules/lines-around-comment) rule. +It adds support for TypeScript syntax. + +See the [ESLint documentation](https://eslint.org/docs/rules/lines-around-comment) for more details on the `lines-around-comment` rule. + +## Options + +In addition to the options supported by the `lines-around-comment` rule in ESLint core, the rule adds the following options: + +- `allowEnumEnd: true` doesn't require a blank line after an enum body block end +- `allowEnumStart: true` doesn't require a blank line before an enum body block start +- `allowInterfaceEnd: true` doesn't require a blank line before an interface body block end +- `allowInterfaceStart: true` doesn't require a blank line after an interface body block start +- `allowModuleEnd: true` doesn't require a blank line before a module body block end +- `allowModuleStart: true` doesn't require a blank line after a module body block start +- `allowTypeEnd: true` doesn't require a blank line before a type literal block end +- `allowTypeStart: true` doesn't require a blank line after a type literal block start diff --git a/docs/description/@typescript-eslint_lines-between-class-members.md b/docs/description/@typescript-eslint_lines-between-class-members.md new file mode 100644 index 000000000..a64339134 --- /dev/null +++ b/docs/description/@typescript-eslint_lines-between-class-members.md @@ -0,0 +1,53 @@ +--- +description: 'Require or disallow an empty line between class members.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/lines-between-class-members** for documentation. + +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. + +## Options + +In addition to the options supported by the `lines-between-class-members` rule in ESLint core, the rule adds the following options: + +- Object option: + + - `"exceptAfterOverload": true` (default) - Skip checking empty lines after overload class members + - `"exceptAfterOverload": false` - **do not** skip checking empty lines after overload class members + +### `exceptAfterOverload: true` + +Examples of **correct** code for the `{ "exceptAfterOverload": true }` option: + +```ts option='"always", { "exceptAfterOverload": true }' showPlaygroundButton +class foo { + bar(a: string): void; + bar(a: string, b: string): void; + bar(a: string, b: string) {} + + baz() {} + + qux() {} +} +``` + +### `exceptAfterOverload: false` + +Examples of **correct** code for the `{ "exceptAfterOverload": false }` option: + +```ts option='"always", { "exceptAfterOverload": false }' showPlaygroundButton +class foo { + bar(a: string): void; + + bar(a: string, b: string): void; + + bar(a: string, b: string) {} + + baz() {} + + qux() {} +} +``` diff --git a/docs/description/@typescript-eslint_member-delimiter-style.md b/docs/description/@typescript-eslint_member-delimiter-style.md new file mode 100644 index 000000000..2a561b0b6 --- /dev/null +++ b/docs/description/@typescript-eslint_member-delimiter-style.md @@ -0,0 +1,166 @@ +--- +description: 'Require a specific member delimiter style for interfaces and type literals.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/member-delimiter-style** for documentation. + +TypeScript allows three delimiters between members in interfaces and type aliases: + + +```ts +interface Foo { + // Semicolons (default, preferred in TypeScript): + name: string; + + // Commas (JSON-like): + name: string, + + // Line breaks (none): + name: string +} +``` + +For code readability, it's generally best to use the same style consistently in your codebase. + +This rule enforces keeping to one configurable code style. +It can also standardize the presence (or absence) of a delimiter in the last member of a construct, as well as a separate delimiter syntax for single line declarations. + +## Options + +Default config: + +```json +{ + "multiline": { + "delimiter": "semi", + "requireLast": true + }, + "singleline": { + "delimiter": "semi", + "requireLast": false + }, + "multilineDetection": "brackets" +} +``` + +`multiline` config only applies to multiline `interface`/`type` definitions. +`singleline` config only applies to single line `interface`/`type` definitions. +The two configs are entirely separate, and do not effect one another. + +`multilineDetection` determines what counts as multiline + +- `"brackets"` (default) any newlines in the type or interface make it multiline. +- `"last-member"` if the last member of the interface is on the same line as the last bracket, it is counted as a single line. + +### `delimiter` + +Accepts three values (or two for `singleline`): + +- `comma` - each member should be delimited with a comma (`,`). +- `semi` - each member should be delimited with a semicolon (`;`). +- `none` - each member should be delimited with nothing. + +:::note +`none` is not an option for `singleline` because having no delimiter between members on a single line is a syntax error in TS. +::: + +### `requireLast` + +Determines whether or not the last member in the `interface`/`type` should have a delimiter: + +- `true` - the last member **_must_** have a delimiter. +- `false` - the last member **_must not_** have a delimiter. + +### `overrides` + +Allows you to specify options specifically for either `interface`s or `type` definitions / inline `type`s. + +For example, to require commas for `type`s, and semicolons for multiline `interface`s: + +```json +{ + "multiline": { + "delimiter": "comma", + "requireLast": true + }, + "singleline": { + "delimiter": "comma", + "requireLast": true + }, + "overrides": { + "interface": { + "multiline": { + "delimiter": "semi", + "requireLast": true + } + } + } +} +``` + +## Examples + +Examples of code for this rule with the default config: + + + +#### ❌ Incorrect + + +```ts +// missing semicolon delimiter +interface Foo { + name: string + greet(): string +} + +// using incorrect delimiter +interface Bar { + name: string, + greet(): string, +} + +// missing last member delimiter +interface Baz { + name: string; + greet(): string +} + +// incorrect delimiter +type FooBar = { name: string, greet(): string } + +// last member should not have delimiter +type FooBar = { name: string; greet(): string; } +``` + +#### ✅ Correct + + +```ts +interface Foo { + name: string; + greet(): string; +} + +interface Foo { name: string } + +type Bar = { + name: string; + greet(): string; +} + +type Bar = { name: string } + +type FooBar = { name: string; greet(): string } +``` + + + +## When Not To Use It + +If you specifically want to use both member delimiter kinds for stylistic reasons, or don't wish to enforce one style over the other, you can avoid this rule. + +However, keep in mind that inconsistent style can harm readability in a project. +We recommend picking a single option for this rule that works best for your project. diff --git a/docs/description/@typescript-eslint_no-extra-parens.md b/docs/description/@typescript-eslint_no-extra-parens.md new file mode 100644 index 000000000..e0afc6573 --- /dev/null +++ b/docs/description/@typescript-eslint_no-extra-parens.md @@ -0,0 +1,10 @@ +--- +description: 'Disallow unnecessary parentheses.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/no-extra-parens** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_no-extra-semi.md b/docs/description/@typescript-eslint_no-extra-semi.md new file mode 100644 index 000000000..b20f22d94 --- /dev/null +++ b/docs/description/@typescript-eslint_no-extra-semi.md @@ -0,0 +1,12 @@ +--- +description: 'Disallow unnecessary semicolons.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/no-extra-semi** for documentation. + +This rule extends the base [`eslint/no-extra-semi`](https://eslint.org/docs/rules/no-extra-semi) rule. +It adds support for class properties. + +Note that this rule is classified as a "Suggestion" rule instead of a "Layout & Formatting" rule because [adding extra semi-colons actually changes the AST of the program](https://typescript-eslint.io/play/#ts=5.1.6&showAST=es&fileType=.ts&code=MYewdgzgLgBAHjAvDAjAbg0A&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQHYHsBaRADwBdoBDQ5RAWwEt0p8AzVyAGnG0gAEyATwAOKAMbQGwssWTwGuMgHoCxclRr0mGSImjR80SDwC%2BIE0A&tsconfig=&tokens=false). With that said, modern TypeScript formatters will remove extra semi-colons automatically during the formatting process. Thus, if you [use a formatter](/troubleshooting/formatting), then enabling this rule is probably unnecessary. diff --git a/docs/description/@typescript-eslint_no-throw-literal.md b/docs/description/@typescript-eslint_no-throw-literal.md new file mode 100644 index 000000000..511b2a987 --- /dev/null +++ b/docs/description/@typescript-eslint_no-throw-literal.md @@ -0,0 +1,22 @@ +--- +description: 'Disallow throwing literals as exceptions.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/no-throw-literal** for documentation. + +It is considered good practice to only `throw` the `Error` object itself or an object using the `Error` object as base objects for user-defined exceptions. +The fundamental benefit of `Error` objects is that they automatically keep track of where they were built and originated. + +This rule restricts what can be thrown as an exception. + +:::warning +This rule is being renamed to [`only-throw-error`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules/only-throw-error.mdx). +When it was first created, it only prevented literals from being thrown (hence the name), but it has now been expanded to only allow expressions which have a possibility of being an `Error` object. +With the `allowThrowingAny` and `allowThrowingUnknown` options, it can be configured to only allow throwing values which are guaranteed to be an instance of `Error`. + +The current name `no-throw-literal` will be removed in a future major version of typescript-eslint. +::: + + diff --git a/docs/description/@typescript-eslint_no-type-alias.md b/docs/description/@typescript-eslint_no-type-alias.md new file mode 100644 index 000000000..3fe99fce5 --- /dev/null +++ b/docs/description/@typescript-eslint_no-type-alias.md @@ -0,0 +1,623 @@ +--- +description: 'Disallow type aliases.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/no-type-alias** for documentation. + +:::danger Deprecated + +This rule has been deprecated in favour of the [`@typescript-eslint/consistent-type-definitions`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules/consistent-type-definitions.mdx) rule. +TypeScript type aliases are a commonly necessary language feature; banning it altogether is oftentimes counterproductive. + +::: + +:::note + +If you want to ban certain classifications of type aliases, consider using [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax). +See [Troubleshooting & FAQs](/troubleshooting#how-can-i-ban-specific-language-feature). + +::: + +In TypeScript, type aliases serve three purposes: + +- Aliasing other types so that we can refer to them using a simpler name. + +```ts +// this... +type Person = { + firstName: string; + lastName: string; + age: number; +}; + +function addPerson(person: Person) { + // ... +} + +// is easier to read than this... +function addPerson(person: { + firstName: string; + lastName: string; + age: number; +}) { + // ... +} +``` + +- Act sort of like an interface, providing a set of methods and properties that must exist + in the objects implementing the type. + +```ts +type Person = { + firstName: string; + lastName: string; + age: number; + walk: () => void; + talk: () => void; +}; + +// you know person will have 3 properties and 2 methods, +// because the structure has already been defined. +var person: Person = { + // ... +}; + +// so we can be sure that this will work +person.walk(); +``` + +- Act like mapping tools between types to allow quick modifications. + +```ts +type Immutable = { readonly [P in keyof T]: T[P] }; + +type Person = { + name: string; + age: number; +}; + +type ImmutablePerson = Immutable; + +var person: ImmutablePerson = { name: 'John', age: 30 }; +person.name = 'Brad'; // error, readonly property +``` + +When aliasing, the type alias does not create a new type, it just creates a new name +to refer to the original type. So aliasing primitives and other simple types, tuples, unions +or intersections can some times be redundant. + +```ts +// this doesn't make much sense +type myString = string; +``` + +On the other hand, using a type alias as an interface can limit your ability to: + +- Reuse your code: interfaces can be extended or implemented by other types. Type aliases cannot. +- Debug your code: interfaces create a new name, so is easy to identify the base type of an object + while debugging the application. + +Finally, mapping types is an advanced technique and leaving it open can quickly become a pain point +in your application. + +## Examples + +This rule disallows the use of type aliases in favor of interfaces +and simplified types (primitives, tuples, unions, intersections, etc). + +## Options + +### `allowAliases` + +This applies to primitive types and reference types. + +The setting accepts the following values: + +- `"always"` or `"never"` to active or deactivate the feature. +- `"in-unions"`, allows aliasing in union statements, e.g. `type Foo = string | string[];` +- `"in-intersections"`, allows aliasing in intersection statements, e.g. `type Foo = string & string[];` +- `"in-unions-and-intersections"`, allows aliasing in union and/or intersection statements. + +Examples of **correct** code for the `{ "allowAliases": "always" }` options: + +```ts option='{ "allowAliases": "always" }' showPlaygroundButton +// primitives +type Foo = 'a'; + +type Foo = 'a' | 'b'; + +type Foo = string; + +type Foo = string | string[]; + +type Foo = string & string[]; + +type Foo = `foo-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar; + +type Foo = Bar | Baz; + +type Foo = Bar & Baz; +``` + +Examples of **incorrect** code for the `{ "allowAliases": "in-unions" }` option: + +```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton +// primitives +type Foo = 'a'; + +type Foo = string; + +type Foo = string & string[]; + +type Foo = `foo-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar; + +type Foo = Bar & Baz; +``` + +Examples of **correct** code for the `{ "allowAliases": "in-unions" }` option: + +```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton +// primitives +type Foo = 'a' | 'b'; + +type Foo = string | string[]; + +type Foo = `a-${number}` | `b-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar | Baz; +``` + +Examples of **incorrect** code for the `{ "allowAliases": "in-intersections" }` option: + +```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton +// primitives +type Foo = 'a'; + +type Foo = 'a' | 'b'; + +type Foo = string; + +type Foo = string | string[]; + +type Foo = `a-${number}` | `b-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar; + +type Foo = Bar | Baz; +``` + +Examples of **correct** code for the `{ "allowAliases": "in-intersections" }` option: + +```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton +// primitives +type Foo = string & string[]; + +type Foo = `a-${number}` & `b-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar & Baz; +``` + +Examples of **incorrect** code for the `{ "allowAliases": "in-unions-and-intersections" }` option: + +```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton +// primitives +type Foo = 'a'; + +type Foo = string; + +type Foo = `foo-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar; +``` + +Examples of **correct** code for the `{ "allowAliases": "in-unions-and-intersections" }` option: + +```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton +// primitives +type Foo = 'a' | 'b'; + +type Foo = string | string[]; + +type Foo = string & string[]; + +type Foo = `a-${number}` & `b-${number}`; + +type Foo = `a-${number}` | `b-${number}`; + +// reference types +interface Bar {} +class Baz implements Bar {} + +type Foo = Bar | Baz; + +type Foo = Bar & Baz; +``` + +### `allowCallbacks` + +This applies to function types. + +The setting accepts the following values: + +- `"always"` or `"never"` to active or deactivate the feature. + +Examples of **correct** code for the `{ "allowCallbacks": "always" }` option: + +```ts option='{ "allowCallbacks": "always" }' showPlaygroundButton +type Foo = () => void; + +type Foo = (name: string) => string; + +class Person {} + +type Foo = (name: string, age: number) => string | Person; + +type Foo = (name: string, age: number) => string & Person; +``` + +### `allowConditionalTypes` + +This applies to conditional types. + +Examples of **correct** code for the `{ "allowConditionalTypes": "always" }` option: + +```ts option='{ "allowConditionalTypes": "always" }' showPlaygroundButton +type Foo = T extends number ? number : null; +``` + +### `allowConstructors` + +This applies to constructor types. + +The setting accepts the following values: + +- `"always"` or `"never"` to active or deactivate the feature. + +Examples of **correct** code for the `{ "allowConstructors": "always" }` option: + +```ts option='{ "allowConstructors": "always" }' showPlaygroundButton +type Foo = new () => void; +``` + +### `allowLiterals` + +This applies to literal types (`type Foo = { ... }`). + +The setting accepts the following options: + +- `"always"` or `"never"` to active or deactivate the feature. +- `"in-unions"`, allows literals in union statements, e.g. `type Foo = string | string[];` +- `"in-intersections"`, allows literals in intersection statements, e.g. `type Foo = string & string[];` +- `"in-unions-and-intersections"`, allows literals in union and/or intersection statements. + +Examples of **correct** code for the `{ "allowLiterals": "always" }` options: + +```ts option='{ "allowLiterals": "always" }' showPlaygroundButton +type Foo = {}; + +type Foo = { + name: string; + age: number; +}; + +type Foo = { + name: string; + age: number; + walk: (miles: number) => void; +}; + +type Foo = { name: string } | { age: number }; + +type Foo = { name: string } & { age: number }; +``` + +Examples of **incorrect** code for the `{ "allowLiterals": "in-unions" }` option: + +```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton +type Foo = {}; + +type Foo = { + name: string; + age: number; +}; + +type Foo = { + name: string; + age: number; + walk: (miles: number) => void; +}; + +type Foo = { name: string } & { age: number }; +``` + +Examples of **correct** code for the `{ "allowLiterals": "in-unions" }` option: + +```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton +type Foo = { name: string } | { age: number }; +``` + +Examples of **incorrect** code for the `{ "allowLiterals": "in-intersections" }` option: + +```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton +type Foo = {}; + +type Foo = { + name: string; + age: number; +}; + +type Foo = { + name: string; + age: number; + walk: (miles: number) => void; +}; + +type Foo = { name: string } | { age: number }; +``` + +Examples of **correct** code for the `{ "allowLiterals": "in-intersections" }` option: + +```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton +type Foo = { name: string } & { age: number }; +``` + +Examples of **incorrect** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option: + +```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = {}; + +type Foo = { + name: string; + age: number; +}; + +type Foo = { + name: string; + age: number; + walk: (miles: number) => void; +}; +``` + +Examples of **correct** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option: + +```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = { name: string } | { age: number }; + +type Foo = { name: string } & { age: number }; +``` + +### `allowMappedTypes` + +This applies to literal types. + +The setting accepts the following values: + +- `"always"` or `"never"` to active or deactivate the feature. +- `"in-unions"`, allows aliasing in union statements, e.g. `type Foo = string | string[];` +- `"in-intersections"`, allows aliasing in intersection statements, e.g. `type Foo = string & string[];` +- `"in-unions-and-intersections"`, allows aliasing in union and/or intersection statements. + +Examples of **correct** code for the `{ "allowMappedTypes": "always" }` options: + +```ts option='{ "allowMappedTypes": "always" }' showPlaygroundButton +type Foo = { readonly [P in keyof T]: T[P] }; + +type Foo = { [P in keyof T]?: T[P] }; + +type Foo = + | { readonly [P in keyof T]: T[P] } + | { readonly [P in keyof U]: U[P] }; + +type Foo = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] }; + +type Foo = { readonly [P in keyof T]: T[P] } & { + readonly [P in keyof U]: U[P]; +}; + +type Foo = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] }; +``` + +Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions" }` option: + +```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton +type Foo = { readonly [P in keyof T]: T[P] }; + +type Foo = { [P in keyof T]?: T[P] }; + +type Foo = { readonly [P in keyof T]: T[P] } & { + readonly [P in keyof U]: U[P]; +}; + +type Foo = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] }; +``` + +Examples of **correct** code for the `{ "allowMappedTypes": "in-unions" }` option: + +```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton +type Foo = + | { readonly [P in keyof T]: T[P] } + | { readonly [P in keyof U]: U[P] }; + +type Foo = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] }; +``` + +Examples of **incorrect** code for the `{ "allowMappedTypes": "in-intersections" }` option: + +```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton +type Foo = { readonly [P in keyof T]: T[P] }; + +type Foo = { [P in keyof T]?: T[P] }; + +type Foo = + | { readonly [P in keyof T]: T[P] } + | { readonly [P in keyof U]: U[P] }; + +type Foo = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] }; +``` + +Examples of **correct** code for the `{ "allowMappedTypes": "in-intersections" }` option: + +```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton +type Foo = { readonly [P in keyof T]: T[P] } & { + readonly [P in keyof U]: U[P]; +}; + +type Foo = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] }; +``` + +Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option: + +```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = { readonly [P in keyof T]: T[P] }; + +type Foo = { [P in keyof T]?: T[P] }; +``` + +Examples of **correct** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option: + +```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = + | { readonly [P in keyof T]: T[P] } + | { readonly [P in keyof U]: U[P] }; + +type Foo = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] }; + +type Foo = { readonly [P in keyof T]: T[P] } & { + readonly [P in keyof U]: U[P]; +}; + +type Foo = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] }; +``` + +### `allowTupleTypes` + +This applies to tuple types (`type Foo = [number]`). + +The setting accepts the following options: + +- `"always"` or `"never"` to active or deactivate the feature. +- `"in-unions"`, allows tuples in union statements, e.g. `type Foo = [string] | [string, string];` +- `"in-intersections"`, allows tuples in intersection statements, e.g. `type Foo = [string] & [string, string];` +- `"in-unions-and-intersections"`, allows tuples in union and/or intersection statements. + +Examples of **correct** code for the `{ "allowTupleTypes": "always" }` options: + +```ts option='{ "allowTupleTypes": "always" }' showPlaygroundButton +type Foo = [number]; + +type Foo = [number] | [number, number]; + +type Foo = [number] & [number, number]; + +type Foo = [number] | ([number, number] & [string, string]); +``` + +Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions" }` option: + +```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton +type Foo = [number]; + +type Foo = [number] & [number, number]; + +type Foo = [string] & [number]; +``` + +Examples of **correct** code for the `{ "allowTupleTypes": "in-unions" }` option: + +```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton +type Foo = [number] | [number, number]; + +type Foo = [string] | [number]; +``` + +Examples of **incorrect** code for the `{ "allowTupleTypes": "in-intersections" }` option: + +```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton +type Foo = [number]; + +type Foo = [number] | [number, number]; + +type Foo = [string] | [number]; +``` + +Examples of **correct** code for the `{ "allowTupleTypes": "in-intersections" }` option: + +```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton +type Foo = [number] & [number, number]; + +type Foo = [string] & [number]; +``` + +Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option: + +```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = [number]; + +type Foo = [string]; +``` + +Examples of **correct** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option: + +```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton +type Foo = [number] & [number, number]; + +type Foo = [string] | [number]; +``` + +### `allowGenerics` + +This applies to generic types, including TypeScript provided global utility types (`type Foo = Record`). + +The setting accepts the following options: + +- `"always"` or `"never"` to active or deactivate the feature. + +Examples of **correct** code for the `{ "allowGenerics": "always" }` options: + +```ts option='{ "allowGenerics": "always" }' showPlaygroundButton +type Foo = Bar; + +type Foo = Record; + +type Foo = Readonly; + +type Foo = Partial; + +type Foo = Omit; +``` + + + +## Further Reading + +- [Advanced Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html) diff --git a/docs/description/@typescript-eslint_no-useless-template-literals.md b/docs/description/@typescript-eslint_no-useless-template-literals.md new file mode 100644 index 000000000..eb1d46fb0 --- /dev/null +++ b/docs/description/@typescript-eslint_no-useless-template-literals.md @@ -0,0 +1,57 @@ +--- +description: 'Disallow unnecessary template literals.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/no-useless-template-literals** for documentation. + +This rule reports template literals that can be simplified to a normal string literal. + +## Examples + + + +#### ❌ Incorrect + +```ts +const ab1 = `${'a'}${'b'}`; +const ab2 = `a${'b'}`; + +const stringWithNumber = `${'1 + 1 = '}${2}`; + +const stringWithBoolean = `${'true is '}${true}`; + +const text = 'a'; +const wrappedText = `${text}`; + +declare const intersectionWithString: string & { _brand: 'test-brand' }; +const wrappedIntersection = `${intersectionWithString}`; +``` + +#### ✅ Correct + +```ts +const ab1 = 'ab'; +const ab2 = 'ab'; + +const stringWithNumber = `1 + 1 = 2`; + +const stringWithBoolean = `true is true`; + +const text = 'a'; +const wrappedText = text; + +declare const intersectionWithString: string & { _brand: 'test-brand' }; +const wrappedIntersection = intersectionWithString; +``` + + + +## When Not To Use It + +When you want to allow string expressions inside template literals. + +## Related To + +- [`restrict-template-expressions`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules/restrict-template-expressions.mdx) diff --git a/docs/description/@typescript-eslint_object-curly-spacing.md b/docs/description/@typescript-eslint_object-curly-spacing.md new file mode 100644 index 000000000..91b242137 --- /dev/null +++ b/docs/description/@typescript-eslint_object-curly-spacing.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent spacing inside braces.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/object-curly-spacing** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_padding-line-between-statements.md b/docs/description/@typescript-eslint_padding-line-between-statements.md new file mode 100644 index 000000000..8cf091b4e --- /dev/null +++ b/docs/description/@typescript-eslint_padding-line-between-statements.md @@ -0,0 +1,33 @@ +--- +description: 'Require or disallow padding lines between statements.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/padding-line-between-statements** for documentation. + +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`. + +## Options + +In addition to options provided by ESLint, `interface` and `type` can be used as statement types. + +For example, to add blank lines before interfaces and type definitions: + +```jsonc +{ + // Example - Add blank lines before interface and type definitions. + "padding-line-between-statements": "off", + "@typescript-eslint/padding-line-between-statements": [ + "error", + { + "blankLine": "always", + "prev": "*", + "next": ["interface", "type"], + }, + ], +} +``` + +**Note:** ESLint `cjs-export` and `cjs-import` statement types are renamed to `exports` and `require` respectively. diff --git a/docs/description/@typescript-eslint_prefer-ts-expect-error.md b/docs/description/@typescript-eslint_prefer-ts-expect-error.md new file mode 100644 index 000000000..c1574d6fe --- /dev/null +++ b/docs/description/@typescript-eslint_prefer-ts-expect-error.md @@ -0,0 +1,72 @@ +--- +description: 'Enforce using `@ts-expect-error` over `@ts-ignore`.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/prefer-ts-expect-error** for documentation. + +TypeScript allows you to suppress all errors on a line by placing a comment starting with `@ts-ignore` or `@ts-expect-error` immediately before the erroring line. +The two directives work the same, except `@ts-expect-error` causes a type error if placed before a line that's not erroring in the first place. + +This means it's easy for `@ts-ignore`s to be forgotten about, and remain in code even after the error they were suppressing is fixed. +This is dangerous, as if a new error arises on that line it'll be suppressed by the forgotten about `@ts-ignore`, and so be missed. + +## Examples + +This rule reports any usage of `@ts-ignore`, including a fixer to replace with `@ts-expect-error`. + + + +#### ❌ Incorrect + +```ts +// @ts-ignore +const str: string = 1; + +/** + * Explaining comment + * + * @ts-ignore */ +const multiLine: number = 'value'; + +/** @ts-ignore */ +const block: string = 1; + +const isOptionEnabled = (key: string): boolean => { + // @ts-ignore: if key isn't in globalOptions it'll be undefined which is false + return !!globalOptions[key]; +}; +``` + +#### ✅ Correct + +```ts +// @ts-expect-error +const str: string = 1; + +/** + * Explaining comment + * + * @ts-expect-error */ +const multiLine: number = 'value'; + +/** @ts-expect-error */ +const block: string = 1; + +const isOptionEnabled = (key: string): boolean => { + // @ts-expect-error: if key isn't in globalOptions it'll be undefined which is false + return !!globalOptions[key]; +}; +``` + + + +## When Not To Use It + +If you are compiling against multiple versions of TypeScript and using `@ts-ignore` to ignore version-specific type errors, this rule might get in your way. +You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule. + +## Further Reading + +- [Original Implementing PR](https://github.com/microsoft/TypeScript/pull/36014) diff --git a/docs/description/@typescript-eslint_quotes.md b/docs/description/@typescript-eslint_quotes.md new file mode 100644 index 000000000..62c6051c4 --- /dev/null +++ b/docs/description/@typescript-eslint_quotes.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce the consistent use of either backticks, double, or single quotes.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/quotes** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_semi.md b/docs/description/@typescript-eslint_semi.md new file mode 100644 index 000000000..b1930e8cd --- /dev/null +++ b/docs/description/@typescript-eslint_semi.md @@ -0,0 +1,12 @@ +--- +description: 'Require or disallow semicolons instead of ASI.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/semi** for documentation. + +This rule extends the base [`eslint/semi`](https://eslint.org/docs/rules/semi) rule. +It adds support for TypeScript features that require semicolons. + +See also the [`@typescript-eslint/member-delimiter-style`](member-delimiter-style.mdx) rule, which allows you to specify the delimiter for `type` and `interface` members. diff --git a/docs/description/@typescript-eslint_sort-type-constituents.md b/docs/description/@typescript-eslint_sort-type-constituents.md new file mode 100644 index 000000000..0f16a6da6 --- /dev/null +++ b/docs/description/@typescript-eslint_sort-type-constituents.md @@ -0,0 +1,202 @@ +--- +description: 'Enforce constituents of a type union/intersection to be sorted alphabetically.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/sort-type-constituents** for documentation. + +Sorting union (`|`) and intersection (`&`) types can help: + +- keep your codebase standardized +- find repeated types +- reduce diff churn + +This rule reports on any types that aren't sorted alphabetically. + +> Types are sorted case-insensitively and treating numbers like a human would, falling back to character code sorting in case of ties. + +:::note +This rule is _feature frozen_: it will no longer receive new features such as new options. +It still will accept bug and documentation fixes for its existing area of features. + +Stylistic rules that enforce naming and/or sorting conventions tend to grow incomprehensibly complex as increasingly obscure features are requested. +This rule has reached the limit of what is reasonable for the typescript-eslint project to maintain. +See [eslint-plugin: Feature freeze naming and sorting stylistic rules](https://github.com/typescript-eslint/typescript-eslint/issues/8792) for more information. +::: + +## Examples + + + +#### ❌ Incorrect + +```ts +type T1 = B | A; + +type T2 = { b: string } & { a: string }; + +type T3 = [1, 2, 4] & [1, 2, 3]; + +type T4 = + | [1, 2, 4] + | [1, 2, 3] + | { b: string } + | { a: string } + | (() => void) + | (() => string) + | 'b' + | 'a' + | 'b' + | 'a' + | readonly string[] + | readonly number[] + | string[] + | number[] + | B + | A + | string + | any; +``` + +#### ✅ Correct + +```ts +type T1 = A | B; + +type T2 = { a: string } & { b: string }; + +type T3 = [1, 2, 3] & [1, 2, 4]; + +type T4 = + | A + | B + | number[] + | string[] + | any + | string + | readonly number[] + | readonly string[] + | 'a' + | 'a' + | 'b' + | 'b' + | (() => string) + | (() => void) + | { a: string } + | { b: string } + | [1, 2, 3] + | [1, 2, 4]; +``` + + + +## Options + +### `caseSensitive` + +Whether to sort using case sensitive string comparisons. + +Examples of code with `{ "caseSensitive": true }`: + + + +#### ❌ Incorrect + +```ts option='{ "caseSensitive": true }' +type T = 'DeletedAt' | 'DeleteForever'; +``` + +#### ✅ Correct + +```ts option='{ "caseSensitive": true }' +type T = 'DeleteForever' | 'DeletedAt'; +``` + + + +### `checkIntersections` + +Whether to check intersection types (`&`). + +Examples of code with `{ "checkIntersections": true }` (the default): + + + +#### ❌ Incorrect + +```ts option='{ "checkIntersections": true }' +type ExampleIntersection = B & A; +``` + +#### ✅ Correct + +```ts option='{ "checkIntersections": true }' +type ExampleIntersection = A & B; +``` + + + +### `checkUnions` + +Whether to check union types (`|`). + +Examples of code with `{ "checkUnions": true }` (the default): + + + +#### ❌ Incorrect + +```ts option='{ "checkUnions": true }' +type ExampleUnion = B | A; +``` + +#### ✅ Correct + +```ts option='{ "checkUnions": true }' +type ExampleUnion = A | B; +``` + + + +### `groupOrder` + +Each constituent of the type is placed into a group, and then the rule sorts alphabetically within each group. +The ordering of groups is determined by this option. + +- `conditional` - Conditional types (`A extends B ? C : D`) +- `function` - Function and constructor types (`() => void`, `new () => type`) +- `import` - Import types (`import('path')`) +- `intersection` - Intersection types (`A & B`) +- `keyword` - Keyword types (`any`, `string`, etc) +- `literal` - Literal types (`1`, `'b'`, `true`, etc) +- `named` - Named types (`A`, `A['prop']`, `B[]`, `Array`) +- `object` - Object types (`{ a: string }`, `{ [key: string]: number }`) +- `operator` - Operator types (`keyof A`, `typeof B`, `readonly C[]`) +- `tuple` - Tuple types (`[A, B, C]`) +- `union` - Union types (`A | B`) +- `nullish` - `null` and `undefined` + +For example, configuring the rule with `{ "groupOrder": ["literal", "nullish" ]}`: + + + +#### ❌ Incorrect + +```ts option='{ "groupOrder": ["literal", "nullish" ]}' +type ExampleGroup = null | 123; +``` + +#### ✅ Correct + +```ts option='{ "groupOrder": ["literal", "nullish" ]}' +type ExampleGroup = 123 | null; +``` + + + +## When Not To Use It + +This rule is purely a stylistic rule for maintaining consistency in your project. +You can turn it off if you don't want to keep a consistent, predictable order for intersection and union types. +However, keep in mind that inconsistent style can harm readability in a project. diff --git a/docs/description/@typescript-eslint_space-before-blocks.md b/docs/description/@typescript-eslint_space-before-blocks.md new file mode 100644 index 000000000..8fa96fd41 --- /dev/null +++ b/docs/description/@typescript-eslint_space-before-blocks.md @@ -0,0 +1,45 @@ +--- +description: 'Enforce consistent spacing before blocks.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/space-before-blocks** for documentation. + +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. + + + +#### ❌ Incorrect + + +```ts +enum Breakpoint{ + Large, + Medium, +} + +interface State{ + currentBreakpoint: Breakpoint; +} +``` + +#### ✅ Correct + +```ts +enum Breakpoint { + Large, + Medium, +} + +interface State { + currentBreakpoint: Breakpoint; +} +``` + + + +## Options + +In case a more specific options object is passed these blocks will follow `classes` configuration option. diff --git a/docs/description/@typescript-eslint_space-before-function-paren.md b/docs/description/@typescript-eslint_space-before-function-paren.md new file mode 100644 index 000000000..92180ced2 --- /dev/null +++ b/docs/description/@typescript-eslint_space-before-function-paren.md @@ -0,0 +1,10 @@ +--- +description: 'Enforce consistent spacing before function parenthesis.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/space-before-function-paren** for documentation. + +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. diff --git a/docs/description/@typescript-eslint_space-infix-ops.md b/docs/description/@typescript-eslint_space-infix-ops.md new file mode 100644 index 000000000..b6b0ecda7 --- /dev/null +++ b/docs/description/@typescript-eslint_space-infix-ops.md @@ -0,0 +1,16 @@ +--- +description: 'Require spacing around infix operators.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> 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 adds support for enum members. + +```ts +enum MyEnum { + KEY = 'value', +} +``` diff --git a/docs/description/@typescript-eslint_type-annotation-spacing.md b/docs/description/@typescript-eslint_type-annotation-spacing.md new file mode 100644 index 000000000..a2e3d6162 --- /dev/null +++ b/docs/description/@typescript-eslint_type-annotation-spacing.md @@ -0,0 +1,327 @@ +--- +description: 'Require consistent spacing around type annotations.' +--- + +> 🛑 This file is source code, not the primary documentation location! 🛑 +> +> See **https://typescript-eslint.io/rules/type-annotation-spacing** for documentation. + +Spacing around type annotations improves readability of the code. Although the most commonly used style guideline for type annotations in TypeScript prescribes adding a space after the colon, but not before it, it is subjective to the preferences of a project. For example: + + +```ts +// with space after, but not before (default if no option is specified) +let foo: string = "bar"; + +// with no spaces +let foo:string = "bar"; + +// with space before and after +let foo : string = "bar"; + +// with space before, but not after +let foo :string = "bar"; + +// with spaces before and after the fat arrow (default if no option is specified) +type Foo = (string: name) => string; + +// with no spaces between the fat arrow +type Foo = (string: name)=>string; + +// with space after, but not before the fat arrow +type Foo = (string: name)=> string; + +// with space before, but not after the fat arrow +type Foo = (string: name) =>string; +``` + +## Examples + +This rule aims to enforce specific spacing patterns around type annotations and function types in type literals. + + + +#### ❌ Incorrect + + +```ts +let foo:string = "bar"; +let foo :string = "bar"; +let foo : string = "bar"; + +function foo():string {} +function foo() :string {} +function foo() : string {} + +class Foo { + name:string; +} + +class Foo { + name :string; +} + +class Foo { + name : string; +} + +type Foo = ()=>{}; +type Foo = () =>{}; +type Foo = ()=> {}; +``` + +#### ✅ Correct + + +```ts +let foo: string = "bar"; + +function foo(): string {} + +class Foo { + name: string; +} + +type Foo = () => {}; +``` + + + +## Options + +### after + +```json +{ "before": false, "after": true } +``` + + + +#### ❌ Incorrect + + +```ts option='{ "before": false, "after": true }' +let foo:string = "bar"; +let foo :string = "bar"; +let foo : string = "bar"; + +function foo():string {} +function foo() :string {} +function foo() : string {} + +class Foo { + name:string; +} + +class Foo { + name :string; +} + +class Foo { + name : string; +} + +type Foo = ()=>{}; +type Foo = () =>{}; +type Foo = () => {}; +``` + +#### ✅ Correct + + +```ts option='{ "before": false, "after": true }' +let foo: string = "bar"; + +function foo(): string {} + +class Foo { + name: string; +} + +type Foo = ()=> {}; +``` + + + +### before + +```json +{ "before": true, "after": true } +``` + + + +#### ❌ Incorrect + + +```ts option='{ "before": true, "after": true }' +let foo: string = "bar"; +let foo:string = "bar"; +let foo :string = "bar"; + +function foo(): string {} +function foo():string {} +function foo() :string {} + +class Foo { + name: string; +} + +class Foo { + name:string; +} + +class Foo { + name :string; +} + +type Foo = ()=>{}; +type Foo = () =>{}; +type Foo = ()=> {}; +``` + +#### ✅ Correct + + +```ts option='{ "before": true, "after": true }' +let foo : string = "bar"; + +function foo() : string {} + +class Foo { + name : string; +} + +type Foo = () => {}; +``` + + + +### overrides - colon + +```json +{ + "before": false, + "after": false, + "overrides": { "colon": { "before": true, "after": true } } +} +``` + + + +#### ❌ Incorrect + + +```ts option='{"before":false,"after":false,"overrides":{"colon":{"before":true,"after":true}}}' +let foo: string = "bar"; +let foo:string = "bar"; +let foo :string = "bar"; + +function foo(): string {} +function foo():string {} +function foo() :string {} + +class Foo { + name: string; +} + +class Foo { + name:string; +} + +class Foo { + name :string; +} + +type Foo = () =>{}; +type Foo = ()=> {}; +type Foo = () => {}; +``` + +#### ✅ Correct + + +```ts option='{"before":false,"after":false,"overrides":{"colon":{"before":true,"after":true}}}' +let foo : string = "bar"; + +function foo() : string {} + +class Foo { + name : string; +} + +type Foo = { + name : (name : string)=>string; +} + +type Foo = ()=>{}; +``` + + + +### overrides - arrow + +```json +{ + "before": false, + "after": false, + "overrides": { "arrow": { "before": true, "after": true } } +} +``` + + + +#### ❌ Incorrect + + +```ts option='{"before":false,"after":false,"overrides":{"arrow":{"before":true,"after":true}}}' +let foo: string = "bar"; +let foo : string = "bar"; +let foo :string = "bar"; + +function foo(): string {} +function foo():string {} +function foo() :string {} + +class Foo { + name: string; +} + +class Foo { + name : string; +} + +class Foo { + name :string; +} + +type Foo = ()=>{}; +type Foo = () =>{}; +type Foo = ()=> {}; +``` + +#### ✅ Correct + + +```ts option='{"before":false,"after":false,"overrides":{"arrow":{"before":true,"after":true}}}' +let foo:string = "bar"; + +function foo():string {} + +class Foo { + name:string; +} + +type Foo = () => {}; +``` + + + +## When Not To Use It + +If you don't want to enforce spacing for your type annotations, you can safely turn this rule off. + +## Further Reading + +- [TypeScript Type System](https://basarat.gitbooks.io/typescript/docs/types/type-system.html) +- [Type Inference](https://www.typescriptlang.org/docs/handbook/type-inference.html) diff --git a/docs/description/array-bracket-newline.md b/docs/description/array-bracket-newline.md new file mode 100644 index 000000000..900fea16f --- /dev/null +++ b/docs/description/array-bracket-newline.md @@ -0,0 +1,331 @@ +--- +title: array-bracket-newline +rule_type: layout +related_rules: +- array-bracket-spacing +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/array-bracket-newline) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +A number of style guides require or disallow line breaks inside of array brackets. + +## Rule Details + +This rule enforces line breaks after opening and before closing array brackets. + +## Options + +This rule has either a string option: + +* `"always"` requires line breaks inside brackets +* `"never"` disallows line breaks inside brackets +* `"consistent"` requires consistent usage of linebreaks for each pair of brackets. It reports an error if one bracket in the pair has a linebreak inside it and the other bracket does not. + +Or an object option (Requires line breaks if any of properties is satisfied. Otherwise, disallows line breaks): + +* `"multiline": true` (default) requires line breaks if there are line breaks inside elements or between elements. If this is false, this condition is disabled. +* `"minItems": null` (default) requires line breaks if the number of elements is at least the given integer. If this is 0, this condition will act the same as the option `"always"`. If this is `null` (the default), this condition is disabled. + +### always + +Examples of **incorrect** code for this rule with the `"always"` option: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", "always"]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, + 2]; +var e = [function foo() { + dosomething(); +}]; +``` + +::: + +Examples of **correct** code for this rule with the `"always"` option: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", "always"]*/ + +var a = [ +]; +var b = [ + 1 +]; +var c = [ + 1, 2 +]; +var d = [ + 1, + 2 +]; +var e = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +### never + +Examples of **incorrect** code for this rule with the `"never"` option: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", "never"]*/ + +var a = [ +]; +var b = [ + 1 +]; +var c = [ + 1, 2 +]; +var d = [ + 1, + 2 +]; +var e = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `"never"` option: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", "never"]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, + 2]; +var e = [function foo() { + dosomething(); +}]; +``` + +::: + +### consistent + +Examples of **incorrect** code for this rule with the `"consistent"` option: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", "consistent"]*/ + +var a = [1 +]; +var b = [ + 1]; +var c = [function foo() { + dosomething(); +} +] +var d = [ + function foo() { + dosomething(); + }] +``` + +::: + +Examples of **correct** code for this rule with the `"consistent"` option: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", "consistent"]*/ + +var a = []; +var b = [ +]; +var c = [1]; +var d = [ + 1 +]; +var e = [function foo() { + dosomething(); +}]; +var f = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +### multiline + +Examples of **incorrect** code for this rule with the default `{ "multiline": true }` option: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", { "multiline": true }]*/ + +var a = [ +]; +var b = [ + 1 +]; +var c = [ + 1, 2 +]; +var d = [1, + 2]; +var e = [function foo() { + dosomething(); +}]; +``` + +::: + +Examples of **correct** code for this rule with the default `{ "multiline": true }` option: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", { "multiline": true }]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [ + 1, + 2 +]; +var e = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +### minItems + +Examples of **incorrect** code for this rule with the `{ "minItems": 2 }` option: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ + +var a = [ +]; +var b = [ + 1 +]; +var c = [1, 2]; +var d = [1, + 2]; +var e = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `{ "minItems": 2 }` option: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", { "minItems": 2 }]*/ + +var a = []; +var b = [1]; +var c = [ + 1, 2 +]; +var d = [ + 1, + 2 +]; +var e = [function foo() { + dosomething(); +}]; +``` + +::: + +### multiline and minItems + +Examples of **incorrect** code for this rule with the `{ "multiline": true, "minItems": 2 }` options: + +:::incorrect + +```js +/*eslint array-bracket-newline: ["error", { "multiline": true, "minItems": 2 }]*/ + +var a = [ +]; +var b = [ + 1 +]; +var c = [1, 2]; +var d = [1, + 2]; +var e = [function foo() { + dosomething(); +}]; +``` + +::: + +Examples of **correct** code for this rule with the `{ "multiline": true, "minItems": 2 }` options: + +:::correct + +```js +/*eslint array-bracket-newline: ["error", { "multiline": true, "minItems": 2 }]*/ + +var a = []; +var b = [1]; +var c = [ + 1, 2 +]; +var d = [ + 1, + 2 +]; +var e = [ + function foo() { + dosomething(); + } +]; +``` + +::: + +## When Not To Use It + +If you don't want to enforce line breaks after opening and before closing array brackets, don't enable this rule. + +## Compatibility + +* **JSCS:** [validateNewlineAfterArrayElements](https://jscs-dev.github.io/rule/validateNewlineAfterArrayElements) diff --git a/docs/description/array-bracket-spacing.md b/docs/description/array-bracket-spacing.md new file mode 100644 index 000000000..53fa82cf5 --- /dev/null +++ b/docs/description/array-bracket-spacing.md @@ -0,0 +1,266 @@ +--- +title: array-bracket-spacing +rule_type: layout +related_rules: +- space-in-parens +- object-curly-spacing +- computed-property-spacing +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/array-bracket-spacing) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +A number of style guides require or disallow spaces between array brackets and other tokens. This rule +applies to both array literals and destructuring assignments (ECMAScript 6). + +```js +/*eslint-env es6*/ + +var arr = [ 'foo', 'bar' ]; +var [ x, y ] = z; + +var arr = ['foo', 'bar']; +var [x,y] = z; +``` + +## Rule Details + +This rule enforces consistent spacing inside array brackets. + +## Options + +This rule has a string option: + +* `"never"` (default) disallows spaces inside array brackets +* `"always"` requires one or more spaces or newlines inside array brackets + +This rule has an object option for exceptions to the `"never"` option: + +* `"singleValue": true` requires one or more spaces or newlines inside brackets of array literals that contain a single element +* `"objectsInArrays": true` requires one or more spaces or newlines between brackets of array literals and braces of their object literal elements `[ {` or `} ]` +* `"arraysInArrays": true` requires one or more spaces or newlines between brackets of array literals and brackets of their array literal elements `[ [` or `] ]` + +This rule has an object option for exceptions to the `"always"` option: + +* `"singleValue": false` disallows spaces inside brackets of array literals that contain a single element +* `"objectsInArrays": false` disallows spaces between brackets of array literals and braces of their object literal elements `[{` or `}]` +* `"arraysInArrays": false` disallows spaces between brackets of array literals and brackets of their array literal elements `[[` or `]]` + +This rule has built-in exceptions: + +* `"never"` (and also the exceptions to the `"always"` option) allows newlines inside array brackets, because this is a common pattern +* `"always"` does not require spaces or newlines in empty array literals `[]` + +### never + +Examples of **incorrect** code for this rule with the default `"never"` option: + +:::incorrect + +```js +/*eslint array-bracket-spacing: ["error", "never"]*/ +/*eslint-env es6*/ + +var arr = [ 'foo', 'bar' ]; +var arr = ['foo', 'bar' ]; +var arr = [ ['foo'], 'bar']; +var arr = [[ 'foo' ], 'bar']; +var arr = [ 'foo', + 'bar' +]; +var [ x, y ] = z; +var [ x,y ] = z; +var [ x, ...y ] = z; +var [ ,,x, ] = z; +``` + +::: + +Examples of **correct** code for this rule with the default `"never"` option: + +:::correct + +```js +/*eslint array-bracket-spacing: ["error", "never"]*/ +/*eslint-env es6*/ + +var arr = []; +var arr = ['foo', 'bar', 'baz']; +var arr = [['foo'], 'bar', 'baz']; +var arr = [ + 'foo', + 'bar', + 'baz' +]; +var arr = ['foo', + 'bar' +]; +var arr = [ + 'foo', + 'bar']; + +var [x, y] = z; +var [x,y] = z; +var [x, ...y] = z; +var [,,x,] = z; +``` + +::: + +### always + +Examples of **incorrect** code for this rule with the `"always"` option: + +:::incorrect + +```js +/*eslint array-bracket-spacing: ["error", "always"]*/ +/*eslint-env es6*/ + +var arr = ['foo', 'bar']; +var arr = ['foo', 'bar' ]; +var arr = [ ['foo'], 'bar' ]; +var arr = ['foo', + 'bar' +]; +var arr = [ + 'foo', + 'bar']; + +var [x, y] = z; +var [x,y] = z; +var [x, ...y] = z; +var [,,x,] = z; +``` + +::: + +Examples of **correct** code for this rule with the `"always"` option: + +:::correct + +```js +/*eslint array-bracket-spacing: ["error", "always"]*/ +/*eslint-env es6*/ + +var arr = []; +var arr = [ 'foo', 'bar', 'baz' ]; +var arr = [ [ 'foo' ], 'bar', 'baz' ]; +var arr = [ 'foo', + 'bar' +]; +var arr = [ + 'foo', + 'bar' ]; +var arr = [ + 'foo', + 'bar', + 'baz' +]; + +var [ x, y ] = z; +var [ x,y ] = z; +var [ x, ...y ] = z; +var [ ,,x, ] = z; +``` + +::: + +### singleValue + +Examples of **incorrect** code for this rule with the `"always", { "singleValue": false }` options: + +:::incorrect + +```js +/*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/ + +var foo = [ 'foo' ]; +var foo = [ 'foo']; +var foo = ['foo' ]; +var foo = [ 1 ]; +var foo = [ 1]; +var foo = [1 ]; +var foo = [ [ 1, 2 ] ]; +var foo = [ { 'foo': 'bar' } ]; +``` + +::: + +Examples of **correct** code for this rule with the `"always", { "singleValue": false }` options: + +:::correct + +```js +/*eslint array-bracket-spacing: ["error", "always", { "singleValue": false }]*/ + +var foo = ['foo']; +var foo = [1]; +var foo = [[ 1, 1 ]]; +var foo = [{ 'foo': 'bar' }]; +``` + +::: + +### objectsInArrays + +Examples of **incorrect** code for this rule with the `"always", { "objectsInArrays": false }` options: + +:::incorrect + +```js +/*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/ + +var arr = [ { 'foo': 'bar' } ]; +var arr = [ { + 'foo': 'bar' +} ] +``` + +::: + +Examples of **correct** code for this rule with the `"always", { "objectsInArrays": false }` options: + +:::correct + +```js +/*eslint array-bracket-spacing: ["error", "always", { "objectsInArrays": false }]*/ + +var arr = [{ 'foo': 'bar' }]; +var arr = [{ + 'foo': 'bar' +}]; +``` + +::: + +### arraysInArrays + +Examples of **incorrect** code for this rule with the `"always", { "arraysInArrays": false }` options: + +:::incorrect + +```js +/*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/ + +var arr = [ [ 1, 2 ], 2, 3, 4 ]; +var arr = [ [ 1, 2 ], 2, [ 3, 4 ] ]; +``` + +::: + +Examples of **correct** code for this rule with the `"always", { "arraysInArrays": false }` options: + +:::correct + +```js +/*eslint array-bracket-spacing: ["error", "always", { "arraysInArrays": false }]*/ + +var arr = [[ 1, 2 ], 2, 3, 4 ]; +var arr = [[ 1, 2 ], 2, [ 3, 4 ]]; +``` + +::: + +## When Not To Use It + +You can turn this rule off if you are not concerned with the consistency of spacing between array brackets. diff --git a/docs/description/array-element-newline.md b/docs/description/array-element-newline.md new file mode 100644 index 000000000..b3aa11bd2 --- /dev/null +++ b/docs/description/array-element-newline.md @@ -0,0 +1,449 @@ +--- +title: array-element-newline +rule_type: layout +related_rules: +- array-bracket-spacing +- array-bracket-newline +- object-property-newline +- object-curly-spacing +- object-curly-newline +- max-statements-per-line +- block-spacing +- brace-style +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/array-element-newline) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +A number of style guides require or disallow line breaks between array elements. + +## Rule Details + +This rule enforces line breaks between array elements. + +## Options + +This rule has either a string option: + +* `"always"` (default) requires line breaks between array elements +* `"never"` disallows line breaks between array elements +* `"consistent"` requires consistent usage of linebreaks between array elements + +Or an object option (Requires line breaks if any of properties is satisfied. Otherwise, disallows line breaks): + +* `"multiline": ` requires line breaks if there are line breaks inside elements. If this is false, this condition is disabled. +* `"minItems": ` requires line breaks if the number of elements is at least the given integer. If this is 0, this condition will act the same as the option `"always"`. If this is `null` (the default), this condition is disabled. + +Alternatively, different configurations can be specified for array expressions and array patterns: + +```json +{ + "array-element-newline": ["error", { + "ArrayExpression": "consistent", + "ArrayPattern": { "minItems": 3 }, + }] +} +``` + +* `"ArrayExpression"` configuration for array expressions (if unspecified, this rule will not apply to array expressions) +* `"ArrayPattern"` configuration for array patterns of destructuring assignments (if unspecified, this rule will not apply to array patterns) + +### always + +Examples of **incorrect** code for this rule with the default `"always"` option: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", "always"]*/ + +var c = [1, 2]; +var d = [1, 2, 3]; +var e = [1, 2, 3 +]; +var f = [ + 1, 2, 3 +]; +var g = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the default `"always"` option: + +:::correct + +```js +/*eslint array-element-newline: ["error", "always"]*/ + +var a = []; +var b = [1]; +var c = [1, + 2]; +var d = [1, + 2, + 3]; +var d = [ + 1, + 2, + 3 +]; +var e = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; +``` + +::: + +### never + +Examples of **incorrect** code for this rule with the `"never"` option: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", "never"]*/ + +var c = [ + 1, + 2 +]; +var d = [ + 1, + 2, + 3 +]; +var e = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `"never"` option: + +:::correct + +```js +/*eslint array-element-newline: ["error", "never"]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, 2, 3]; +var e = [ + 1, 2, 3]; +var f = [ + 1, 2, 3 +]; +var g = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; +``` + +::: + +### consistent + +Examples of **incorrect** code for this rule with the `"consistent"` option: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", "consistent"]*/ + +var a = [ + 1, 2, + 3 +]; +var b = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + }, + function baz() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `"consistent"` option: + +:::correct + +```js +/*eslint array-element-newline: ["error", "consistent"]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, 2, 3]; +var e = [ + 1, + 2 +]; +var f = [ + 1, + 2, + 3 +]; +var g = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + }, function baz() { + dosomething(); + } +]; +var h = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + }, + function baz() { + dosomething(); + } +]; +``` + +::: + +### multiline + +Examples of **incorrect** code for this rule with the `{ "multiline": true }` option: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", { "multiline": true }]*/ + +var d = [1, + 2, 3]; +var e = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `{ "multiline": true }` option: + +:::correct + +```js +/*eslint array-element-newline: ["error", { "multiline": true }]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, 2, 3]; +var e = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; +``` + +::: + +### minItems + +Examples of **incorrect** code for this rule with the `{ "minItems": 3 }` option: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", { "minItems": 3 }]*/ + +var c = [1, + 2]; +var d = [1, 2, 3]; +var e = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `{ "minItems": 3 }` option: + +:::correct + +```js +/*eslint array-element-newline: ["error", { "minItems": 3 }]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, + 2, + 3]; +var e = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; +``` + +::: + +### multiline and minItems + +Examples of **incorrect** code for this rule with the `{ "multiline": true, "minItems": 3 }` options: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/ + +var c = [1, +2]; +var d = [1, 2, 3]; +var e = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; +``` + +::: + +Examples of **correct** code for this rule with the `{ "multiline": true, "minItems": 3 }` options: + +:::correct + +```js +/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/ + +var a = []; +var b = [1]; +var c = [1, 2]; +var d = [1, + 2, + 3]; +var e = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; +``` + +::: + +### ArrayExpression and ArrayPattern + +Examples of **incorrect** code for this rule with the `{ "ArrayExpression": "always", "ArrayPattern": "never" }` options: + +:::incorrect + +```js +/*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/ + +var a = [1, 2]; +var b = [1, 2, 3]; +var c = [ + function foo() { + dosomething(); + }, function bar() { + dosomething(); + } +]; + +var [d, + e] = arr; +var [f, + g, + h] = arr; +var [i = function foo() { + dosomething() +}, +j = function bar() { + dosomething() +}] = arr +``` + +::: + +Examples of **correct** code for this rule with the `{ "ArrayExpression": "always", "ArrayPattern": "never" }` options: + +:::correct + +```js +/*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/ + +var a = [1, + 2]; +var b = [1, + 2, + 3]; +var c = [ + function foo() { + dosomething(); + }, + function bar() { + dosomething(); + } +]; + +var [d, e] = arr +var [f, g, h] = arr +var [i = function foo() { + dosomething() +}, j = function bar() { + dosomething() +}] = arr +``` + +::: + +## When Not To Use It + +If you don't want to enforce linebreaks between array elements, don't enable this rule. + +## Compatibility + +* **JSCS:** [validateNewlineAfterArrayElements](https://jscs-dev.github.io/rule/validateNewlineAfterArrayElements) diff --git a/docs/description/arrow-parens.md b/docs/description/arrow-parens.md new file mode 100644 index 000000000..d84e1999d --- /dev/null +++ b/docs/description/arrow-parens.md @@ -0,0 +1,254 @@ +--- +title: arrow-parens +rule_type: layout +further_reading: +- https://github.com/airbnb/javascript#arrows--one-arg-parens +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/arrow-parens) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +Arrow functions can omit parentheses when they have exactly one parameter. In all other cases the parameter(s) must +be wrapped in parentheses. This rule enforces the consistent use of parentheses in arrow functions. + +## Rule Details + +This rule enforces parentheses around arrow function parameters regardless of arity. For example: + +```js +/*eslint-env es6*/ + +// Bad +a => {} + +// Good +(a) => {} +``` + +Following this style will help you find arrow functions (`=>`) which may be mistakenly included in a condition +when a comparison such as `>=` was the intent. + +```js +/*eslint-env es6*/ + +// Bad +if (a => 2) { +} + +// Good +if (a >= 2) { +} +``` + +The rule can also be configured to discourage the use of parens when they are not required: + +```js +/*eslint-env es6*/ + +// Bad +(a) => {} + +// Good +a => {} +``` + +## Options + +This rule has a string option and an object one. + +String options are: + +* `"always"` (default) requires parens around arguments in all cases. +* `"as-needed"` enforces no parens where they can be omitted. + +Object properties for variants of the `"as-needed"` option: + +* `"requireForBlockBody": true` modifies the as-needed rule in order to require parens if the function body is in an instructions block (surrounded by braces). + +### always + +Examples of **incorrect** code for this rule with the default `"always"` option: + +:::incorrect + +```js +/*eslint arrow-parens: ["error", "always"]*/ +/*eslint-env es6*/ + +a => {}; +a => a; +a => {'\n'}; +a.then(foo => {}); +a.then(foo => a); +a(foo => { if (true) {} }); +``` + +::: + +Examples of **correct** code for this rule with the default `"always"` option: + +:::correct + +```js +/*eslint arrow-parens: ["error", "always"]*/ +/*eslint-env es6*/ + +() => {}; +(a) => {}; +(a) => a; +(a) => {'\n'} +a.then((foo) => {}); +a.then((foo) => { if (true) {} }); +``` + +::: + +#### If Statements + +One of the benefits of this option is that it prevents the incorrect use of arrow functions in conditionals: + +```js +/*eslint-env es6*/ + +var a = 1; +var b = 2; +// ... +if (a => b) { + console.log('bigger'); +} else { + console.log('smaller'); +} +// outputs 'bigger', not smaller as expected +``` + +The contents of the `if` statement is an arrow function, not a comparison. + +If the arrow function is intentional, it should be wrapped in parens to remove ambiguity. + +```js +/*eslint-env es6*/ + +var a = 1; +var b = 0; +// ... +if ((a) => b) { + console.log('truthy value returned'); +} else { + console.log('falsy value returned'); +} +// outputs 'truthy value returned' +``` + +The following is another example of this behavior: + +```js +/*eslint-env es6*/ + +var a = 1, b = 2, c = 3, d = 4; +var f = a => b ? c: d; +// f = ? +``` + +`f` is an arrow function which takes `a` as an argument and returns the result of `b ? c: d`. + +This should be rewritten like so: + +```js +/*eslint-env es6*/ + +var a = 1, b = 2, c = 3, d = 4; +var f = (a) => b ? c: d; +``` + +### as-needed + +Examples of **incorrect** code for this rule with the `"as-needed"` option: + +:::incorrect + +```js +/*eslint arrow-parens: ["error", "as-needed"]*/ +/*eslint-env es6*/ + +(a) => {}; +(a) => a; +(a) => {'\n'}; +a.then((foo) => {}); +a.then((foo) => a); +a((foo) => { if (true) {} }); +const f = /** @type {number} */(a) => a + a; +const g = /* comment */ (a) => a + a; +const h = (a) /* comment */ => a + a; +``` + +::: + +Examples of **correct** code for this rule with the `"as-needed"` option: + +:::correct + +```js +/*eslint arrow-parens: ["error", "as-needed"]*/ +/*eslint-env es6*/ + +() => {}; +a => {}; +a => a; +a => {'\n'}; +a.then(foo => {}); +a.then(foo => { if (true) {} }); +(a, b, c) => a; +(a = 10) => a; +([a, b]) => a; +({a, b}) => a; +const f = (/** @type {number} */a) => a + a; +const g = (/* comment */ a) => a + a; +const h = (a /* comment */) => a + a; +``` + +::: + +### requireForBlockBody + +Examples of **incorrect** code for the `{ "requireForBlockBody": true }` option: + +:::incorrect + +```js +/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/ +/*eslint-env es6*/ + +(a) => a; +a => {}; +a => {'\n'}; +a.map((x) => x * x); +a.map(x => { + return x * x; +}); +a.then(foo => {}); +``` + +::: + +Examples of **correct** code for the `{ "requireForBlockBody": true }` option: + +:::correct + +```js +/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/ +/*eslint-env es6*/ + +(a) => {}; +(a) => {'\n'}; +a => ({}); +() => {}; +a => a; +a.then((foo) => {}); +a.then((foo) => { if (true) {} }); +a((foo) => { if (true) {} }); +(a, b, c) => a; +(a = 10) => a; +([a, b]) => a; +({a, b}) => a; +``` + +::: diff --git a/docs/description/arrow-spacing.md b/docs/description/arrow-spacing.md new file mode 100644 index 000000000..c0e4c3e1e --- /dev/null +++ b/docs/description/arrow-spacing.md @@ -0,0 +1,122 @@ +--- +title: arrow-spacing +rule_type: layout +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/arrow-spacing) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +This rule normalize style of spacing before/after an arrow function's arrow(`=>`). + +```js +/*eslint-env es6*/ + +// { "before": true, "after": true } +(a) => {} + +// { "before": false, "after": false } +(a)=>{} +``` + +## Rule Details + +This rule takes an object argument with `before` and `after` properties, each with a Boolean value. + +The default configuration is `{ "before": true, "after": true }`. + +`true` means there should be **one or more spaces** and `false` means **no spaces**. + +Examples of **incorrect** code for this rule with the default `{ "before": true, "after": true }` option: + +:::incorrect + +```js +/*eslint arrow-spacing: "error"*/ +/*eslint-env es6*/ + +()=> {}; +() =>{}; +(a)=> {}; +(a) =>{}; +a =>a; +a=> a; +()=> {'\n'}; +() =>{'\n'}; +``` + +::: + +Examples of **correct** code for this rule with the default `{ "before": true, "after": true }` option: + +:::correct + +```js +/*eslint arrow-spacing: "error"*/ +/*eslint-env es6*/ + +() => {}; +(a) => {}; +a => a; +() => {'\n'}; +``` + +::: + +Examples of **incorrect** code for this rule with the `{ "before": false, "after": false }` option: + +:::incorrect + +```js +/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ +/*eslint-env es6*/ + +() =>{}; +(a) => {}; +()=> {'\n'}; +``` + +::: + +Examples of **correct** code for this rule with the `{ "before": false, "after": false }` option: + +:::correct + +```js +/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ +/*eslint-env es6*/ + +()=>{}; +(a)=>{}; +()=>{'\n'}; +``` + +::: + +Examples of **incorrect** code for this rule with the `{ "before": false, "after": true }` option: + +:::incorrect + +```js +/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ +/*eslint-env es6*/ + +() =>{}; +(a) => {}; +()=>{'\n'}; +``` + +::: + +Examples of **correct** code for this rule with the `{ "before": false, "after": true }` option: + +:::correct + +```js +/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ +/*eslint-env es6*/ + +()=> {}; +(a)=> {}; +()=> {'\n'}; +``` + +::: diff --git a/docs/description/block-spacing.md b/docs/description/block-spacing.md new file mode 100644 index 000000000..02aec62a6 --- /dev/null +++ b/docs/description/block-spacing.md @@ -0,0 +1,99 @@ +--- +title: block-spacing +rule_type: layout +related_rules: +- space-before-blocks +- brace-style +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/block-spacing) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +## Rule Details + +This rule enforces consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. + +## Options + +This rule has a string option: + +* `"always"` (default) requires one or more spaces +* `"never"` disallows spaces + +### always + +Examples of **incorrect** code for this rule with the default `"always"` option: + +:::incorrect + +```js +/*eslint block-spacing: "error"*/ + +function foo() {return true;} +if (foo) { bar = 0;} +function baz() {let i = 0; + return i; +} + +class C { + static {this.bar = 0;} +} +``` + +::: + +Examples of **correct** code for this rule with the default `"always"` option: + +:::correct + +```js +/*eslint block-spacing: "error"*/ + +function foo() { return true; } +if (foo) { bar = 0; } + +class C { + static { this.bar = 0; } +} +``` + +::: + +### never + +Examples of **incorrect** code for this rule with the `"never"` option: + +:::incorrect + +```js +/*eslint block-spacing: ["error", "never"]*/ + +function foo() { return true; } +if (foo) { bar = 0;} + +class C { + static { this.bar = 0; } +} +``` + +::: + +Examples of **correct** code for this rule with the `"never"` option: + +:::correct + +```js +/*eslint block-spacing: ["error", "never"]*/ + +function foo() {return true;} +if (foo) {bar = 0;} + +class C { + static {this.bar = 0;} +} +``` + +::: + +## When Not To Use It + +If you don't want to be notified about spacing style inside of blocks, you can safely disable this rule. diff --git a/docs/description/brace-style.md b/docs/description/brace-style.md new file mode 100644 index 000000000..4d3932e3c --- /dev/null +++ b/docs/description/brace-style.md @@ -0,0 +1,431 @@ +--- +title: brace-style +rule_type: layout +related_rules: +- block-spacing +- space-before-blocks +further_reading: +- https://en.wikipedia.org/wiki/Indent_style +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/brace-style) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +Brace style is closely related to [indent style](https://en.wikipedia.org/wiki/Indent_style) in programming and describes the placement of braces relative to their control statement and body. There are probably a dozen, if not more, brace styles in the world. + +The *one true brace style* is one of the most common brace styles in JavaScript, in which the opening brace of a block is placed on the same line as its corresponding statement or declaration. For example: + +```js +if (foo) { + bar(); +} else { + baz(); +} +``` + +One common variant of one true brace style is called Stroustrup, in which the `else` statements in an `if-else` construct, as well as `catch` and `finally`, must be on its own line after the preceding closing brace. For example: + +```js +if (foo) { + bar(); +} +else { + baz(); +} +``` + +Another style is called [Allman](https://en.wikipedia.org/wiki/Indent_style#Allman_style), in which all the braces are expected to be on their own lines without any extra indentation. For example: + +```js +if (foo) +{ + bar(); +} +else +{ + baz(); +} +``` + +While no style is considered better than the other, most developers agree that having a consistent style throughout a project is important for its long-term maintainability. + +## Rule Details + +This rule enforces consistent brace style for blocks. + +## Options + +This rule has a string option: + +* `"1tbs"` (default) enforces one true brace style +* `"stroustrup"` enforces Stroustrup style +* `"allman"` enforces Allman style + +This rule has an object option for an exception: + +* `"allowSingleLine": true` (default `false`) allows the opening and closing braces for a block to be on the *same* line + +### 1tbs + +Examples of **incorrect** code for this rule with the default `"1tbs"` option: + +:::incorrect + +```js +/*eslint brace-style: "error"*/ + +function foo() +{ + return true; +} + +if (foo) +{ + bar(); +} + +try +{ + somethingRisky(); +} catch(e) +{ + handleError(); +} + +if (foo) { + bar(); +} +else { + baz(); +} + +class C +{ + static + { + foo(); + } +} +``` + +::: + +Examples of **correct** code for this rule with the default `"1tbs"` option: + +:::correct + +```js +/*eslint brace-style: "error"*/ + +function foo() { + return true; +} + +if (foo) { + bar(); +} + +if (foo) { + bar(); +} else { + baz(); +} + +try { + somethingRisky(); +} catch(e) { + handleError(); +} + +class C { + static { + foo(); + } +} + +// when there are no braces, there are no problems +if (foo) bar(); +else if (baz) boom(); +``` + +::: + +Examples of **correct** code for this rule with the `"1tbs", { "allowSingleLine": true }` options: + +:::correct + +```js +/*eslint brace-style: ["error", "1tbs", { "allowSingleLine": true }]*/ + +function nop() { return; } + +if (foo) { bar(); } + +if (foo) { bar(); } else { baz(); } + +try { somethingRisky(); } catch(e) { handleError(); } + +if (foo) { baz(); } else { + boom(); +} + +if (foo) { baz(); } else if (bar) { + boom(); +} + +if (foo) { baz(); } else +if (bar) { + boom(); +} + +if (foo) { baz(); } else if (bar) { + boom(); +} + +try { somethingRisky(); } catch(e) { + handleError(); +} + +class C { + static { foo(); } +} + +class D { static { foo(); } } +``` + +::: + +### stroustrup + +Examples of **incorrect** code for this rule with the `"stroustrup"` option: + +:::incorrect + +```js +/*eslint brace-style: ["error", "stroustrup"]*/ + +function foo() +{ + return true; +} + +if (foo) +{ + bar(); +} + +try +{ + somethingRisky(); +} catch(e) +{ + handleError(); +} + +class C +{ + static + { + foo(); + } +} + +if (foo) { + bar(); +} else { + baz(); +} +``` + +::: + +Examples of **correct** code for this rule with the `"stroustrup"` option: + +:::correct + +```js +/*eslint brace-style: ["error", "stroustrup"]*/ + +function foo() { + return true; +} + +if (foo) { + bar(); +} + +if (foo) { + bar(); +} +else { + baz(); +} + +try { + somethingRisky(); +} +catch(e) { + handleError(); +} + +class C { + static { + foo(); + } +} + +// when there are no braces, there are no problems +if (foo) bar(); +else if (baz) boom(); +``` + +::: + +Examples of **correct** code for this rule with the `"stroustrup", { "allowSingleLine": true }` options: + +:::correct + +```js +/*eslint brace-style: ["error", "stroustrup", { "allowSingleLine": true }]*/ + +function nop() { return; } + +if (foo) { bar(); } + +if (foo) { bar(); } +else { baz(); } + +try { somethingRisky(); } +catch(e) { handleError(); } + +class C { + static { foo(); } +} + +class D { static { foo(); } } +``` + +::: + +### allman + +Examples of **incorrect** code for this rule with the `"allman"` option: + +:::incorrect + +```js +/*eslint brace-style: ["error", "allman"]*/ + +function foo() { + return true; +} + +if (foo) +{ + bar(); } + +try +{ + somethingRisky(); +} catch(e) +{ + handleError(); +} + +class C { + static { + foo(); + } +} + +if (foo) { + bar(); +} else { + baz(); +} +``` + +::: + +Examples of **correct** code for this rule with the `"allman"` option: + +:::correct + +```js +/*eslint brace-style: ["error", "allman"]*/ + +function foo() +{ + return true; +} + +if (foo) +{ + bar(); +} + +if (foo) +{ + bar(); +} +else +{ + baz(); +} + +try +{ + somethingRisky(); +} +catch(e) +{ + handleError(); +} + +class C +{ + static + { + foo(); + } +} + +// when there are no braces, there are no problems +if (foo) bar(); +else if (baz) boom(); +``` + +::: + +Examples of **correct** code for this rule with the `"allman", { "allowSingleLine": true }` options: + +:::correct + +```js +/*eslint brace-style: ["error", "allman", { "allowSingleLine": true }]*/ + +function nop() { return; } + +if (foo) { bar(); } + +if (foo) { bar(); } +else { baz(); } + +try { somethingRisky(); } +catch(e) { handleError(); } + +class C +{ + static { foo(); } + + static + { foo(); } +} + +class D { static { foo(); } } +``` + +::: + +## When Not To Use It + +If you don't want to enforce a particular brace style, don't enable this rule. diff --git a/docs/description/callback-return.md b/docs/description/callback-return.md new file mode 100644 index 000000000..92ec02628 --- /dev/null +++ b/docs/description/callback-return.md @@ -0,0 +1,191 @@ +--- +title: callback-return +rule_type: suggestion +related_rules: +- handle-callback-err +further_reading: +- https://github.com/maxogden/art-of-node#callbacks +- https://web.archive.org/web/20171224042620/https://docs.nodejitsu.com/articles/errors/what-are-the-error-conventions/ +--- + + +This rule was **deprecated** in ESLint v7.0.0. Please use the corresponding rule in [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n). + +The callback pattern is at the heart of most I/O and event-driven programming + in JavaScript. + +```js +function doSomething(err, callback) { + if (err) { + return callback(err); + } + callback(); +} +``` + +To prevent calling the callback multiple times it is important to `return` anytime the callback is triggered outside + of the main function body. Neglecting this technique often leads to issues where you do something more than once. + For example, in the case of an HTTP request, you may try to send HTTP headers more than once leading Node.js to `throw` + a `Can't render headers after they are sent to the client.` error. + +## Rule Details + +This rule is aimed at ensuring that callbacks used outside of the main function block are always part-of or immediately +preceding a `return` statement. This rule decides what is a callback based on the name of the function being called. + +## Options + +The rule takes a single option - an array of possible callback names - which may include object methods. The default callback names are `callback`, `cb`, `next`. + +### Default callback names + +Examples of **incorrect** code for this rule with the default `["callback", "cb", "next"]` option: + +:::incorrect + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + callback(err); + } + callback(); +} +``` + +::: + +Examples of **correct** code for this rule with the default `["callback", "cb", "next"]` option: + +:::correct + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + return callback(err); + } + callback(); +} +``` + +::: + +### Supplied callback names + +Examples of **incorrect** code for this rule with the option `["done", "send.error", "send.success"]`: + +:::incorrect + +```js +/*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/ + +function foo(err, done) { + if (err) { + done(err); + } + done(); +} + +function bar(err, send) { + if (err) { + send.error(err); + } + send.success(); +} +``` + +::: + +Examples of **correct** code for this rule with the option `["done", "send.error", "send.success"]`: + +:::correct + +```js +/*eslint callback-return: ["error", ["done", "send.error", "send.success"]]*/ + +function foo(err, done) { + if (err) { + return done(err); + } + done(); +} + +function bar(err, send) { + if (err) { + return send.error(err); + } + send.success(); +} +``` + +::: + +## Known Limitations + +Because it is difficult to understand the meaning of a program through static analysis, this rule has limitations: + +* *false negatives* when this rule reports correct code, but the program calls the callback more than one time (which is incorrect behavior) +* *false positives* when this rule reports incorrect code, but the program calls the callback only one time (which is correct behavior) + +### Passing the callback by reference + +The static analysis of this rule does not detect that the program calls the callback if it is an argument of a function (for example, `setTimeout`). + +Example of a *false negative* when this rule reports correct code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + setTimeout(callback, 0); // this is bad, but WILL NOT warn + } + callback(); +} +``` + +### Triggering the callback within a nested function + +The static analysis of this rule does not detect that the program calls the callback from within a nested function or an immediately-invoked function expression (IIFE). + +Example of a *false negative* when this rule reports correct code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + process.nextTick(function() { + return callback(); // this is bad, but WILL NOT warn + }); + } + callback(); +} +``` + +### If/else statements + +The static analysis of this rule does not detect that the program calls the callback only one time in each branch of an `if` statement. + +Example of a *false positive* when this rule reports incorrect code: + +```js +/*eslint callback-return: "error"*/ + +function foo(err, callback) { + if (err) { + callback(err); // this is fine, but WILL warn + } else { + callback(); // this is fine, but WILL warn + } +} +``` + +## When Not To Use It + +There are some cases where you might want to call a callback function more than once. In those cases this rule + may lead to incorrect behavior. In those cases you may want to reserve a special name for those callbacks and + not include that in the list of callbacks that trigger warnings. diff --git a/docs/description/comma-dangle.md b/docs/description/comma-dangle.md new file mode 100644 index 000000000..3b4e888a0 --- /dev/null +++ b/docs/description/comma-dangle.md @@ -0,0 +1,368 @@ +--- +title: comma-dangle +rule_type: layout +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/comma-dangle) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +Trailing commas in object literals are valid according to the ECMAScript 5 (and ECMAScript 3!) spec. However, IE8 (when not in IE8 document mode) and below will throw an error when it encounters trailing commas in JavaScript. + +```js +var foo = { + bar: "baz", + qux: "quux", +}; +``` + +Trailing commas simplify adding and removing items to objects and arrays, since only the lines you are modifying must be touched. +Another argument in favor of trailing commas is that it improves the clarity of diffs when an item is added or removed from an object or array: + +Less clear: + +```diff + var foo = { +- bar: "baz", +- qux: "quux" ++ bar: "baz" + }; +``` + +More clear: + +```diff + var foo = { + bar: "baz", +- qux: "quux", + }; +``` + +## Rule Details + +This rule enforces consistent use of trailing commas in object and array literals. + +## Options + +This rule has a string option or an object option: + +```json +{ + "comma-dangle": ["error", "never"], + // or + "comma-dangle": ["error", { + "arrays": "never", + "objects": "never", + "imports": "never", + "exports": "never", + "functions": "never" + }] +} +``` + +* `"never"` (default) disallows trailing commas +* `"always"` requires trailing commas +* `"always-multiline"` requires trailing commas when the last element or property is in a *different* line than the closing `]` or `}` and disallows trailing commas when the last element or property is on the *same* line as the closing `]` or `}` +* `"only-multiline"` allows (but does not require) trailing commas when the last element or property is in a *different* line than the closing `]` or `}` and disallows trailing commas when the last element or property is on the *same* line as the closing `]` or `}` + +You can also use an object option to configure this rule for each type of syntax. +Each of the following options can be set to `"never"`, `"always"`, `"always-multiline"`, `"only-multiline"`, or `"ignore"`. +The default for each option is `"never"` unless otherwise specified. + +* `arrays` is for array literals and array patterns of destructuring. (e.g. `let [a,] = [1,];`) +* `objects` is for object literals and object patterns of destructuring. (e.g. `let {a,} = {a: 1};`) +* `imports` is for import declarations of ES Modules. (e.g. `import {a,} from "foo";`) +* `exports` is for export declarations of ES Modules. (e.g. `export {a,};`) +* `functions` is for function declarations and function calls. (e.g. `(function(a,){ })(b,);`) + * `functions` should only be enabled when linting ECMAScript 2017 or higher. + +### never + +Examples of **incorrect** code for this rule with the default `"never"` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", "never"]*/ + +var foo = { + bar: "baz", + qux: "quux", +}; + +var arr = [1,2,]; + +foo({ + bar: "baz", + qux: "quux", +}); +``` + +::: + +Examples of **correct** code for this rule with the default `"never"` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", "never"]*/ + +var foo = { + bar: "baz", + qux: "quux" +}; + +var arr = [1,2]; + +foo({ + bar: "baz", + qux: "quux" +}); +``` + +::: + +### always + +Examples of **incorrect** code for this rule with the `"always"` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", "always"]*/ + +var foo = { + bar: "baz", + qux: "quux" +}; + +var arr = [1,2]; + +foo({ + bar: "baz", + qux: "quux" +}); +``` + +::: + +Examples of **correct** code for this rule with the `"always"` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", "always"]*/ + +var foo = { + bar: "baz", + qux: "quux", +}; + +var arr = [1,2,]; + +foo({ + bar: "baz", + qux: "quux", +}); +``` + +::: + +### always-multiline + +Examples of **incorrect** code for this rule with the `"always-multiline"` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", "always-multiline"]*/ + +var foo = { + bar: "baz", + qux: "quux" +}; + +var foo = { bar: "baz", qux: "quux", }; + +var arr = [1,2,]; + +var arr = [1, + 2,]; + +var arr = [ + 1, + 2 +]; + +foo({ + bar: "baz", + qux: "quux" +}); +``` + +::: + +Examples of **correct** code for this rule with the `"always-multiline"` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", "always-multiline"]*/ + +var foo = { + bar: "baz", + qux: "quux", +}; + +var foo = {bar: "baz", qux: "quux"}; +var arr = [1,2]; + +var arr = [1, + 2]; + +var arr = [ + 1, + 2, +]; + +foo({ + bar: "baz", + qux: "quux", +}); +``` + +::: + +### only-multiline + +Examples of **incorrect** code for this rule with the `"only-multiline"` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", "only-multiline"]*/ + +var foo = { bar: "baz", qux: "quux", }; + +var arr = [1,2,]; + +var arr = [1, + 2,]; + +``` + +::: + +Examples of **correct** code for this rule with the `"only-multiline"` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", "only-multiline"]*/ + +var foo = { + bar: "baz", + qux: "quux", +}; + +var foo = { + bar: "baz", + qux: "quux" +}; + +var foo = {bar: "baz", qux: "quux"}; +var arr = [1,2]; + +var arr = [1, + 2]; + +var arr = [ + 1, + 2, +]; + +var arr = [ + 1, + 2 +]; + +foo({ + bar: "baz", + qux: "quux", +}); + +foo({ + bar: "baz", + qux: "quux" +}); +``` + +::: + +### functions + +Examples of **incorrect** code for this rule with the `{"functions": "never"}` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", {"functions": "never"}]*/ + +function foo(a, b,) { +} + +foo(a, b,); +new foo(a, b,); +``` + +::: + +Examples of **correct** code for this rule with the `{"functions": "never"}` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", {"functions": "never"}]*/ + +function foo(a, b) { +} + +foo(a, b); +new foo(a, b); +``` + +::: + +Examples of **incorrect** code for this rule with the `{"functions": "always"}` option: + +:::incorrect + +```js +/*eslint comma-dangle: ["error", {"functions": "always"}]*/ + +function foo(a, b) { +} + +foo(a, b); +new foo(a, b); +``` + +::: + +Examples of **correct** code for this rule with the `{"functions": "always"}` option: + +:::correct + +```js +/*eslint comma-dangle: ["error", {"functions": "always"}]*/ + +function foo(a, b,) { +} + +foo(a, b,); +new foo(a, b,); +``` + +::: + +## When Not To Use It + +You can turn this rule off if you are not concerned with dangling commas. diff --git a/docs/description/comma-spacing.md b/docs/description/comma-spacing.md new file mode 100644 index 000000000..ffc85f27d --- /dev/null +++ b/docs/description/comma-spacing.md @@ -0,0 +1,162 @@ +--- +title: comma-spacing +rule_type: layout +related_rules: +- array-bracket-spacing +- comma-style +- object-curly-spacing +- space-in-brackets +- space-in-parens +- space-infix-ops +- space-after-keywords +- space-unary-ops +- space-return-throw-case +further_reading: +- https://www.crockford.com/code.html +- https://dojotoolkit.org/reference-guide/1.9/developer/styleguide.html +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/comma-spacing) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +Spacing around commas improves readability of a list of items. Although most of the style guidelines for languages prescribe adding a space after a comma and not before it, it is subjective to the preferences of a project. + +```js +var foo = 1, bar = 2; +var foo = 1 ,bar = 2; +``` + +## Rule Details + +This rule enforces consistent spacing before and after commas in variable declarations, array literals, object literals, function parameters, and sequences. + +This rule does not apply in either of the following cases: + +* between two commas +* between opening bracket `[` and comma, to avoid conflicts with the [`array-bracket-spacing`](array-bracket-spacing) rule +* between comma and closing bracket `]`, to avoid conflicts with the [`array-bracket-spacing`](array-bracket-spacing) rule +* between comma and closing brace `}`, to avoid conflicts with the [`object-curly-spacing`](object-curly-spacing) rule +* between comma and closing parentheses `)`, to avoid conflicts with the [`space-in-parens`](space-in-parens) rule + +## Options + +This rule has an object option: + +* `"before": false` (default) disallows spaces before commas +* `"before": true` requires one or more spaces before commas +* `"after": true` (default) requires one or more spaces after commas +* `"after": false` disallows spaces after commas + +### after + +Examples of **incorrect** code for this rule with the default `{ "before": false, "after": true }` options: + +:::incorrect + +```js +/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/ + +var foo = 1 ,bar = 2; +var arr = [1 , 2]; +var obj = {"foo": "bar" ,"baz": "qur"}; +foo(a ,b); +new Foo(a ,b); +function baz(a ,b){} +a ,b +``` + +::: + +Examples of **correct** code for this rule with the default `{ "before": false, "after": true }` options: + +:::correct + +```js +/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/ + +var foo = 1, bar = 2 + , baz = 3; +var arr = [1, 2]; +var arr = [1,, 3] +var obj = {"foo": "bar", "baz": "qur"}; +foo(a, b); +new Foo(a, b); +function qur(a, b){} +a, b +``` + +::: + +Additional examples of **correct** code for this rule with the default `{ "before": false, "after": true }` options: + +:::correct + +```js +/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/ + +// this rule does not enforce spacing between two commas +var arr = [ + ,, + , , +]; + +// this rule does not enforce spacing after `[` and before `]` +var arr = [,]; +var arr = [ , ]; +var arr = [a, b,]; +[,] = arr; +[ , ] = arr; +[a, b,] = arr; + +// this rule does not enforce spacing before `}` +var obj = {x, y,}; +var {z, q,} = obj; +import {foo, bar,} from "mod"; + +// this rule does not enforce spacing before `)` +foo(a, b,) +``` + +::: + +### before + +Examples of **incorrect** code for this rule with the `{ "before": true, "after": false }` options: + +:::incorrect + +```js +/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/ + +var foo = 1, bar = 2; +var arr = [1 , 2]; +var obj = {"foo": "bar", "baz": "qur"}; +new Foo(a,b); +function baz(a,b){} +a, b +``` + +::: + +Examples of **correct** code for this rule with the `{ "before": true, "after": false }` options: + +:::correct + +```js +/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/ + +var foo = 1 ,bar = 2 , + baz = true; +var arr = [1 ,2]; +var arr = [1 ,,3] +var obj = {"foo": "bar" ,"baz": "qur"}; +foo(a ,b); +new Foo(a ,b); +function qur(a ,b){} +a ,b +``` + +::: + +## When Not To Use It + +If your project will not be following a consistent comma-spacing pattern, turn this rule off. diff --git a/docs/description/comma-style.md b/docs/description/comma-style.md new file mode 100644 index 000000000..ee2438376 --- /dev/null +++ b/docs/description/comma-style.md @@ -0,0 +1,191 @@ +--- +title: comma-style +rule_type: layout +related_rules: +- operator-linebreak +further_reading: +- https://gist.github.com/isaacs/357981 +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/comma-style) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +The Comma Style rule enforces styles for comma-separated lists. There are two comma styles primarily used in JavaScript: + +* The standard style, in which commas are placed at the end of the current line +* Comma First style, in which commas are placed at the start of the next line + +One of the justifications for using Comma First style is that it can help track missing and trailing commas. These are problematic because missing commas in variable declarations can lead to the leakage of global variables and trailing commas can lead to errors in older versions of IE. + +## Rule Details + +This rule enforce consistent comma style in array literals, object literals, and variable declarations. + +This rule does not apply in either of the following cases: + +* comma preceded and followed by linebreak (lone comma) +* single-line array literals, object literals, and variable declarations + +## Options + +This rule has a string option: + +* `"last"` (default) requires a comma after and on the same line as an array element, object property, or variable declaration +* `"first"` requires a comma before and on the same line as an array element, object property, or variable declaration + +This rule also accepts an additional `exceptions` object: + +* `"exceptions"` has properties whose names correspond to node types in the abstract syntax tree (AST) of JavaScript code: + + * `"ArrayExpression": true` ignores comma style in array literals + * `"ArrayPattern": true` ignores comma style in array patterns of destructuring + * `"ArrowFunctionExpression": true` ignores comma style in the parameters of arrow function expressions + * `"CallExpression": true` ignores comma style in the arguments of function calls + * `"FunctionDeclaration": true` ignores comma style in the parameters of function declarations + * `"FunctionExpression": true` ignores comma style in the parameters of function expressions + * `"ImportDeclaration": true` ignores comma style in the specifiers of import declarations + * `"ObjectExpression": true` ignores comma style in object literals + * `"ObjectPattern": true` ignores comma style in object patterns of destructuring + * `"VariableDeclaration": true` ignores comma style in variable declarations + * `"NewExpression": true` ignores comma style in the parameters of constructor expressions + +A way to determine the node types as defined by [ESTree](https://github.com/estree/estree) is to use [AST Explorer](https://astexplorer.net/) with the espree parser. + +### last + +Examples of **incorrect** code for this rule with the default `"last"` option: + +:::incorrect + +```js +/*eslint comma-style: ["error", "last"]*/ + +var foo = 1 +, +bar = 2; + +var foo = 1 + , bar = 2; + +var foo = ["apples" + , "oranges"]; + +function baz() { + return { + "a": 1 + ,"b:": 2 + }; +} +``` + +::: + +Examples of **correct** code for this rule with the default `"last"` option: + +:::correct + +```js +/*eslint comma-style: ["error", "last"]*/ + +var foo = 1, bar = 2; + +var foo = 1, + bar = 2; + +var foo = ["apples", + "oranges"]; + +function baz() { + return { + "a": 1, + "b:": 2 + }; +} +``` + +::: + +### first + +Examples of **incorrect** code for this rule with the `"first"` option: + +:::incorrect + +```js +/*eslint comma-style: ["error", "first"]*/ + +var foo = 1, + bar = 2; + +var foo = ["apples", + "oranges"]; + +function baz() { + return { + "a": 1, + "b:": 2 + }; +} +``` + +::: + +Examples of **correct** code for this rule with the `"first"` option: + +:::correct + +```js +/*eslint comma-style: ["error", "first"]*/ + +var foo = 1, bar = 2; + +var foo = 1 + ,bar = 2; + +var foo = ["apples" + ,"oranges"]; + +function baz() { + return { + "a": 1 + ,"b:": 2 + }; +} +``` + +::: + +### exceptions + +An example use case is to enforce comma style *only* in var statements. + +Examples of **incorrect** code for this rule with sample `"first", { "exceptions": { … } }` options: + +:::incorrect + +```js +/*eslint comma-style: ["error", "first", { "exceptions": { "ArrayExpression": true, "ObjectExpression": true } }]*/ + +var o = {}, + a = []; +``` + +::: + +Examples of **correct** code for this rule with sample `"first", { "exceptions": { … } }` options: + +:::correct + +```js +/*eslint comma-style: ["error", "first", { "exceptions": { "ArrayExpression": true, "ObjectExpression": true } }]*/ + +var o = {fst:1, + snd: [1, + 2]} + , a = []; +``` + +::: + +## When Not To Use It + +This rule can safely be turned off if your project does not care about enforcing a consistent comma style. diff --git a/docs/description/computed-property-spacing.md b/docs/description/computed-property-spacing.md new file mode 100644 index 000000000..8e8b2d5ab --- /dev/null +++ b/docs/description/computed-property-spacing.md @@ -0,0 +1,210 @@ +--- +title: computed-property-spacing +rule_type: layout +related_rules: +- array-bracket-spacing +- comma-spacing +- space-in-parens +--- + +This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding rule](https://eslint.style/rules/js/computed-property-spacing) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js). + +While formatting preferences are very personal, a number of style guides require +or disallow spaces between computed properties in the following situations: + +```js +/*eslint-env es6*/ + +var obj = { prop: "value" }; +var a = "prop"; +var x = obj[a]; // computed property in object member expression + +var a = "prop"; +var obj = { + [a]: "value" // computed property key in object literal (ECMAScript 6) +}; + +var obj = { prop: "value" }; +var a = "prop"; +var { [a]: x } = obj; // computed property key in object destructuring pattern (ECMAScript 6) +``` + +## Rule Details + +This rule enforces consistent spacing inside computed property brackets. + +It either requires or disallows spaces between the brackets and the values inside of them. +This rule does not apply to brackets that are separated from the adjacent value by a newline. + +## Options + +This rule has two options, a string option and an object option. + +String option: + +* `"never"` (default) disallows spaces inside computed property brackets +* `"always"` requires one or more spaces inside computed property brackets + +Object option: + +* `"enforceForClassMembers": true` (default) additionally applies this rule to class members. + +### never + +Examples of **incorrect** code for this rule with the default `"never"` option: + +::: incorrect + +```js +/*eslint computed-property-spacing: ["error", "never"]*/ +/*eslint-env es6*/ + +obj[foo ] +obj[ 'foo'] +var x = {[ b ]: a} +obj[foo[ bar ]] + +const { [ a ]: someProp } = obj; +({ [ b ]: anotherProp } = anotherObj); +``` + +::: + +Examples of **correct** code for this rule with the default `"never"` option: + +::: correct + +```js +/*eslint computed-property-spacing: ["error", "never"]*/ +/*eslint-env es6*/ + +obj[foo] +obj['foo'] +var x = {[b]: a} +obj[foo[bar]] + +const { [a]: someProp } = obj; +({ [b]: anotherProp } = anotherObj); +``` + +::: + +### always + +Examples of **incorrect** code for this rule with the `"always"` option: + +::: incorrect + +```js +/*eslint computed-property-spacing: ["error", "always"]*/ +/*eslint-env es6*/ + +obj[foo] +var x = {[b]: a} +obj[ foo] +obj['foo' ] +obj[foo[ bar ]] +var x = {[ b]: a} +const { [a]: someProp } = obj; +({ [b ]: anotherProp } = anotherObj); +``` + +::: + +Examples of **correct** code for this rule with the `"always"` option: + +::: correct + +```js +/*eslint computed-property-spacing: ["error", "always"]*/ +/*eslint-env es6*/ + +obj[ foo ] +obj[ 'foo' ] +var x = {[ b ]: a} +obj[ foo[ bar ] ] +const { [ a ]: someProp } = obj; +({ [ b ]: anotherProp } = anotherObj); +``` + +::: + +#### enforceForClassMembers + +With `enforceForClassMembers` set to `true` (default), the rule also disallows/enforces spaces inside of computed keys of class methods, getters and setters. + +Examples of **incorrect** code for this rule with `"never"` and `{ "enforceForClassMembers": true }` (default): + +::: incorrect + +```js +/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/ +/*eslint-env es6*/ + +class Foo { + [a ]() {} + get [b ]() {} + set [b ](value) {} +} + +const Bar = class { + [ a](){} + static [ b]() {} + static get [ c ]() {} + static set [ c ](value) {} +} +``` + +::: + +Examples of **correct** code for this rule with `"never"` and `{ "enforceForClassMembers": true }` (default): + +::: correct + +```js +/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/ +/*eslint-env es6*/ + +class Foo { + [a]() {} + get [b]() {} + set [b](value) {} +} + +const Bar = class { + [a](){} + static [b]() {} + static get [c]() {} + static set [c](value) {} +} +``` + +::: + +Examples of **correct** code for this rule with `"never"` and `{ "enforceForClassMembers": false }`: + +::: correct + +```js +/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": false }]*/ +/*eslint-env es6*/ + +class Foo { + [a ]() {} + get [b ]() {} + set [b ](value) {} +} + +const Bar = class { + [ a](){} + static [ b]() {} + static get [ c ]() {} + static set [ c ](value) {} +} +``` + +::: + +## When Not To Use It + +You can turn this rule off if you are not concerned with the consistency of computed properties. diff --git a/docs/description/description.json b/docs/description/description.json index c3c58790f..795000d1e 100644 --- a/docs/description/description.json +++ b/docs/description/description.json @@ -19,6 +19,20 @@ "description": "Enforce getter and setter pairs in objects and classes", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "array-bracket-newline", + "title": "Array bracket newline", + "description": "Enforce linebreaks after opening and before closing array brackets", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "array-bracket-spacing", + "title": "Array bracket spacing", + "description": "Enforce consistent spacing inside array brackets", + "timeToFix": 5 + }, { "parameters": [ { @@ -39,6 +53,13 @@ "description": "Enforce `return` statements in callbacks of array methods", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "array-element-newline", + "title": "Array element newline", + "description": "Enforce line breaks after each array element", + "timeToFix": 5 + }, { "parameters": [], "patternId": "arrow-body-style", @@ -46,6 +67,34 @@ "description": "Require braces around arrow function bodies", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "requireForBlockBody", + "description": "requireForBlockBody" + } + ], + "patternId": "arrow-parens", + "title": "Arrow parens", + "description": "Require parentheses around arrow function arguments", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "arrow-spacing", + "title": "Arrow spacing", + "description": "Enforce consistent spacing before and after the arrow in arrow functions", + "timeToFix": 5 + }, { "parameters": [], "patternId": "block-scoped-var", @@ -53,6 +102,32 @@ "description": "Enforce the use of variables within the scope they are defined", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "block-spacing", + "title": "Block spacing", + "description": "Disallow or enforce spaces inside of blocks after opening block and before closing block", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "allowSingleLine", + "description": "allowSingleLine" + } + ], + "patternId": "brace-style", + "title": "Brace style", + "description": "Enforce consistent brace style for blocks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "callback-return", + "title": "Callback return", + "description": "Require `return` statements after callbacks", + "timeToFix": 5 + }, { "parameters": [ { @@ -92,6 +167,36 @@ "description": "Enforce that class methods utilize `this`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "comma-dangle", + "title": "Comma dangle", + "description": "Require or disallow trailing commas", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "comma-spacing", + "title": "Comma spacing", + "description": "Enforce consistent spacing before and after commas", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "comma-style", + "title": "Comma style", + "description": "Enforce consistent comma style", + "timeToFix": 5 + }, { "parameters": [ { @@ -104,6 +209,18 @@ "description": "Enforce a maximum cyclomatic complexity allowed in a program", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "enforceForClassMembers", + "description": "enforceForClassMembers" + } + ], + "patternId": "computed-property-spacing", + "title": "Computed property spacing", + "description": "Enforce consistent spacing inside computed property brackets", + "timeToFix": 5 + }, { "parameters": [ { @@ -168,6 +285,13 @@ "description": "Enforce default parameters to be last", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "dot-location", + "title": "Dot location", + "description": "Enforce consistent newlines before and after dots", + "timeToFix": 5 + }, { "parameters": [ { @@ -184,6 +308,13 @@ "description": "Enforce dot notation whenever possible", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "eol-last", + "title": "Eol last", + "description": "Require or disallow newline at the end of files", + "timeToFix": 5 + }, { "parameters": [ { @@ -203,6 +334,13 @@ "description": "Enforce \"for\" loop update clause moving the counter in the right direction", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "func-call-spacing", + "title": "Func call spacing", + "description": "Require or disallow spacing between function identifiers and their invocations", + "timeToFix": 5 + }, { "parameters": [], "patternId": "func-name-matching", @@ -233,6 +371,27 @@ "description": "Enforce the consistent use of either `function` declarations or expressions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "function-call-argument-newline", + "title": "Function call argument newline", + "description": "Enforce line breaks between arguments of a function call", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "function-paren-newline", + "title": "Function paren newline", + "description": "Enforce consistent line breaks inside function parentheses", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "generator-star-spacing", + "title": "Generator star spacing", + "description": "Enforce consistent spacing around `*` operators in generator functions", + "timeToFix": 5 + }, { "parameters": [ { @@ -245,6 +404,13 @@ "description": "Enforce `return` statements in getters", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "global-require", + "title": "Global require", + "description": "Require `require()` calls to be placed at top-level module scope", + "timeToFix": 5 + }, { "parameters": [], "patternId": "grouped-accessor-pairs", @@ -259,6 +425,20 @@ "description": "Require `for-in` loops to include an `if` statement", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "handle-callback-err", + "title": "Handle callback err", + "description": "Require error handling in callbacks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "id-blacklist", + "title": "Id blacklist", + "description": "Disallow specified identifiers", + "timeToFix": 5 + }, { "parameters": [], "patternId": "id-denylist", @@ -306,6 +486,44 @@ "description": "Require identifiers to match a specified regular expression", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "implicit-arrow-linebreak", + "title": "Implicit arrow linebreak", + "description": "Enforce the location of arrow function bodies", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "SwitchCase", + "description": "SwitchCase" + }, + { + "name": "flatTernaryExpressions", + "description": "flatTernaryExpressions" + }, + { + "name": "offsetTernaryExpressions", + "description": "offsetTernaryExpressions" + }, + { + "name": "ignoreComments", + "description": "ignoreComments" + } + ], + "patternId": "indent", + "title": "Indent", + "description": "Enforce consistent indentation", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "indent-legacy", + "title": "Indent legacy", + "description": "Enforce consistent indentation", + "timeToFix": 5 + }, { "parameters": [ { @@ -318,6 +536,36 @@ "description": "Require or disallow initialization in variable declarations", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "jsx-quotes", + "title": "Jsx quotes", + "description": "Enforce the consistent use of either double or single quotes in JSX attributes", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "key-spacing", + "title": "Key spacing", + "description": "Enforce consistent spacing between keys and values in object literal properties", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "keyword-spacing", + "title": "Keyword spacing", + "description": "Enforce consistent spacing before and after keywords", + "timeToFix": 5 + }, { "parameters": [], "patternId": "line-comment-position", @@ -325,6 +573,68 @@ "description": "Enforce position of line comments", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "linebreak-style", + "title": "Linebreak style", + "description": "Enforce consistent linebreak style", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "beforeBlockComment", + "description": "beforeBlockComment" + }, + { + "name": "afterBlockComment", + "description": "afterBlockComment" + }, + { + "name": "beforeLineComment", + "description": "beforeLineComment" + }, + { + "name": "afterLineComment", + "description": "afterLineComment" + }, + { + "name": "allowBlockStart", + "description": "allowBlockStart" + }, + { + "name": "allowBlockEnd", + "description": "allowBlockEnd" + }, + { + "name": "afterHashbangComment", + "description": "afterHashbangComment" + } + ], + "patternId": "lines-around-comment", + "title": "Lines around comment", + "description": "Require empty lines around comments", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "lines-around-directive", + "title": "Lines around directive", + "description": "Require or disallow newlines around directives", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "exceptAfterSingleLine", + "description": "exceptAfterSingleLine" + } + ], + "patternId": "lines-between-class-members", + "title": "Lines between class members", + "description": "Require or disallow an empty line between class members", + "timeToFix": 5 + }, { "parameters": [], "patternId": "logical-assignment-operators", @@ -346,6 +656,13 @@ "description": "Enforce a maximum depth that blocks can be nested", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "max-len", + "title": "Max len", + "description": "Enforce a maximum line length", + "timeToFix": 5 + }, { "parameters": [], "patternId": "max-lines", @@ -386,6 +703,18 @@ "description": "Enforce a maximum number of statements allowed in function blocks", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "max", + "description": "max" + } + ], + "patternId": "max-statements-per-line", + "title": "Max statements per line", + "description": "Enforce a maximum number of statements allowed per line", + "timeToFix": 5 + }, { "parameters": [], "patternId": "multiline-comment-style", @@ -393,6 +722,13 @@ "description": "Enforce a particular style for multiline comments", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "multiline-ternary", + "title": "Multiline ternary", + "description": "Enforce newlines between operands of ternary expressions", + "timeToFix": 5 + }, { "parameters": [ { @@ -413,6 +749,44 @@ "description": "Require constructor names to begin with a capital letter", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "new-parens", + "title": "New parens", + "description": "Enforce or disallow parentheses when invoking a constructor with no arguments", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "unnamedParam", + "description": "unnamedParam" + } + ], + "patternId": "newline-after-var", + "title": "Newline after var", + "description": "Require or disallow an empty line after variable declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "newline-before-return", + "title": "Newline before return", + "description": "Require an empty line before `return` statements", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "ignoreChainWithDepth", + "description": "ignoreChainWithDepth" + } + ], + "patternId": "newline-per-chained-call", + "title": "Newline per chained call", + "description": "Require a newline after each call in a method chain", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-alert", @@ -453,6 +827,13 @@ "description": "Disallow bitwise operators", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-buffer-constructor", + "title": "No buffer constructor", + "description": "Disallow use of the `Buffer()` constructor", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-caller", @@ -467,6 +848,13 @@ "description": "Disallow lexical declarations in case clauses", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-catch-shadow", + "title": "No catch shadow", + "description": "Disallow `catch` clause parameters from shadowing variables in the outer scope", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-class-assign", @@ -493,6 +881,22 @@ "description": "Disallow assignment operators in conditional expressions", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "allowParens", + "description": "allowParens" + }, + { + "name": "onlyOneSimpleParam", + "description": "onlyOneSimpleParam" + } + ], + "patternId": "no-confusing-arrow", + "title": "No confusing arrow", + "description": "Disallow arrow functions where they could be confused with comparisons", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-console", @@ -731,6 +1135,20 @@ "description": "Disallow unnecessary labels", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-extra-parens", + "title": "No extra parens", + "description": "Disallow unnecessary parentheses", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-extra-semi", + "title": "No extra semi", + "description": "Disallow unnecessary semicolons", + "timeToFix": 5 + }, { "parameters": [ { @@ -747,6 +1165,13 @@ "description": "Disallow fallthrough of `case` statements", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-floating-decimal", + "title": "No floating decimal", + "description": "Disallow leading or trailing decimal points in numeric literals", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-func-assign", @@ -970,6 +1395,32 @@ "description": "Disallow characters which are made with multiple code points in character class syntax", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "allowSamePrecedence", + "description": "allowSamePrecedence" + } + ], + "patternId": "no-mixed-operators", + "title": "No mixed operators", + "description": "Disallow mixed binary operators", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-mixed-requires", + "title": "No mixed requires", + "description": "Disallow `require` calls to be mixed with regular variable declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-mixed-spaces-and-tabs", + "title": "No mixed spaces and tabs", + "description": "Disallow mixed spaces and tabs for indentation", + "timeToFix": 5 + }, { "parameters": [ { @@ -982,6 +1433,18 @@ "description": "Disallow use of chained assignment expressions", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "ignoreEOLComments", + "description": "ignoreEOLComments" + } + ], + "patternId": "no-multi-spaces", + "title": "No multi spaces", + "description": "Disallow multiple spaces", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-multi-str", @@ -989,6 +1452,20 @@ "description": "Disallow multiline strings", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-multiple-empty-lines", + "title": "No multiple empty lines", + "description": "Disallow multiple empty lines", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-native-reassign", + "title": "No native reassign", + "description": "Disallow assignments to native objects or read-only global variables", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-negated-condition", @@ -996,6 +1473,13 @@ "description": "Disallow negated conditions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-negated-in-lhs", + "title": "No negated in lhs", + "description": "Disallow negating the left operand in `in` expressions", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-nested-ternary", @@ -1024,6 +1508,20 @@ "description": "Disallow `new` operators with global non-constructor functions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-new-object", + "title": "No new object", + "description": "Disallow `Object` constructors", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-new-require", + "title": "No new require", + "description": "Disallow `new` operators with calls to `require`", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-new-symbol", @@ -1080,6 +1578,13 @@ "description": "Disallow reassigning `function` parameters", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-path-concat", + "title": "No path concat", + "description": "Disallow string concatenation with `__dirname` and `__filename`", + "timeToFix": 5 + }, { "parameters": [ { @@ -1092,6 +1597,20 @@ "description": "Disallow the unary operators `++` and `--`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-process-env", + "title": "No process env", + "description": "Disallow the use of `process.env`", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "no-process-exit", + "title": "No process exit", + "description": "Disallow the use of `process.exit()`", + "timeToFix": 5 + }, { "parameters": [ { @@ -1158,6 +1677,18 @@ "description": "Disallow specified modules when loaded by `import`", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "unnamedParam", + "description": "unnamedParam" + } + ], + "patternId": "no-restricted-modules", + "title": "No restricted modules", + "description": "Disallow specified modules when loaded by `require`", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-restricted-properties", @@ -1184,6 +1715,13 @@ "description": "Disallow assignment operators in `return` statements", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-return-await", + "title": "No return await", + "description": "Disallow unnecessary `return await`", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-script-url", @@ -1256,6 +1794,13 @@ "description": "Disallow identifiers from shadowing restricted names", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-spaced-func", + "title": "No spaced func", + "description": "Disallow spacing between function identifiers and their applications (deprecated)", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-sparse-arrays", @@ -1263,6 +1808,30 @@ "description": "Disallow sparse arrays", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "allowAtRootLevel", + "description": "allowAtRootLevel" + } + ], + "patternId": "no-sync", + "title": "No sync", + "description": "Disallow synchronous methods", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "allowIndentationTabs", + "description": "allowIndentationTabs" + } + ], + "patternId": "no-tabs", + "title": "No tabs", + "description": "Disallow all tabs", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-template-curly-in-string", @@ -1291,6 +1860,22 @@ "description": "Disallow throwing literals as exceptions", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "skipBlankLines", + "description": "skipBlankLines" + }, + { + "name": "ignoreComments", + "description": "ignoreComments" + } + ], + "patternId": "no-trailing-spaces", + "title": "No trailing spaces", + "description": "Disallow trailing whitespace at the end of lines", + "timeToFix": 5 + }, { "parameters": [ { @@ -1587,6 +2172,13 @@ "description": "Disallow specified warning terms in comments", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "no-whitespace-before-property", + "title": "No whitespace before property", + "description": "Disallow whitespace before properties", + "timeToFix": 5 + }, { "parameters": [], "patternId": "no-with", @@ -1594,6 +2186,43 @@ "description": "Disallow `with` statements", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "nonblock-statement-body-position", + "title": "Nonblock statement body position", + "description": "Enforce the location of single-line statements", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "object-curly-newline", + "title": "Object curly newline", + "description": "Enforce consistent line breaks after opening and before closing braces", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "object-curly-spacing", + "title": "Object curly spacing", + "description": "Enforce consistent spacing inside braces", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "allowAllPropertiesOnSameLine", + "description": "allowAllPropertiesOnSameLine" + }, + { + "name": "allowMultiplePropertiesPerLine", + "description": "allowMultiplePropertiesPerLine" + } + ], + "patternId": "object-property-newline", + "title": "Object property newline", + "description": "Enforce placing object properties on separate lines", + "timeToFix": 5 + }, { "parameters": [], "patternId": "object-shorthand", @@ -1613,6 +2242,13 @@ "description": "Enforce variables to be declared either together or separately in functions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "one-var-declaration-per-line", + "title": "One var declaration per line", + "description": "Require or disallow newlines around variable declarations", + "timeToFix": 5 + }, { "parameters": [], "patternId": "operator-assignment", @@ -1620,6 +2256,27 @@ "description": "Require or disallow assignment operator shorthand where possible", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "operator-linebreak", + "title": "Operator linebreak", + "description": "Enforce consistent linebreak style for operators", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "padded-blocks", + "title": "Padded blocks", + "description": "Require or disallow padding within blocks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "padding-line-between-statements", + "title": "Padding line between statements", + "description": "Require or disallow padding lines between statements", + "timeToFix": 5 + }, { "parameters": [ { @@ -1706,6 +2363,13 @@ "description": "Require using Error objects as Promise rejection reasons", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "prefer-reflect", + "title": "Prefer reflect", + "description": "Require `Reflect` methods where applicable", + "timeToFix": 5 + }, { "parameters": [ { @@ -1739,6 +2403,20 @@ "description": "Require template literals instead of string concatenation", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "quote-props", + "title": "Quote props", + "description": "Require quotes around object literal property names", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "quotes", + "title": "Quotes", + "description": "Enforce the consistent use of either backticks, double, or single quotes", + "timeToFix": 5 + }, { "parameters": [], "patternId": "radix", @@ -1765,6 +2443,18 @@ "description": "Disallow async functions which have no `await` expression", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "require", + "description": "require" + } + ], + "patternId": "require-jsdoc", + "title": "Require jsdoc", + "description": "Require JSDoc comments", + "timeToFix": 5 + }, { "parameters": [], "patternId": "require-unicode-regexp", @@ -1779,6 +2469,43 @@ "description": "Require generator functions to contain `yield`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "rest-spread-spacing", + "title": "Rest spread spacing", + "description": "Enforce spacing between rest and spread operators and their expressions", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "semi", + "title": "Semi", + "description": "Require or disallow semicolons instead of ASI", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "semi-spacing", + "title": "Semi spacing", + "description": "Enforce consistent spacing before and after semicolons", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "semi-style", + "title": "Semi style", + "description": "Enforce location of semicolons", + "timeToFix": 5 + }, { "parameters": [ { @@ -1843,6 +2570,62 @@ "description": "Require variables within the same declaration block to be sorted", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "space-before-blocks", + "title": "Space before blocks", + "description": "Enforce consistent spacing before blocks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "space-before-function-paren", + "title": "Space before function paren", + "description": "Enforce consistent spacing before `function` definition opening parenthesis", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "space-in-parens", + "title": "Space in parens", + "description": "Enforce consistent spacing inside parentheses", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "int32Hint", + "description": "int32Hint" + } + ], + "patternId": "space-infix-ops", + "title": "Space infix ops", + "description": "Require spacing around infix operators", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "words", + "description": "words" + }, + { + "name": "nonwords", + "description": "nonwords" + } + ], + "patternId": "space-unary-ops", + "title": "Space unary ops", + "description": "Enforce consistent spacing before or after unary operators", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "spaced-comment", + "title": "Spaced comment", + "description": "Enforce consistent spacing after the `//` or `/*` in a comment", + "timeToFix": 5 + }, { "parameters": [ { @@ -1855,6 +2638,22 @@ "description": "Require or disallow strict mode directives", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "switch-colon-spacing", + "title": "Switch colon spacing", + "description": "Enforce spacing around colons of switch statements", + "timeToFix": 5 + }, { "parameters": [], "patternId": "symbol-description", @@ -1862,6 +2661,20 @@ "description": "Require symbol descriptions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "template-curly-spacing", + "title": "Template curly spacing", + "description": "Require or disallow spacing around embedded expressions of template strings", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "template-tag-spacing", + "title": "Template tag spacing", + "description": "Require or disallow spacing between template tags and their literals", + "timeToFix": 5 + }, { "parameters": [], "patternId": "unicode-bom", @@ -1885,6 +2698,34 @@ "description": "Require calls to `isNaN()` when checking for `NaN`", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "requireReturn", + "description": "requireReturn" + }, + { + "name": "requireParamDescription", + "description": "requireParamDescription" + }, + { + "name": "requireReturnDescription", + "description": "requireReturnDescription" + }, + { + "name": "requireReturnType", + "description": "requireReturnType" + }, + { + "name": "requireParamType", + "description": "requireParamType" + } + ], + "patternId": "valid-jsdoc", + "title": "Valid jsdoc", + "description": "Enforce valid JSDoc comments", + "timeToFix": 5 + }, { "parameters": [ { @@ -1904,6 +2745,32 @@ "description": "Require `var` declarations be placed at the top of their containing scope", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "functionPrototypeMethods", + "description": "functionPrototypeMethods" + } + ], + "patternId": "wrap-iife", + "title": "Wrap iife", + "description": "Require parentheses around immediate `function` invocations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "wrap-regex", + "title": "Wrap regex", + "description": "Require parenthesis around regex literals", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "yield-star-spacing", + "title": "Yield star spacing", + "description": "Require or disallow spacing around the `*` in `yield*` expressions", + "timeToFix": 5 + }, { "parameters": [ { @@ -2125,6 +2992,13 @@ "description": "Ensures component, directive and pipe `standalone` property is set to `true` in the component decorator", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@angular-eslint_prefer-standalone-component", + "title": "@angular eslint: Prefer standalone component", + "description": "Ensures component `standalone` property is set to `true` in the component decorator", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@angular-eslint_prefer-output-readonly", @@ -2162,6 +3036,18 @@ "description": "Ensures that lifecycle methods are declared in order of execution", "timeToFix": 5 }, + { + "parameters": [ + { + "name": "locale", + "description": "locale" + } + ], + "patternId": "@angular-eslint_sort-ngmodule-metadata-arrays", + "title": "@angular eslint: Sort ngmodule metadata arrays", + "description": "Ensures ASC alphabetical order for `NgModule` metadata arrays for easy visual scanning", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@angular-eslint_use-component-selector", @@ -2265,6 +3151,20 @@ "description": "Disallow unused expressions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@babel_object-curly-spacing", + "title": "@babel: Object curly spacing", + "description": "Enforce consistent spacing inside braces", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@babel_semi", + "title": "@babel: Semi", + "description": "Require or disallow semicolons instead of ASI", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@lwc_lwc_consistent-component-name", @@ -2314,6 +3214,13 @@ "description": "Disallow DOM query at the document level.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@lwc_lwc_no-dupe-class-members", + "title": "@lwc: [Lwc] No dupe class members", + "description": "Disallow duplicate class members", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@lwc_lwc_no-for-of", @@ -3635,6 +4542,13 @@ "description": "Enforce line breaks before and after JSX elements when they are used as arguments to a function.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@stylistic_jsx-indent", + "title": "@stylistic: Jsx indent", + "description": "Enforce JSX indentation. Deprecated, use `indent` rule instead.", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@stylistic_jsx-indent-props", @@ -3835,6 +4749,25 @@ "description": "Disallow certain types", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_block-spacing", + "title": "@typescript eslint: Block spacing", + "description": "Disallow or enforce spaces inside of blocks after opening block and before closing block", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "allowSingleLine", + "description": "allowSingleLine" + } + ], + "patternId": "@typescript-eslint_brace-style", + "title": "@typescript eslint: Brace style", + "description": "Enforce consistent brace style for blocks", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_class-literal-property-style", @@ -3854,6 +4787,29 @@ "description": "Enforce that class methods utilize `this`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_comma-dangle", + "title": "@typescript eslint: Comma dangle", + "description": "Require or disallow trailing commas", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "@typescript-eslint_comma-spacing", + "title": "@typescript eslint: Comma spacing", + "description": "Enforce consistent spacing before and after commas", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_consistent-generic-constructors", @@ -3951,24 +4907,133 @@ "timeToFix": 5 }, { - "parameters": [], - "patternId": "@typescript-eslint_explicit-module-boundary-types", - "title": "@typescript eslint: Explicit module boundary types", - "description": "Require explicit return and argument types on exported functions' and classes' public class methods", + "parameters": [], + "patternId": "@typescript-eslint_explicit-module-boundary-types", + "title": "@typescript eslint: Explicit module boundary types", + "description": "Require explicit return and argument types on exported functions' and classes' public class methods", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_func-call-spacing", + "title": "@typescript eslint: Func call spacing", + "description": "Require or disallow spacing between function identifiers and their invocations", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "SwitchCase", + "description": "SwitchCase" + }, + { + "name": "flatTernaryExpressions", + "description": "flatTernaryExpressions" + }, + { + "name": "offsetTernaryExpressions", + "description": "offsetTernaryExpressions" + }, + { + "name": "ignoreComments", + "description": "ignoreComments" + } + ], + "patternId": "@typescript-eslint_indent", + "title": "@typescript eslint: Indent", + "description": "Enforce consistent indentation", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_init-declarations", + "title": "@typescript eslint: Init declarations", + "description": "Require or disallow initialization in variable declarations", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_key-spacing", + "title": "@typescript eslint: Key spacing", + "description": "Enforce consistent spacing between property names and type annotations in types and interfaces", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "before", + "description": "before" + }, + { + "name": "after", + "description": "after" + } + ], + "patternId": "@typescript-eslint_keyword-spacing", + "title": "@typescript eslint: Keyword spacing", + "description": "Enforce consistent spacing before and after keywords", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "beforeBlockComment", + "description": "beforeBlockComment" + }, + { + "name": "afterBlockComment", + "description": "afterBlockComment" + }, + { + "name": "beforeLineComment", + "description": "beforeLineComment" + }, + { + "name": "afterLineComment", + "description": "afterLineComment" + }, + { + "name": "allowBlockStart", + "description": "allowBlockStart" + }, + { + "name": "allowBlockEnd", + "description": "allowBlockEnd" + } + ], + "patternId": "@typescript-eslint_lines-around-comment", + "title": "@typescript eslint: Lines around comment", + "description": "Require empty lines around comments", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "exceptAfterSingleLine", + "description": "exceptAfterSingleLine" + }, + { + "name": "exceptAfterOverload", + "description": "exceptAfterOverload" + } + ], + "patternId": "@typescript-eslint_lines-between-class-members", + "title": "@typescript eslint: Lines between class members", + "description": "Require or disallow an empty line between class members", "timeToFix": 5 }, { "parameters": [], - "patternId": "@typescript-eslint_init-declarations", - "title": "@typescript eslint: Init declarations", - "description": "Require or disallow initialization in variable declarations", + "patternId": "@typescript-eslint_max-params", + "title": "@typescript eslint: Max params", + "description": "Enforce a maximum number of parameters in function definitions", "timeToFix": 5 }, { "parameters": [], - "patternId": "@typescript-eslint_max-params", - "title": "@typescript eslint: Max params", - "description": "Enforce a maximum number of parameters in function definitions", + "patternId": "@typescript-eslint_member-delimiter-style", + "title": "@typescript eslint: Member delimiter style", + "description": "Require a specific member delimiter style for interfaces and type literals", "timeToFix": 5 }, { @@ -4090,6 +5155,20 @@ "description": "Disallow extra non-null assertions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_no-extra-parens", + "title": "@typescript eslint: No extra parens", + "description": "Disallow unnecessary parentheses", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_no-extra-semi", + "title": "@typescript eslint: No extra semi", + "description": "Disallow unnecessary semicolons", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_no-extraneous-class", @@ -4296,6 +5375,20 @@ "description": "Disallow aliasing `this`", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_no-throw-literal", + "title": "@typescript eslint: No throw literal", + "description": "Disallow throwing literals as exceptions", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_no-type-alias", + "title": "@typescript eslint: No type alias", + "description": "Disallow type aliases", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_no-unnecessary-boolean-literal-compare", @@ -4474,6 +5567,13 @@ "description": "Disallow empty exports that don't change anything in a module file", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_no-useless-template-literals", + "title": "@typescript eslint: No useless template literals", + "description": "Disallow unnecessary template expressions", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_no-var-requires", @@ -4495,6 +5595,13 @@ "description": "Enforce non-null assertions over explicit type casts", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_object-curly-spacing", + "title": "@typescript eslint: Object curly spacing", + "description": "Enforce consistent spacing inside braces", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_only-throw-error", @@ -4502,6 +5609,13 @@ "description": "Disallow throwing non-`Error` values as exceptions", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_padding-line-between-statements", + "title": "@typescript eslint: Padding line between statements", + "description": "Require or disallow padding lines between statements", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_parameter-properties", @@ -4635,6 +5749,13 @@ "description": "Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_prefer-ts-expect-error", + "title": "@typescript eslint: Prefer ts expect error", + "description": "Enforce using `@ts-expect-error` over `@ts-ignore`", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_promise-function-async", @@ -4642,6 +5763,13 @@ "description": "Require any function or method that returns a Promise to be marked async", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_quotes", + "title": "@typescript eslint: Quotes", + "description": "Enforce the consistent use of either backticks, double, or single quotes", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_require-array-sort-compare", @@ -4677,6 +5805,46 @@ "description": "Enforce consistent awaiting of returned promises", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_semi", + "title": "@typescript eslint: Semi", + "description": "Require or disallow semicolons instead of ASI", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_sort-type-constituents", + "title": "@typescript eslint: Sort type constituents", + "description": "Enforce constituents of a type union/intersection to be sorted alphabetically", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_space-before-blocks", + "title": "@typescript eslint: Space before blocks", + "description": "Enforce consistent spacing before blocks", + "timeToFix": 5 + }, + { + "parameters": [], + "patternId": "@typescript-eslint_space-before-function-paren", + "title": "@typescript eslint: Space before function paren", + "description": "Enforce consistent spacing before function parenthesis", + "timeToFix": 5 + }, + { + "parameters": [ + { + "name": "int32Hint", + "description": "int32Hint" + } + ], + "patternId": "@typescript-eslint_space-infix-ops", + "title": "@typescript eslint: Space infix ops", + "description": "Require spacing around infix operators", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_strict-boolean-expressions", @@ -4698,6 +5866,13 @@ "description": "Disallow certain triple slash directives in favor of ES6-style import declarations", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "@typescript-eslint_type-annotation-spacing", + "title": "@typescript eslint: Type annotation spacing", + "description": "Require consistent spacing around type annotations", + "timeToFix": 5 + }, { "parameters": [], "patternId": "@typescript-eslint_typedef", @@ -8530,6 +9705,12 @@ "title": "Flowtype: Use read only spread", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "flowtype_valid-syntax", + "title": "Flowtype: Valid syntax", + "timeToFix": 5 + }, { "parameters": [], "patternId": "formatjs_blocklist-elements", @@ -8815,6 +9996,13 @@ "description": "Prefer property signatures over method signatures.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "functional_prefer-readonly-type", + "title": "Functional: Prefer readonly type", + "description": "Prefer readonly types over mutable types.", + "timeToFix": 5 + }, { "parameters": [], "patternId": "functional_prefer-tacit", @@ -9181,6 +10369,13 @@ "description": "Forbid imported names marked with `@deprecated` documentation tag.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "import_imports-first", + "title": "Import: Imports first", + "description": "Replaced by `import/first`.", + "timeToFix": 5 + }, { "parameters": [], "patternId": "import-alias_import-alias", @@ -11103,6 +12298,13 @@ "title": "Jsx: No undef", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "jsx-a11y_accessible-emoji", + "title": "Jsx a11y: Accessible emoji", + "description": "Enforce emojis are wrapped in `` and provide screen reader access.", + "timeToFix": 5 + }, { "parameters": [], "patternId": "jsx-a11y_alt-text", @@ -11234,6 +12436,13 @@ "description": "Enforce that a `label` tag has a text label and an associated control.", "timeToFix": 5 }, + { + "parameters": [], + "patternId": "jsx-a11y_label-has-for", + "title": "Jsx a11y: Label has for", + "description": "Enforce that `