eslint-plugin-jest 27.2.1 → 27.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +1 -1
  2. package/docs/rules/no-alias-methods.md +1 -1
  3. package/docs/rules/no-hooks.md +1 -1
  4. package/docs/rules/no-large-snapshots.md +4 -0
  5. package/docs/rules/require-hook.md +2 -6
  6. package/docs/rules/valid-expect.md +2 -2
  7. package/lib/index.js +2 -0
  8. package/lib/processors/__tests__/snapshot-processor.test.js +36 -0
  9. package/lib/rules/__tests__/consistent-test-it.test.js +921 -0
  10. package/lib/rules/__tests__/expect-expect.test.js +347 -0
  11. package/lib/rules/__tests__/fixtures/class.ts +13 -0
  12. package/lib/rules/__tests__/fixtures/file.ts +0 -0
  13. package/lib/rules/__tests__/fixtures/foo.ts +1 -0
  14. package/lib/rules/__tests__/fixtures/indent/indent-invalid-fixture-1.js +530 -0
  15. package/lib/rules/__tests__/fixtures/indent/indent-valid-fixture-1.js +530 -0
  16. package/lib/rules/__tests__/fixtures/react.tsx +0 -0
  17. package/lib/rules/__tests__/fixtures/tsconfig-withmeta.json +6 -0
  18. package/lib/rules/__tests__/fixtures/tsconfig.json +16 -0
  19. package/lib/rules/__tests__/fixtures/unstrict/file.ts +0 -0
  20. package/lib/rules/__tests__/fixtures/unstrict/react.tsx +0 -0
  21. package/lib/rules/__tests__/fixtures/unstrict/tsconfig.json +15 -0
  22. package/lib/rules/__tests__/max-expects.test.js +330 -0
  23. package/lib/rules/__tests__/max-nested-describe.test.js +247 -0
  24. package/lib/rules/__tests__/no-alias-methods.test.js +190 -0
  25. package/lib/rules/__tests__/no-commented-out-tests.test.js +213 -0
  26. package/lib/rules/__tests__/no-conditional-expect.test.js +696 -0
  27. package/lib/rules/__tests__/no-conditional-in-test.test.js +777 -0
  28. package/lib/rules/__tests__/no-deprecated-functions.test.js +119 -0
  29. package/lib/rules/__tests__/no-disabled-tests.test.js +241 -0
  30. package/lib/rules/__tests__/no-done-callback.test.js +424 -0
  31. package/lib/rules/__tests__/no-duplicate-hooks.test.js +469 -0
  32. package/lib/rules/__tests__/no-export.test.js +107 -0
  33. package/lib/rules/__tests__/no-focused-tests.test.js +373 -0
  34. package/lib/rules/__tests__/no-hooks.test.js +90 -0
  35. package/lib/rules/__tests__/no-identical-title.test.js +270 -0
  36. package/lib/rules/__tests__/no-if.test.js +787 -0
  37. package/lib/rules/__tests__/no-interpolation-in-snapshots.test.js +58 -0
  38. package/lib/rules/__tests__/no-jasmine-globals.test.js +206 -0
  39. package/lib/rules/__tests__/no-large-snapshots.test.js +237 -0
  40. package/lib/rules/__tests__/no-mocks-import.test.js +73 -0
  41. package/lib/rules/__tests__/no-restricted-jest-methods.test.js +103 -0
  42. package/lib/rules/__tests__/no-restricted-matchers.test.js +244 -0
  43. package/lib/rules/__tests__/no-standalone-expect.test.js +230 -0
  44. package/lib/rules/__tests__/no-test-prefixes.test.js +206 -0
  45. package/lib/rules/__tests__/no-test-return-statement.test.js +122 -0
  46. package/lib/rules/__tests__/no-untyped-mock-factory.test.js +149 -0
  47. package/lib/rules/__tests__/prefer-called-with.test.js +40 -0
  48. package/lib/rules/__tests__/prefer-comparison-matcher.test.js +200 -0
  49. package/lib/rules/__tests__/prefer-each.test.js +295 -0
  50. package/lib/rules/__tests__/prefer-equality-matcher.test.js +184 -0
  51. package/lib/rules/__tests__/prefer-expect-assertions.test.js +1437 -0
  52. package/lib/rules/__tests__/prefer-expect-resolves.test.js +96 -0
  53. package/lib/rules/__tests__/prefer-hooks-in-order.test.js +678 -0
  54. package/lib/rules/__tests__/prefer-hooks-on-top.test.js +218 -0
  55. package/lib/rules/__tests__/prefer-lowercase-title.test.js +619 -0
  56. package/lib/rules/__tests__/prefer-mock-promise-shorthand.test.js +360 -0
  57. package/lib/rules/__tests__/prefer-snapshot-hint.test.js +784 -0
  58. package/lib/rules/__tests__/prefer-spy-on.test.js +100 -0
  59. package/lib/rules/__tests__/prefer-strict-equal.test.js +46 -0
  60. package/lib/rules/__tests__/prefer-to-be.test.js +438 -0
  61. package/lib/rules/__tests__/prefer-to-contain.test.js +301 -0
  62. package/lib/rules/__tests__/prefer-to-have-length.test.js +99 -0
  63. package/lib/rules/__tests__/prefer-todo.test.js +78 -0
  64. package/lib/rules/__tests__/require-hook.test.js +403 -0
  65. package/lib/rules/__tests__/require-to-throw-message.test.js +108 -0
  66. package/lib/rules/__tests__/require-top-level-describe.test.js +236 -0
  67. package/lib/rules/__tests__/test-utils.js +11 -0
  68. package/lib/rules/__tests__/unbound-method.test.js +518 -0
  69. package/lib/rules/__tests__/valid-describe-callback.test.js +305 -0
  70. package/lib/rules/__tests__/valid-expect-in-promise.test.js +1583 -0
  71. package/lib/rules/__tests__/valid-expect.test.js +894 -0
  72. package/lib/rules/__tests__/valid-title.test.js +1147 -0
  73. package/lib/rules/utils/__tests__/detectJestVersion.test.js +221 -0
  74. package/lib/rules/utils/__tests__/parseJestFnCall.test.js +809 -0
  75. package/lib/rules/utils/accessors.js +4 -0
  76. package/lib/rules/utils/misc.js +36 -20
  77. package/package.json +12 -8
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+
3
+ var _path = _interopRequireDefault(require("path"));
4
+ var _utils = require("@typescript-eslint/utils");
5
+ var _dedent = _interopRequireDefault(require("dedent"));
6
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ function getFixturesRootDir() {
8
+ return _path.default.join(__dirname, 'fixtures');
9
+ }
10
+ const rootPath = getFixturesRootDir();
11
+ const ruleTester = new _utils.ESLintUtils.RuleTester({
12
+ parser: '@typescript-eslint/parser',
13
+ parserOptions: {
14
+ sourceType: 'module',
15
+ tsconfigRootDir: rootPath,
16
+ project: './tsconfig.json'
17
+ }
18
+ });
19
+ const ConsoleClassAndVariableCode = (0, _dedent.default)`
20
+ class Console {
21
+ log(str) {
22
+ process.stdout.write(str);
23
+ }
24
+ }
25
+
26
+ const console = new Console();
27
+ `;
28
+ const toThrowMatchers = ['toThrow', 'toThrowError', 'toThrowErrorMatchingSnapshot', 'toThrowErrorMatchingInlineSnapshot'];
29
+ const validTestCases = [...['expect(Console.prototype.log).toHaveBeenCalledTimes(1);', 'expect(Console.prototype.log).not.toHaveBeenCalled();', 'expect(Console.prototype.log).toStrictEqual(somethingElse);'].map(code => [ConsoleClassAndVariableCode, code].join('\n')), (0, _dedent.default)`
30
+ expect(() => {
31
+ ${ConsoleClassAndVariableCode}
32
+
33
+ expect(Console.prototype.log).toHaveBeenCalledTimes(1);
34
+ }).not.toThrow();
35
+ `, 'expect(() => Promise.resolve().then(console.log)).not.toThrow();', ...toThrowMatchers.map(matcher => `expect(console.log).not.${matcher}();`), ...toThrowMatchers.map(matcher => `expect(console.log).${matcher}();`)];
36
+ const invalidTestCases = [{
37
+ code: (0, _dedent.default)`
38
+ ${ConsoleClassAndVariableCode}
39
+
40
+ expect(Console.prototype.log)
41
+ `,
42
+ errors: [{
43
+ line: 9,
44
+ messageId: 'unboundWithoutThisAnnotation'
45
+ }]
46
+ }, {
47
+ code: 'expect(Console.prototype.log).toHaveBeenCalledTimes',
48
+ errors: [{
49
+ line: 1,
50
+ messageId: 'unboundWithoutThisAnnotation'
51
+ }]
52
+ }, {
53
+ code: (0, _dedent.default)`
54
+ expect(() => {
55
+ ${ConsoleClassAndVariableCode}
56
+
57
+ Promise.resolve().then(console.log);
58
+ }).not.toThrow();
59
+ `,
60
+ errors: [{
61
+ line: 10,
62
+ messageId: 'unboundWithoutThisAnnotation'
63
+ }]
64
+ },
65
+ // toThrow matchers call the expected value (which is expected to be a function)
66
+ ...toThrowMatchers.map(matcher => ({
67
+ code: (0, _dedent.default)`
68
+ ${ConsoleClassAndVariableCode}
69
+
70
+ expect(console.log).${matcher}();
71
+ `,
72
+ errors: [{
73
+ line: 9,
74
+ messageId: 'unboundWithoutThisAnnotation'
75
+ }]
76
+ })),
77
+ // toThrow matchers call the expected value (which is expected to be a function)
78
+ ...toThrowMatchers.map(matcher => ({
79
+ code: (0, _dedent.default)`
80
+ ${ConsoleClassAndVariableCode}
81
+
82
+ expect(console.log).not.${matcher}();
83
+ `,
84
+ errors: [{
85
+ line: 9,
86
+ messageId: 'unboundWithoutThisAnnotation'
87
+ }]
88
+ }))];
89
+ const requireRule = throwWhenRequiring => {
90
+ jest.resetModules();
91
+ TSESLintPluginRef.throwWhenRequiring = throwWhenRequiring;
92
+
93
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,node/no-missing-require
94
+ return require('../unbound-method').default;
95
+ };
96
+ const TSESLintPluginRef = {
97
+ throwWhenRequiring: false
98
+ };
99
+ jest.mock('@typescript-eslint/eslint-plugin', () => {
100
+ if (TSESLintPluginRef.throwWhenRequiring) {
101
+ throw new class extends Error {
102
+ constructor(message) {
103
+ super(message);
104
+ this.code = 'MODULE_NOT_FOUND';
105
+ }
106
+ }();
107
+ }
108
+ return jest.requireActual('@typescript-eslint/eslint-plugin');
109
+ });
110
+ describe('error handling', () => {
111
+ describe('when an error is thrown accessing the base rule', () => {
112
+ it('re-throws the error', () => {
113
+ jest.mock('@typescript-eslint/eslint-plugin', () => {
114
+ throw new Error('oh noes!');
115
+ });
116
+ jest.resetModules();
117
+
118
+ // eslint-disable-next-line @typescript-eslint/no-require-imports,node/no-missing-require
119
+ expect(() => require('../unbound-method').default).toThrow(/oh noes!/iu);
120
+ });
121
+ });
122
+ describe('when @typescript-eslint/eslint-plugin is not available', () => {
123
+ const ruleTester = new _utils.ESLintUtils.RuleTester({
124
+ parser: '@typescript-eslint/parser',
125
+ parserOptions: {
126
+ sourceType: 'module',
127
+ tsconfigRootDir: rootPath,
128
+ project: './tsconfig.json'
129
+ }
130
+ });
131
+ ruleTester.run('unbound-method jest edition without type service', requireRule(true), {
132
+ valid: validTestCases.concat(invalidTestCases.map(({
133
+ code
134
+ }) => code)),
135
+ invalid: []
136
+ });
137
+ });
138
+ });
139
+ ruleTester.run('unbound-method jest edition', requireRule(false), {
140
+ valid: validTestCases,
141
+ invalid: invalidTestCases
142
+ });
143
+ function addContainsMethodsClass(code) {
144
+ return `
145
+ class ContainsMethods {
146
+ bound?: () => void;
147
+ unbound?(): void;
148
+
149
+ static boundStatic?: () => void;
150
+ static unboundStatic?(): void;
151
+ }
152
+
153
+ let instance = new ContainsMethods();
154
+
155
+ const arith = {
156
+ double(this: void, x: number): number {
157
+ return x * 2;
158
+ }
159
+ };
160
+
161
+ ${code}
162
+ `;
163
+ }
164
+ function addContainsMethodsClassInvalid(code) {
165
+ return code.map(c => ({
166
+ code: addContainsMethodsClass(c),
167
+ errors: [{
168
+ line: 18,
169
+ messageId: 'unboundWithoutThisAnnotation'
170
+ }]
171
+ }));
172
+ }
173
+ ruleTester.run('unbound-method', requireRule(false), {
174
+ valid: ['Promise.resolve().then(console.log);', "['1', '2', '3'].map(Number.parseInt);", '[5.2, 7.1, 3.6].map(Math.floor);', 'const x = console.log;', ...['instance.bound();', 'instance.unbound();', 'ContainsMethods.boundStatic();', 'ContainsMethods.unboundStatic();', 'const bound = instance.bound;', 'const boundStatic = ContainsMethods;', 'const { bound } = instance;', 'const { boundStatic } = ContainsMethods;', '(instance.bound)();', '(instance.unbound)();', '(ContainsMethods.boundStatic)();', '(ContainsMethods.unboundStatic)();', 'instance.bound``;', 'instance.unbound``;', 'if (instance.bound) { }', 'if (instance.unbound) { }', 'if (instance.bound !== undefined) { }', 'if (instance.unbound !== undefined) { }', 'if (ContainsMethods.boundStatic) { }', 'if (ContainsMethods.unboundStatic) { }', 'if (ContainsMethods.boundStatic !== undefined) { }', 'if (ContainsMethods.unboundStatic !== undefined) { }', 'if (ContainsMethods.boundStatic && instance) { }', 'if (ContainsMethods.unboundStatic && instance) { }', 'if (instance.bound || instance) { }', 'if (instance.unbound || instance) { }', 'ContainsMethods.unboundStatic && 0 || ContainsMethods;', '(instance.bound || instance) ? 1 : 0', '(instance.unbound || instance) ? 1 : 0', 'while (instance.bound) { }', 'while (instance.unbound) { }', 'while (instance.bound !== undefined) { }', 'while (instance.unbound !== undefined) { }', 'while (ContainsMethods.boundStatic) { }', 'while (ContainsMethods.unboundStatic) { }', 'while (ContainsMethods.boundStatic !== undefined) { }', 'while (ContainsMethods.unboundStatic !== undefined) { }', 'instance.bound as any;', 'ContainsMethods.boundStatic as any;', 'instance.bound++;', '+instance.bound;', '++instance.bound;', 'instance.bound--;', '-instance.bound;', '--instance.bound;', 'instance.bound += 1;', 'instance.bound -= 1;', 'instance.bound *= 1;', 'instance.bound /= 1;', 'instance.bound || 0;', 'instance.bound && 0;', 'instance.bound ? 1 : 0;', 'instance.unbound ? 1 : 0;', 'ContainsMethods.boundStatic++;', '+ContainsMethods.boundStatic;', '++ContainsMethods.boundStatic;', 'ContainsMethods.boundStatic--;', '-ContainsMethods.boundStatic;', '--ContainsMethods.boundStatic;', 'ContainsMethods.boundStatic += 1;', 'ContainsMethods.boundStatic -= 1;', 'ContainsMethods.boundStatic *= 1;', 'ContainsMethods.boundStatic /= 1;', 'ContainsMethods.boundStatic || 0;', 'instane.boundStatic && 0;', 'ContainsMethods.boundStatic ? 1 : 0;', 'ContainsMethods.unboundStatic ? 1 : 0;', "typeof instance.bound === 'function';", "typeof instance.unbound === 'function';", "typeof ContainsMethods.boundStatic === 'function';", "typeof ContainsMethods.unboundStatic === 'function';", 'instance.unbound = () => {};', 'instance.unbound = instance.unbound.bind(instance);', 'if (!!instance.unbound) {}', 'void instance.unbound', 'delete instance.unbound', 'const { double } = arith;'].map(addContainsMethodsClass), `
175
+ interface RecordA {
176
+ readonly type: 'A';
177
+ readonly a: {};
178
+ }
179
+ interface RecordB {
180
+ readonly type: 'B';
181
+ readonly b: {};
182
+ }
183
+ type AnyRecord = RecordA | RecordB;
184
+
185
+ function test(obj: AnyRecord) {
186
+ switch (obj.type) {
187
+ }
188
+ }
189
+ `,
190
+ // https://github.com/typescript-eslint/typescript-eslint/issues/496
191
+ `
192
+ class CommunicationError {
193
+ constructor() {
194
+ const x = CommunicationError.prototype;
195
+ }
196
+ }
197
+ `, `
198
+ class CommunicationError {}
199
+ const x = CommunicationError.prototype;
200
+ `,
201
+ // optional chain
202
+ `
203
+ class ContainsMethods {
204
+ bound?: () => void;
205
+ unbound?(): void;
206
+
207
+ static boundStatic?: () => void;
208
+ static unboundStatic?(): void;
209
+ }
210
+
211
+ function foo(instance: ContainsMethods | null) {
212
+ instance?.bound();
213
+ instance?.unbound();
214
+
215
+ instance?.bound++;
216
+
217
+ if (instance?.bound) {
218
+ }
219
+ if (instance?.unbound) {
220
+ }
221
+
222
+ typeof instance?.bound === 'function';
223
+ typeof instance?.unbound === 'function';
224
+ }
225
+ `,
226
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1425
227
+ `
228
+ interface OptionalMethod {
229
+ mightBeDefined?(): void;
230
+ }
231
+
232
+ const x: OptionalMethod = {};
233
+ declare const myCondition: boolean;
234
+ if (myCondition || x.mightBeDefined) {
235
+ console.log('hello world');
236
+ }
237
+ `,
238
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1256
239
+ `
240
+ class A {
241
+ unbound(): void {
242
+ this.unbound = undefined;
243
+ this.unbound = this.unbound.bind(this);
244
+ }
245
+ }
246
+ `, 'const { parseInt } = Number;', 'const { log } = console;', `
247
+ let parseInt;
248
+ ({ parseInt } = Number);
249
+ `, `
250
+ let log;
251
+ ({ log } = console);
252
+ `, `
253
+ const foo = {
254
+ bar: 'bar',
255
+ };
256
+ const { bar } = foo;
257
+ `, `
258
+ class Foo {
259
+ unbnound() {}
260
+ bar = 4;
261
+ }
262
+ const { bar } = new Foo();
263
+ `, `
264
+ class Foo {
265
+ bound = () => 'foo';
266
+ }
267
+ const { bound } = new Foo();
268
+ `,
269
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1866
270
+ `
271
+ class BaseClass {
272
+ x: number = 42;
273
+ logThis() {}
274
+ }
275
+ class OtherClass extends BaseClass {
276
+ superLogThis: any;
277
+ constructor() {
278
+ super();
279
+ this.superLogThis = super.logThis;
280
+ }
281
+ }
282
+ const oc = new OtherClass();
283
+ oc.superLogThis();
284
+ `],
285
+ invalid: [{
286
+ code: `
287
+ class Console {
288
+ log(str) {
289
+ process.stdout.write(str);
290
+ }
291
+ }
292
+
293
+ const console = new Console();
294
+
295
+ Promise.resolve().then(console.log);
296
+ `,
297
+ errors: [{
298
+ line: 10,
299
+ messageId: 'unboundWithoutThisAnnotation'
300
+ }]
301
+ }, {
302
+ code: `
303
+ import { console } from './class';
304
+ const x = console.log;
305
+ `,
306
+ errors: [{
307
+ line: 3,
308
+ messageId: 'unboundWithoutThisAnnotation'
309
+ }]
310
+ }, {
311
+ code: addContainsMethodsClass(`
312
+ function foo(arg: ContainsMethods | null) {
313
+ const unbound = arg?.unbound;
314
+ arg.unbound += 1;
315
+ arg?.unbound as any;
316
+ }
317
+ `),
318
+ errors: [{
319
+ line: 20,
320
+ messageId: 'unboundWithoutThisAnnotation'
321
+ }, {
322
+ line: 21,
323
+ messageId: 'unboundWithoutThisAnnotation'
324
+ }, {
325
+ line: 22,
326
+ messageId: 'unboundWithoutThisAnnotation'
327
+ }]
328
+ }, ...addContainsMethodsClassInvalid(['const unbound = instance.unbound;', 'const unboundStatic = ContainsMethods.unboundStatic;', 'const { unbound } = instance;', 'const { unboundStatic } = ContainsMethods;', '<any>instance.unbound;', 'instance.unbound as any;', '<any>ContainsMethods.unboundStatic;', 'ContainsMethods.unboundStatic as any;', 'instance.unbound || 0;', 'ContainsMethods.unboundStatic || 0;', 'instance.unbound ? instance.unbound : null']), {
329
+ code: `
330
+ class ContainsMethods {
331
+ unbound?(): void;
332
+
333
+ static unboundStatic?(): void;
334
+ }
335
+
336
+ new ContainsMethods().unbound;
337
+
338
+ ContainsMethods.unboundStatic;
339
+ `,
340
+ options: [{
341
+ ignoreStatic: true
342
+ }],
343
+ errors: [{
344
+ line: 8,
345
+ messageId: 'unboundWithoutThisAnnotation'
346
+ }]
347
+ },
348
+ // https://github.com/typescript-eslint/typescript-eslint/issues/496
349
+ {
350
+ code: `
351
+ class CommunicationError {
352
+ foo() {}
353
+ }
354
+ const x = CommunicationError.prototype.foo;
355
+ `,
356
+ errors: [{
357
+ line: 5,
358
+ messageId: 'unboundWithoutThisAnnotation'
359
+ }]
360
+ }, {
361
+ // Promise.all is not auto-bound to Promise
362
+ code: 'const x = Promise.all;',
363
+ errors: [{
364
+ line: 1,
365
+ messageId: 'unboundWithoutThisAnnotation'
366
+ }]
367
+ }, {
368
+ code: `
369
+ class Foo {
370
+ unbound() {}
371
+ }
372
+ const instance = new Foo();
373
+
374
+ let x;
375
+
376
+ x = instance.unbound; // THIS SHOULD ERROR
377
+ instance.unbound = x; // THIS SHOULD NOT
378
+ `,
379
+ errors: [{
380
+ line: 9,
381
+ messageId: 'unboundWithoutThisAnnotation'
382
+ }]
383
+ }, {
384
+ code: `
385
+ class Foo {
386
+ unbound = function () {};
387
+ }
388
+ const unbound = new Foo().unbound;
389
+ `,
390
+ errors: [{
391
+ line: 5,
392
+ messageId: 'unbound'
393
+ }]
394
+ }, {
395
+ code: `
396
+ class Foo {
397
+ unbound() {}
398
+ }
399
+ const { unbound } = new Foo();
400
+ `,
401
+ errors: [{
402
+ line: 5,
403
+ messageId: 'unboundWithoutThisAnnotation'
404
+ }]
405
+ }, {
406
+ code: `
407
+ class Foo {
408
+ unbound = function () {};
409
+ }
410
+ const { unbound } = new Foo();
411
+ `,
412
+ errors: [{
413
+ line: 5,
414
+ messageId: 'unbound'
415
+ }]
416
+ }, {
417
+ code: `
418
+ class Foo {
419
+ unbound() {}
420
+ }
421
+ let unbound;
422
+ ({ unbound } = new Foo());
423
+ `,
424
+ errors: [{
425
+ line: 6,
426
+ messageId: 'unboundWithoutThisAnnotation'
427
+ }]
428
+ }, {
429
+ code: `
430
+ class Foo {
431
+ unbound = function () {};
432
+ }
433
+ let unbound;
434
+ ({ unbound } = new Foo());
435
+ `,
436
+ errors: [{
437
+ line: 6,
438
+ messageId: 'unbound'
439
+ }]
440
+ }, {
441
+ code: `
442
+ class CommunicationError {
443
+ foo() {}
444
+ }
445
+ const { foo } = CommunicationError.prototype;
446
+ `,
447
+ errors: [{
448
+ line: 5,
449
+ messageId: 'unboundWithoutThisAnnotation'
450
+ }]
451
+ }, {
452
+ code: `
453
+ class CommunicationError {
454
+ foo() {}
455
+ }
456
+ let foo;
457
+ ({ foo } = CommunicationError.prototype);
458
+ `,
459
+ errors: [{
460
+ line: 6,
461
+ messageId: 'unboundWithoutThisAnnotation'
462
+ }]
463
+ }, {
464
+ code: `
465
+ import { console } from './class';
466
+ const { log } = console;
467
+ `,
468
+ errors: [{
469
+ line: 3,
470
+ messageId: 'unboundWithoutThisAnnotation'
471
+ }]
472
+ }, {
473
+ code: 'const { all } = Promise;',
474
+ errors: [{
475
+ line: 1,
476
+ messageId: 'unboundWithoutThisAnnotation'
477
+ }]
478
+ },
479
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1866
480
+ {
481
+ code: `
482
+ class BaseClass {
483
+ logThis() {}
484
+ }
485
+ class OtherClass extends BaseClass {
486
+ constructor() {
487
+ super();
488
+ const x = super.logThis;
489
+ }
490
+ }
491
+ `,
492
+ errors: [{
493
+ line: 8,
494
+ column: 15,
495
+ messageId: 'unboundWithoutThisAnnotation'
496
+ }]
497
+ },
498
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1866
499
+ {
500
+ code: `
501
+ class BaseClass {
502
+ logThis() {}
503
+ }
504
+ class OtherClass extends BaseClass {
505
+ constructor() {
506
+ super();
507
+ let x;
508
+ x = super.logThis;
509
+ }
510
+ }
511
+ `,
512
+ errors: [{
513
+ line: 9,
514
+ column: 9,
515
+ messageId: 'unboundWithoutThisAnnotation'
516
+ }]
517
+ }]
518
+ });