diff --git a/docs/rules/no-implicit-any-catch.md b/docs/rules/no-implicit-any-catch.md index 059cbdef..93c08042 100644 --- a/docs/rules/no-implicit-any-catch.md +++ b/docs/rules/no-implicit-any-catch.md @@ -74,11 +74,11 @@ throwError(() => new Error("Kaboom!")).pipe( | Name | Description | Type | Default | | :----------------- | :---------------------------------------------------- | :------ | :------ | -| `allowExplicitAny` | Allow error variable to be explicitly typed as `any`. | Boolean | `false` | +| `allowExplicitAny` | Allow error variable to be explicitly typed as `any`. | Boolean | `true` | -This rule accepts a single option which is an object with an `allowExplicitAny` property that determines whether or not the error variable can be explicitly typed as `any`. By default, the use of explicit `any` is forbidden. +This rule accepts a single option which is an object with an `allowExplicitAny` property that determines whether or not the error variable can be explicitly typed as `any`. By default, the use of explicit `any` is allowed. ```json { diff --git a/src/rules/no-implicit-any-catch.ts b/src/rules/no-implicit-any-catch.ts index 5c74081b..75c6c99f 100644 --- a/src/rules/no-implicit-any-catch.ts +++ b/src/rules/no-implicit-any-catch.ts @@ -59,7 +59,7 @@ export const noImplicitAnyCatchRule = ruleCreator({ allowExplicitAny: { type: 'boolean', description: 'Allow error variable to be explicitly typed as `any`.', - default: false, + default: true, }, }, type: 'object', @@ -70,7 +70,7 @@ export const noImplicitAnyCatchRule = ruleCreator({ name: 'no-implicit-any-catch', create: (context) => { const [config = {}] = context.options; - const { allowExplicitAny = false } = config; + const { allowExplicitAny = true } = config; const { couldBeObservable } = getTypeServices(context); const sourceCode = context.sourceCode; diff --git a/tests/rules/no-implicit-any-catch.test.ts b/tests/rules/no-implicit-any-catch.test.ts index d4c37ca8..2e9cac6f 100644 --- a/tests/rules/no-implicit-any-catch.test.ts +++ b/tests/rules/no-implicit-any-catch.test.ts @@ -59,7 +59,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, catchError((error: unknown) => console.error(error)) ); `, - options: [{ allowExplicitAny: false }], + options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -71,7 +71,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, catchError(function (error: unknown) { console.error(error); }) ); `, - options: [{ allowExplicitAny: false }], + options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -83,7 +83,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, catchError((error: any) => console.error(error)) ); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -95,7 +94,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, catchError(function (error: any) { console.error(error); }) ); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -110,7 +108,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, }, { code: stripIndent` - // subscribe; arrow; explicit any + // subscribe; arrow; explicit any; default option import { throwError } from "rxjs"; throwError("Kaboom!").subscribe( @@ -118,7 +116,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, (error: any) => console.error(error) ); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -132,14 +129,13 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, }, { code: stripIndent` - // subscribe observer; arrow; explicit any + // subscribe observer; arrow; explicit any; default option import { throwError } from "rxjs"; throwError("Kaboom!").subscribe({ error: (error: any) => console.error(error) }); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -155,7 +151,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, }, { code: stripIndent` - // tap; arrow; explicit any + // tap; arrow; explicit any; default option import { throwError } from "rxjs"; import { tap } from "rxjs/operators"; @@ -164,7 +160,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, (error: any) => console.error(error) )); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -179,7 +174,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, }, { code: stripIndent` - // tap observer; arrow; explicit any + // tap observer; arrow; explicit any; default option import { throwError } from "rxjs"; import { tap } from "rxjs/operators"; @@ -187,7 +182,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, error: (error: any) => console.error(error) })); `, - options: [{ allowExplicitAny: true }], }, { code: stripIndent` @@ -315,80 +309,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, ], }, ), - fromFixture( - stripIndent` - // arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError((error: any) => console.error(error)) - ~~~~~~~~~~ [explicitAny suggest] - ); - `, - { - output: stripIndent` - // arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError((error: unknown) => console.error(error)) - ); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError((error: unknown) => console.error(error)) - ); - `, - }, - ], - }, - ), - fromFixture( - stripIndent` - // non-arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError(function (error: any) { console.error(error); }) - ~~~~~~~~~~ [explicitAny suggest] - ); - `, - { - output: stripIndent` - // non-arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError(function (error: unknown) { console.error(error); }) - ); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // non-arrow; explicit any; default option - import { throwError } from "rxjs"; - import { catchError } from "rxjs/operators"; - - throwError("Kaboom!").pipe( - catchError(function (error: unknown) { console.error(error); }) - ); - `, - }, - ], - }, - ), fromFixture( stripIndent` // arrow; explicit any; explicit option @@ -595,43 +515,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, ], }, ), - fromFixture( - stripIndent` - // subscribe; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe( - undefined, - (error: any) => console.error(error) - ~~~~~~~~~~ [explicitAny suggest] - ); - `, - { - output: stripIndent` - // subscribe; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe( - undefined, - (error: unknown) => console.error(error) - ); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // subscribe; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe( - undefined, - (error: unknown) => console.error(error) - ); - `, - }, - ], - }, - ), fromFixture( stripIndent` // subscribe; arrow; explicit any; explicit option @@ -766,40 +649,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, ], }, ), - fromFixture( - stripIndent` - // subscribe observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe({ - error: (error: any) => console.error(error) - ~~~~~~~~~~ [explicitAny suggest] - }); - `, - { - output: stripIndent` - // subscribe observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe({ - error: (error: unknown) => console.error(error) - }); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // subscribe observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - - throwError("Kaboom!").subscribe({ - error: (error: unknown) => console.error(error) - }); - `, - }, - ], - }, - ), fromFixture( stripIndent` // subscribe observer; arrow; explicit any; explicit option @@ -941,46 +790,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, ], }, ), - fromFixture( - stripIndent` - // tap; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap( - undefined, - (error: any) => console.error(error) - ~~~~~~~~~~ [explicitAny suggest] - )); - `, - { - output: stripIndent` - // tap; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap( - undefined, - (error: unknown) => console.error(error) - )); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // tap; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap( - undefined, - (error: unknown) => console.error(error) - )); - `, - }, - ], - }, - ), fromFixture( stripIndent` // tap; arrow; explicit any; explicit option @@ -1126,43 +935,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule, ], }, ), - fromFixture( - stripIndent` - // tap observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap({ - error: (error: any) => console.error(error) - ~~~~~~~~~~ [explicitAny suggest] - })); - `, - { - output: stripIndent` - // tap observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap({ - error: (error: unknown) => console.error(error) - })); - `, - suggestions: [ - { - messageId: 'suggestExplicitUnknown', - output: stripIndent` - // tap observer; arrow; explicit any; default option - import { throwError } from "rxjs"; - import { tap } from "rxjs/operators"; - - throwError("Kaboom!").pipe(tap({ - error: (error: unknown) => console.error(error) - })); - `, - }, - ], - }, - ), fromFixture( stripIndent` // tap observer; arrow; explicit any; explicit option