|
| 1 | +import { stripIndent } from 'common-tags'; |
| 2 | +import { noImportOperatorsRule } from '../../src/rules/no-import-operators'; |
| 3 | +import { fromFixture } from '../etc'; |
| 4 | +import { ruleTester } from '../rule-tester'; |
| 5 | + |
| 6 | +ruleTester({ types: false }).run('no-import-operators', noImportOperatorsRule, { |
| 7 | + valid: [ |
| 8 | + stripIndent` |
| 9 | + // import declaration named |
| 10 | + import { concat } from "rxjs"; |
| 11 | + import { concat } from 'rxjs'; |
| 12 | + `, |
| 13 | + stripIndent` |
| 14 | + // import declaration namespace |
| 15 | + import * as Rx from "rxjs"; |
| 16 | + `, |
| 17 | + stripIndent` |
| 18 | + // import expression |
| 19 | + const { concat } = await import("rxjs"); |
| 20 | + `, |
| 21 | + stripIndent` |
| 22 | + // import expression with identifier is not supported |
| 23 | + const path = "rxjs/operators"; |
| 24 | + const { concat } = await import(path); |
| 25 | + `, |
| 26 | + stripIndent` |
| 27 | + // export named |
| 28 | + export { concat } from "rxjs"; |
| 29 | + `, |
| 30 | + stripIndent` |
| 31 | + // export all |
| 32 | + export * from "rxjs"; |
| 33 | + `, |
| 34 | + stripIndent` |
| 35 | + // unrelated import |
| 36 | + import { ajax } from "rxjs/ajax"; |
| 37 | + import { fromFetch } from "rxjs/fetch"; |
| 38 | + import { TestScheduler } from "rxjs/testing"; |
| 39 | + import { webSocket } from "rxjs/webSocket"; |
| 40 | + import * as prefixedPackage from "rxjs-prefixed-package"; |
| 41 | + `, |
| 42 | + ], |
| 43 | + invalid: [ |
| 44 | + fromFixture( |
| 45 | + stripIndent` |
| 46 | + // import declaration named |
| 47 | + import { concat } from "rxjs/operators"; |
| 48 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 49 | + import { concat } from 'rxjs/operators'; |
| 50 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 51 | + `, |
| 52 | + ), |
| 53 | + fromFixture( |
| 54 | + stripIndent` |
| 55 | + // import declaration namespace |
| 56 | + import * as RxOperators from "rxjs/operators"; |
| 57 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 58 | + `, |
| 59 | + ), |
| 60 | + fromFixture( |
| 61 | + stripIndent` |
| 62 | + // import expression |
| 63 | + const { concat } = await import("rxjs/operators"); |
| 64 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 65 | + `, |
| 66 | + ), |
| 67 | + fromFixture( |
| 68 | + stripIndent` |
| 69 | + // export named |
| 70 | + export { concat } from "rxjs/operators"; |
| 71 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 72 | + `, |
| 73 | + ), |
| 74 | + fromFixture( |
| 75 | + stripIndent` |
| 76 | + // export all |
| 77 | + export * from "rxjs/operators"; |
| 78 | + ~~~~~~~~~~~~~~~~ [forbidden] |
| 79 | + `, |
| 80 | + ), |
| 81 | + ], |
| 82 | +}); |
0 commit comments