1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | Object.defineProperty(exports, "__esModule", { value: true });
|
22 | const util = __importStar(require("../util"));
|
23 | const utils_1 = require("@typescript-eslint/utils");
|
24 | exports.default = util.createRule({
|
25 | name: 'no-implicit-any-catch',
|
26 | meta: {
|
27 | deprecated: true,
|
28 | type: 'suggestion',
|
29 | docs: {
|
30 | description: 'Disallow usage of the implicit `any` type in catch clauses',
|
31 | recommended: false,
|
32 | suggestion: true,
|
33 | },
|
34 | fixable: 'code',
|
35 | hasSuggestions: true,
|
36 | messages: {
|
37 | implicitAnyInCatch: 'Implicit any in catch clause.',
|
38 | explicitAnyInCatch: 'Explicit any in catch clause.',
|
39 | suggestExplicitUnknown: 'Use `unknown` instead, this will force you to explicitly, and safely assert the type is correct.',
|
40 | },
|
41 | schema: [
|
42 | {
|
43 | type: 'object',
|
44 | additionalProperties: false,
|
45 | properties: {
|
46 | allowExplicitAny: {
|
47 | type: 'boolean',
|
48 | },
|
49 | },
|
50 | },
|
51 | ],
|
52 | },
|
53 | defaultOptions: [
|
54 | {
|
55 | allowExplicitAny: false,
|
56 | },
|
57 | ],
|
58 | create(context, [{ allowExplicitAny }]) {
|
59 | return {
|
60 | CatchClause(node) {
|
61 | if (!node.param) {
|
62 | return;
|
63 | }
|
64 | if (!node.param.typeAnnotation) {
|
65 | context.report({
|
66 | node,
|
67 | messageId: 'implicitAnyInCatch',
|
68 | suggest: [
|
69 | {
|
70 | messageId: 'suggestExplicitUnknown',
|
71 | fix(fixer) {
|
72 | return fixer.insertTextAfter(node.param, ': unknown');
|
73 | },
|
74 | },
|
75 | ],
|
76 | });
|
77 | }
|
78 | else if (!allowExplicitAny &&
|
79 | node.param.typeAnnotation.typeAnnotation.type ===
|
80 | utils_1.AST_NODE_TYPES.TSAnyKeyword) {
|
81 | context.report({
|
82 | node,
|
83 | messageId: 'explicitAnyInCatch',
|
84 | suggest: [
|
85 | {
|
86 | messageId: 'suggestExplicitUnknown',
|
87 | fix(fixer) {
|
88 | return fixer.replaceText(node.param.typeAnnotation, ': unknown');
|
89 | },
|
90 | },
|
91 | ],
|
92 | });
|
93 | }
|
94 | },
|
95 | };
|
96 | },
|
97 | });
|
98 |
|
\ | No newline at end of file |