Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/rules/no-implicit-any-catch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |

<!-- end auto-generated rule options list -->

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
{
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-implicit-any-catch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;

Expand Down
240 changes: 6 additions & 234 deletions tests/rules/no-implicit-any-catch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
Expand All @@ -83,7 +83,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
catchError((error: any) => console.error(error))
);
`,
options: [{ allowExplicitAny: true }],
},
{
code: stripIndent`
Expand All @@ -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`
Expand All @@ -110,15 +108,14 @@ 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(
undefined,
(error: any) => console.error(error)
);
`,
options: [{ allowExplicitAny: true }],
},
{
code: stripIndent`
Expand All @@ -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`
Expand All @@ -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";

Expand All @@ -164,7 +160,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
(error: any) => console.error(error)
));
`,
options: [{ allowExplicitAny: true }],
},
{
code: stripIndent`
Expand All @@ -179,15 +174,14 @@ 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";

throwError("Kaboom!").pipe(tap({
error: (error: any) => console.error(error)
}));
`,
options: [{ allowExplicitAny: true }],
},
{
code: stripIndent`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down