|
| 1 | +import { ESLintUtils } from '@typescript-eslint/utils'; |
| 2 | +import { InvalidTestCase, ValidTestCase } from '@typescript-eslint/rule-tester'; |
| 3 | +import rule, { |
| 4 | + messageId, |
| 5 | +} from '../../../src/rules/component-store/require-super-ondestroy'; |
| 6 | +import { fromFixture, ruleTester } from '../../utils'; |
| 7 | +import path = require('path'); |
| 8 | + |
| 9 | +type MessageIds = ESLintUtils.InferMessageIdsTypeFromRule<typeof rule>; |
| 10 | +type Options = ESLintUtils.InferOptionsTypeFromRule<typeof rule>; |
| 11 | + |
| 12 | +const valid: () => (string | ValidTestCase<Options>)[] = () => [ |
| 13 | + ` |
| 14 | +import { ComponentStore } from '@ngrx/component-store'; |
| 15 | +
|
| 16 | +class BooksStore extends ComponentStore<BooksState> |
| 17 | +{ |
| 18 | +}`, |
| 19 | + ` |
| 20 | +import { ComponentStore } from '@ngrx/component-store'; |
| 21 | +
|
| 22 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy |
| 23 | +{ |
| 24 | + override ngOnDestroy(): void { |
| 25 | + super.ngOnDestroy(); |
| 26 | + } |
| 27 | +}`, |
| 28 | + ` |
| 29 | +import { ComponentStore } from '@ngrx/component-store'; |
| 30 | +
|
| 31 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy |
| 32 | +{ |
| 33 | + cleanUp() {} |
| 34 | +
|
| 35 | + override ngOnDestroy(): void { |
| 36 | + this.cleanUp(); |
| 37 | + super.ngOnDestroy(); |
| 38 | + } |
| 39 | +}`, |
| 40 | + ` |
| 41 | +import { ComponentStore } from '@ngrx/component-store'; |
| 42 | +
|
| 43 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy |
| 44 | +{ |
| 45 | + cleanUp() {} |
| 46 | +
|
| 47 | + override ngOnDestroy(): void { |
| 48 | + super.ngOnDestroy(); |
| 49 | + this.cleanUp(); |
| 50 | + } |
| 51 | +}`, |
| 52 | + ` |
| 53 | +import { ComponentStore } from '@ngrx/component-store'; |
| 54 | +
|
| 55 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy |
| 56 | +{ |
| 57 | + cleanUp() {} |
| 58 | +
|
| 59 | + override ngOnDestroy(): void { |
| 60 | + this.cleanUp(); |
| 61 | + super.ngOnDestroy(); |
| 62 | + this.cleanUp(); |
| 63 | + } |
| 64 | +}`, |
| 65 | + ` |
| 66 | +import { ComponentStore } from '../components/component-store'; |
| 67 | +
|
| 68 | +class BooksStore extends ComponentStore implements OnDestroy |
| 69 | +{ |
| 70 | + cleanUp() {} |
| 71 | +
|
| 72 | + override ngOnDestroy(): void { |
| 73 | + this.cleanUp(); |
| 74 | + } |
| 75 | +}`, |
| 76 | +]; |
| 77 | + |
| 78 | +const invalid: () => InvalidTestCase<MessageIds, Options>[] = () => [ |
| 79 | + fromFixture(` |
| 80 | +import { ComponentStore } from '@ngrx/component-store'; |
| 81 | +
|
| 82 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy { |
| 83 | + override ngOnDestroy(): void { |
| 84 | + ~~~~~~~~~~~ [${messageId}] |
| 85 | + } |
| 86 | +}`), |
| 87 | + fromFixture(` |
| 88 | +import { ComponentStore } from '@ngrx/component-store'; |
| 89 | +
|
| 90 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy { |
| 91 | + cleanUp() {} |
| 92 | +
|
| 93 | + override ngOnDestroy(): void { |
| 94 | + ~~~~~~~~~~~ [${messageId}] |
| 95 | + this.cleanUp(); |
| 96 | + } |
| 97 | +}`), |
| 98 | + fromFixture(` |
| 99 | +import { ComponentStore } from '@ngrx/component-store'; |
| 100 | +
|
| 101 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy { |
| 102 | + override ngOnDestroy(): void { |
| 103 | + ~~~~~~~~~~~ [${messageId}] |
| 104 | + super.ngOnDestroy; |
| 105 | + } |
| 106 | +}`), |
| 107 | + fromFixture(` |
| 108 | +import { ComponentStore } from '@ngrx/component-store'; |
| 109 | +
|
| 110 | +class BooksStore extends ComponentStore<BooksState> implements OnDestroy { |
| 111 | + override ngOnDestroy(): void { |
| 112 | + ~~~~~~~~~~~ [${messageId}] |
| 113 | + super.get(); |
| 114 | + } |
| 115 | +}`), |
| 116 | +]; |
| 117 | + |
| 118 | +ruleTester().run(path.parse(__filename).name, rule, { |
| 119 | + valid: valid(), |
| 120 | + invalid: invalid(), |
| 121 | +}); |
0 commit comments