|
1 |
| -import { test, testFilePath } from '../utils' |
| 1 | +import { test, testFilePath } from '../../src/utils' |
2 | 2 | import jsxConfig from '../../../config/react'
|
3 | 3 | import typescriptConfig from '../../../config/typescript'
|
4 | 4 |
|
@@ -71,32 +71,39 @@ ruleTester.run('no-unused-modules', rule, {
|
71 | 71 | // tests for exports
|
72 | 72 | ruleTester.run('no-unused-modules', rule, {
|
73 | 73 | valid: [
|
74 |
| - |
75 | 74 | test({ options: unusedExportsOptions,
|
76 | 75 | code: 'import { o2 } from "./file-o";export default () => 12',
|
77 |
| - filename: testFilePath('./no-unused-modules/file-a.js')}), |
| 76 | + filename: testFilePath('./no-unused-modules/file-a.js'), |
| 77 | + parser: require.resolve('babel-eslint')}), |
78 | 78 | test({ options: unusedExportsOptions,
|
79 | 79 | code: 'export const b = 2',
|
80 |
| - filename: testFilePath('./no-unused-modules/file-b.js')}), |
| 80 | + filename: testFilePath('./no-unused-modules/file-b.js'), |
| 81 | + parser: require.resolve('babel-eslint')}), |
81 | 82 | test({ options: unusedExportsOptions,
|
82 | 83 | code: 'const c1 = 3; function c2() { return 3 }; export { c1, c2 }',
|
83 |
| - filename: testFilePath('./no-unused-modules/file-c.js')}), |
| 84 | + filename: testFilePath('./no-unused-modules/file-c.js'), |
| 85 | + parser: require.resolve('babel-eslint')}), |
84 | 86 | test({ options: unusedExportsOptions,
|
85 | 87 | code: 'export function d() { return 4 }',
|
86 |
| - filename: testFilePath('./no-unused-modules/file-d.js')}), |
| 88 | + filename: testFilePath('./no-unused-modules/file-d.js'), |
| 89 | + parser: require.resolve('babel-eslint')}), |
87 | 90 | test({ options: unusedExportsOptions,
|
88 | 91 | code: 'export class q { q0() {} }',
|
89 |
| - filename: testFilePath('./no-unused-modules/file-q.js')}), |
| 92 | + filename: testFilePath('./no-unused-modules/file-q.js'), |
| 93 | + parser: require.resolve('babel-eslint')}), |
90 | 94 | test({ options: unusedExportsOptions,
|
91 | 95 | code: 'const e0 = 5; export { e0 as e }',
|
92 |
| - filename: testFilePath('./no-unused-modules/file-e.js')}), |
| 96 | + filename: testFilePath('./no-unused-modules/file-e.js'), |
| 97 | + parser: require.resolve('babel-eslint')}), |
93 | 98 | test({ options: unusedExportsOptions,
|
94 | 99 | code: 'const l0 = 5; const l = 10; export { l0 as l1, l }; export default () => {}',
|
95 |
| - filename: testFilePath('./no-unused-modules/file-l.js')}), |
| 100 | + filename: testFilePath('./no-unused-modules/file-l.js'), |
| 101 | + parser: require.resolve('babel-eslint')}), |
96 | 102 | test({ options: unusedExportsOptions,
|
97 | 103 | code: 'const o0 = 0; const o1 = 1; export { o0, o1 as o2 }; export default () => {}',
|
98 |
| - filename: testFilePath('./no-unused-modules/file-o.js')}), |
99 |
| - ], |
| 104 | + filename: testFilePath('./no-unused-modules/file-o.js'), |
| 105 | + parser: require.resolve('babel-eslint')}), |
| 106 | + ], |
100 | 107 | invalid: [
|
101 | 108 | test({ options: unusedExportsOptions,
|
102 | 109 | code: `import eslint from 'eslint'
|
@@ -164,6 +171,56 @@ ruleTester.run('no-unused-modules', rule, {
|
164 | 171 | ],
|
165 | 172 | })
|
166 | 173 |
|
| 174 | +// test for unused exports with `import()` |
| 175 | +ruleTester.run('no-unused-modules', rule, { |
| 176 | + valid: [ |
| 177 | + test({ options: unusedExportsOptions, |
| 178 | + code: ` |
| 179 | + export const a = 10 |
| 180 | + export const b = 20 |
| 181 | + export const c = 30 |
| 182 | + const d = 40 |
| 183 | + export default d |
| 184 | + `, |
| 185 | + parser: require.resolve('babel-eslint'), |
| 186 | + filename: testFilePath('./no-unused-modules/exports-for-dynamic-js.js')}), |
| 187 | + ], |
| 188 | + invalid: [ |
| 189 | + test({ options: unusedExportsOptions, |
| 190 | + code: ` |
| 191 | + export const a = 10 |
| 192 | + export const b = 20 |
| 193 | + export const c = 30 |
| 194 | + const d = 40 |
| 195 | + export default d |
| 196 | + `, |
| 197 | + parser: require.resolve('babel-eslint'), |
| 198 | + filename: testFilePath('./no-unused-modules/exports-for-dynamic-js-2.js'), |
| 199 | + errors: [ |
| 200 | + error(`exported declaration 'a' not used within other modules`), |
| 201 | + error(`exported declaration 'b' not used within other modules`), |
| 202 | + error(`exported declaration 'c' not used within other modules`), |
| 203 | + error(`exported declaration 'default' not used within other modules`), |
| 204 | + ]}), |
| 205 | + ], |
| 206 | +}) |
| 207 | +typescriptRuleTester.run('no-unused-modules', rule, { |
| 208 | + valid: [ |
| 209 | + test({ options: unusedExportsTypescriptOptions, |
| 210 | + code: ` |
| 211 | + export const ts_a = 10 |
| 212 | + export const ts_b = 20 |
| 213 | + export const ts_c = 30 |
| 214 | + const ts_d = 40 |
| 215 | + export default ts_d |
| 216 | + `, |
| 217 | + parser: require.resolve('@typescript-eslint/parser'), |
| 218 | + filename: testFilePath('./no-unused-modules/typescript/exports-for-dynamic-ts.ts')}), |
| 219 | + ], |
| 220 | + invalid: [ |
| 221 | + ], |
| 222 | +}) |
| 223 | + |
167 | 224 | // // test for export from
|
168 | 225 | ruleTester.run('no-unused-modules', rule, {
|
169 | 226 | valid: [
|
|
0 commit comments