|
1 |
| -import { test, testFilePath } from '../utils' |
| 1 | +import { test, testFilePath, getTSParsers } from '../utils' |
2 | 2 | import jsxConfig from '../../../config/react'
|
3 | 3 | import typescriptConfig from '../../../config/typescript'
|
4 | 4 |
|
@@ -736,10 +736,81 @@ describe('correctly work with Typescript only files', () => {
|
736 | 736 | error(`exported declaration 'b' not used within other modules`),
|
737 | 737 | ],
|
738 | 738 | }),
|
| 739 | + test({ |
| 740 | + options: unusedExportsTypescriptOptions, |
| 741 | + code: `export interface c {};`, |
| 742 | + parser: require.resolve('babel-eslint'), |
| 743 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-c.ts'), |
| 744 | + errors: [ |
| 745 | + error(`exported declaration 'c' not used within other modules`), |
| 746 | + ], |
| 747 | + }), |
| 748 | + test({ |
| 749 | + options: unusedExportsTypescriptOptions, |
| 750 | + code: `export type d = {};`, |
| 751 | + parser: require.resolve('babel-eslint'), |
| 752 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-d.ts'), |
| 753 | + errors: [ |
| 754 | + error(`exported declaration 'd' not used within other modules`), |
| 755 | + ], |
| 756 | + }), |
739 | 757 | ],
|
740 | 758 | })
|
741 | 759 | })
|
742 | 760 |
|
| 761 | +context('TypeScript', function () { |
| 762 | + getTSParsers().forEach((parser) => { |
| 763 | + typescriptRuleTester.run('no-unused-modules', rule, { |
| 764 | + valid: [ |
| 765 | + test({ |
| 766 | + options: unusedExportsTypescriptOptions, |
| 767 | + code: 'import a from "file-ts-a";', |
| 768 | + parser: parser, |
| 769 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-a.ts'), |
| 770 | + }), |
| 771 | + ], |
| 772 | + invalid: [ |
| 773 | + test({ |
| 774 | + options: unusedExportsTypescriptOptions, |
| 775 | + code: `export const b = 2;`, |
| 776 | + parser: parser, |
| 777 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-b.ts'), |
| 778 | + errors: [ |
| 779 | + error(`exported declaration 'b' not used within other modules`), |
| 780 | + ], |
| 781 | + }), |
| 782 | + test({ |
| 783 | + options: unusedExportsTypescriptOptions, |
| 784 | + code: `export interface c {};`, |
| 785 | + parser: parser, |
| 786 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-c.ts'), |
| 787 | + errors: [ |
| 788 | + error(`exported declaration 'c' not used within other modules`), |
| 789 | + ], |
| 790 | + }), |
| 791 | + test({ |
| 792 | + options: unusedExportsTypescriptOptions, |
| 793 | + code: `export type d = {};`, |
| 794 | + parser: parser, |
| 795 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-d.ts'), |
| 796 | + errors: [ |
| 797 | + error(`exported declaration 'd' not used within other modules`), |
| 798 | + ], |
| 799 | + }), |
| 800 | + test({ |
| 801 | + options: unusedExportsTypescriptOptions, |
| 802 | + code: `export enum e { f };`, |
| 803 | + parser: parser, |
| 804 | + filename: testFilePath('./no-unused-modules/typescript/file-ts-e.ts'), |
| 805 | + errors: [ |
| 806 | + error(`exported declaration 'e' not used within other modules`), |
| 807 | + ], |
| 808 | + }), |
| 809 | + ], |
| 810 | + }) |
| 811 | + }) |
| 812 | +}) |
| 813 | + |
743 | 814 | describe('correctly work with JSX only files', () => {
|
744 | 815 | jsxRuleTester.run('no-unused-modules', rule, {
|
745 | 816 | valid: [
|
|
0 commit comments