Skip to content

Commit d32e3e4

Browse files
feat(no-implicit-any-catch)!: default to allow explicit any
BREAKING CHANGE: allowExplicitAny now defaults to `true` instead of `false. This change was made to align with other rules in this codebase dealing with explicit `any` (namely `throw-error`). Additionally, lax codebases commonly turn on this setting, or else turn off this rule entirely. By relaxing the default options, developers will be encouraged to use this rule, and stricter codebases can re-opt-in to banning `any`. The upcoming `strict` config will set this option back to `false` accordingly.
1 parent a722e58 commit d32e3e4

File tree

3 files changed

+10
-238
lines changed

3 files changed

+10
-238
lines changed

docs/rules/no-implicit-any-catch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ throwError(() => new Error("Kaboom!")).pipe(
7474

7575
| Name | Description | Type | Default |
7676
| :----------------- | :---------------------------------------------------- | :------ | :------ |
77-
| `allowExplicitAny` | Allow error variable to be explicitly typed as `any`. | Boolean | `false` |
77+
| `allowExplicitAny` | Allow error variable to be explicitly typed as `any`. | Boolean | `true` |
7878

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

81-
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.
81+
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.
8282

8383
```json
8484
{

src/rules/no-implicit-any-catch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const noImplicitAnyCatchRule = ruleCreator({
5959
allowExplicitAny: {
6060
type: 'boolean',
6161
description: 'Allow error variable to be explicitly typed as `any`.',
62-
default: false,
62+
default: true,
6363
},
6464
},
6565
type: 'object',
@@ -70,7 +70,7 @@ export const noImplicitAnyCatchRule = ruleCreator({
7070
name: 'no-implicit-any-catch',
7171
create: (context) => {
7272
const [config = {}] = context.options;
73-
const { allowExplicitAny = false } = config;
73+
const { allowExplicitAny = true } = config;
7474
const { couldBeObservable } = getTypeServices(context);
7575
const sourceCode = context.sourceCode;
7676

tests/rules/no-implicit-any-catch.test.ts

Lines changed: 6 additions & 234 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
5959
catchError((error: unknown) => console.error(error))
6060
);
6161
`,
62-
options: [{ allowExplicitAny: false }],
62+
options: [{ allowExplicitAny: true }],
6363
},
6464
{
6565
code: stripIndent`
@@ -71,7 +71,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
7171
catchError(function (error: unknown) { console.error(error); })
7272
);
7373
`,
74-
options: [{ allowExplicitAny: false }],
74+
options: [{ allowExplicitAny: true }],
7575
},
7676
{
7777
code: stripIndent`
@@ -83,7 +83,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
8383
catchError((error: any) => console.error(error))
8484
);
8585
`,
86-
options: [{ allowExplicitAny: true }],
8786
},
8887
{
8988
code: stripIndent`
@@ -95,7 +94,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
9594
catchError(function (error: any) { console.error(error); })
9695
);
9796
`,
98-
options: [{ allowExplicitAny: true }],
9997
},
10098
{
10199
code: stripIndent`
@@ -110,15 +108,14 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
110108
},
111109
{
112110
code: stripIndent`
113-
// subscribe; arrow; explicit any
111+
// subscribe; arrow; explicit any; default option
114112
import { throwError } from "rxjs";
115113
116114
throwError("Kaboom!").subscribe(
117115
undefined,
118116
(error: any) => console.error(error)
119117
);
120118
`,
121-
options: [{ allowExplicitAny: true }],
122119
},
123120
{
124121
code: stripIndent`
@@ -132,14 +129,13 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
132129
},
133130
{
134131
code: stripIndent`
135-
// subscribe observer; arrow; explicit any
132+
// subscribe observer; arrow; explicit any; default option
136133
import { throwError } from "rxjs";
137134
138135
throwError("Kaboom!").subscribe({
139136
error: (error: any) => console.error(error)
140137
});
141138
`,
142-
options: [{ allowExplicitAny: true }],
143139
},
144140
{
145141
code: stripIndent`
@@ -155,7 +151,7 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
155151
},
156152
{
157153
code: stripIndent`
158-
// tap; arrow; explicit any
154+
// tap; arrow; explicit any; default option
159155
import { throwError } from "rxjs";
160156
import { tap } from "rxjs/operators";
161157
@@ -164,7 +160,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
164160
(error: any) => console.error(error)
165161
));
166162
`,
167-
options: [{ allowExplicitAny: true }],
168163
},
169164
{
170165
code: stripIndent`
@@ -179,15 +174,14 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
179174
},
180175
{
181176
code: stripIndent`
182-
// tap observer; arrow; explicit any
177+
// tap observer; arrow; explicit any; default option
183178
import { throwError } from "rxjs";
184179
import { tap } from "rxjs/operators";
185180
186181
throwError("Kaboom!").pipe(tap({
187182
error: (error: any) => console.error(error)
188183
}));
189184
`,
190-
options: [{ allowExplicitAny: true }],
191185
},
192186
{
193187
code: stripIndent`
@@ -315,80 +309,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
315309
],
316310
},
317311
),
318-
fromFixture(
319-
stripIndent`
320-
// arrow; explicit any; default option
321-
import { throwError } from "rxjs";
322-
import { catchError } from "rxjs/operators";
323-
324-
throwError("Kaboom!").pipe(
325-
catchError((error: any) => console.error(error))
326-
~~~~~~~~~~ [explicitAny suggest]
327-
);
328-
`,
329-
{
330-
output: stripIndent`
331-
// arrow; explicit any; default option
332-
import { throwError } from "rxjs";
333-
import { catchError } from "rxjs/operators";
334-
335-
throwError("Kaboom!").pipe(
336-
catchError((error: unknown) => console.error(error))
337-
);
338-
`,
339-
suggestions: [
340-
{
341-
messageId: 'suggestExplicitUnknown',
342-
output: stripIndent`
343-
// arrow; explicit any; default option
344-
import { throwError } from "rxjs";
345-
import { catchError } from "rxjs/operators";
346-
347-
throwError("Kaboom!").pipe(
348-
catchError((error: unknown) => console.error(error))
349-
);
350-
`,
351-
},
352-
],
353-
},
354-
),
355-
fromFixture(
356-
stripIndent`
357-
// non-arrow; explicit any; default option
358-
import { throwError } from "rxjs";
359-
import { catchError } from "rxjs/operators";
360-
361-
throwError("Kaboom!").pipe(
362-
catchError(function (error: any) { console.error(error); })
363-
~~~~~~~~~~ [explicitAny suggest]
364-
);
365-
`,
366-
{
367-
output: stripIndent`
368-
// non-arrow; explicit any; default option
369-
import { throwError } from "rxjs";
370-
import { catchError } from "rxjs/operators";
371-
372-
throwError("Kaboom!").pipe(
373-
catchError(function (error: unknown) { console.error(error); })
374-
);
375-
`,
376-
suggestions: [
377-
{
378-
messageId: 'suggestExplicitUnknown',
379-
output: stripIndent`
380-
// non-arrow; explicit any; default option
381-
import { throwError } from "rxjs";
382-
import { catchError } from "rxjs/operators";
383-
384-
throwError("Kaboom!").pipe(
385-
catchError(function (error: unknown) { console.error(error); })
386-
);
387-
`,
388-
},
389-
],
390-
},
391-
),
392312
fromFixture(
393313
stripIndent`
394314
// arrow; explicit any; explicit option
@@ -595,43 +515,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
595515
],
596516
},
597517
),
598-
fromFixture(
599-
stripIndent`
600-
// subscribe; arrow; explicit any; default option
601-
import { throwError } from "rxjs";
602-
603-
throwError("Kaboom!").subscribe(
604-
undefined,
605-
(error: any) => console.error(error)
606-
~~~~~~~~~~ [explicitAny suggest]
607-
);
608-
`,
609-
{
610-
output: stripIndent`
611-
// subscribe; arrow; explicit any; default option
612-
import { throwError } from "rxjs";
613-
614-
throwError("Kaboom!").subscribe(
615-
undefined,
616-
(error: unknown) => console.error(error)
617-
);
618-
`,
619-
suggestions: [
620-
{
621-
messageId: 'suggestExplicitUnknown',
622-
output: stripIndent`
623-
// subscribe; arrow; explicit any; default option
624-
import { throwError } from "rxjs";
625-
626-
throwError("Kaboom!").subscribe(
627-
undefined,
628-
(error: unknown) => console.error(error)
629-
);
630-
`,
631-
},
632-
],
633-
},
634-
),
635518
fromFixture(
636519
stripIndent`
637520
// subscribe; arrow; explicit any; explicit option
@@ -766,40 +649,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
766649
],
767650
},
768651
),
769-
fromFixture(
770-
stripIndent`
771-
// subscribe observer; arrow; explicit any; default option
772-
import { throwError } from "rxjs";
773-
774-
throwError("Kaboom!").subscribe({
775-
error: (error: any) => console.error(error)
776-
~~~~~~~~~~ [explicitAny suggest]
777-
});
778-
`,
779-
{
780-
output: stripIndent`
781-
// subscribe observer; arrow; explicit any; default option
782-
import { throwError } from "rxjs";
783-
784-
throwError("Kaboom!").subscribe({
785-
error: (error: unknown) => console.error(error)
786-
});
787-
`,
788-
suggestions: [
789-
{
790-
messageId: 'suggestExplicitUnknown',
791-
output: stripIndent`
792-
// subscribe observer; arrow; explicit any; default option
793-
import { throwError } from "rxjs";
794-
795-
throwError("Kaboom!").subscribe({
796-
error: (error: unknown) => console.error(error)
797-
});
798-
`,
799-
},
800-
],
801-
},
802-
),
803652
fromFixture(
804653
stripIndent`
805654
// subscribe observer; arrow; explicit any; explicit option
@@ -941,46 +790,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
941790
],
942791
},
943792
),
944-
fromFixture(
945-
stripIndent`
946-
// tap; arrow; explicit any; default option
947-
import { throwError } from "rxjs";
948-
import { tap } from "rxjs/operators";
949-
950-
throwError("Kaboom!").pipe(tap(
951-
undefined,
952-
(error: any) => console.error(error)
953-
~~~~~~~~~~ [explicitAny suggest]
954-
));
955-
`,
956-
{
957-
output: stripIndent`
958-
// tap; arrow; explicit any; default option
959-
import { throwError } from "rxjs";
960-
import { tap } from "rxjs/operators";
961-
962-
throwError("Kaboom!").pipe(tap(
963-
undefined,
964-
(error: unknown) => console.error(error)
965-
));
966-
`,
967-
suggestions: [
968-
{
969-
messageId: 'suggestExplicitUnknown',
970-
output: stripIndent`
971-
// tap; arrow; explicit any; default option
972-
import { throwError } from "rxjs";
973-
import { tap } from "rxjs/operators";
974-
975-
throwError("Kaboom!").pipe(tap(
976-
undefined,
977-
(error: unknown) => console.error(error)
978-
));
979-
`,
980-
},
981-
],
982-
},
983-
),
984793
fromFixture(
985794
stripIndent`
986795
// tap; arrow; explicit any; explicit option
@@ -1126,43 +935,6 @@ ruleTester({ types: true }).run('no-implicit-any-catch', noImplicitAnyCatchRule,
1126935
],
1127936
},
1128937
),
1129-
fromFixture(
1130-
stripIndent`
1131-
// tap observer; arrow; explicit any; default option
1132-
import { throwError } from "rxjs";
1133-
import { tap } from "rxjs/operators";
1134-
1135-
throwError("Kaboom!").pipe(tap({
1136-
error: (error: any) => console.error(error)
1137-
~~~~~~~~~~ [explicitAny suggest]
1138-
}));
1139-
`,
1140-
{
1141-
output: stripIndent`
1142-
// tap observer; arrow; explicit any; default option
1143-
import { throwError } from "rxjs";
1144-
import { tap } from "rxjs/operators";
1145-
1146-
throwError("Kaboom!").pipe(tap({
1147-
error: (error: unknown) => console.error(error)
1148-
}));
1149-
`,
1150-
suggestions: [
1151-
{
1152-
messageId: 'suggestExplicitUnknown',
1153-
output: stripIndent`
1154-
// tap observer; arrow; explicit any; default option
1155-
import { throwError } from "rxjs";
1156-
import { tap } from "rxjs/operators";
1157-
1158-
throwError("Kaboom!").pipe(tap({
1159-
error: (error: unknown) => console.error(error)
1160-
}));
1161-
`,
1162-
},
1163-
],
1164-
},
1165-
),
1166938
fromFixture(
1167939
stripIndent`
1168940
// tap observer; arrow; explicit any; explicit option

0 commit comments

Comments
 (0)