@@ -83,8 +83,6 @@ def test_move_to_file_update_all_imports(tmpdir) -> None:
8383
8484 # language=typescript
8585 EXPECTED_FILE_2_CONTENT = """
86- import { externalDep } from 'file1';
87-
8886function foo() {
8987 return fooDep() + 1;
9088}
@@ -130,7 +128,7 @@ def test_move_to_file_update_all_imports(tmpdir) -> None:
130128 file3 = codebase .get_file ("file3.ts" )
131129
132130 bar = file2 .get_function ("bar" )
133- bar .move_to_file (file3 , include_dependencies = True , strategy = "update_all_imports" )
131+ bar .move_to_file (file3 , include_dependencies = True , strategy = "update_all_imports" , remove_unused_imports = True )
134132
135133 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
136134 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -227,7 +225,7 @@ def test_move_to_file_update_all_imports_include_dependencies(tmpdir) -> None:
227225 file3 = codebase .get_file ("file3.ts" )
228226
229227 bar_symbol = file2 .get_symbol ("bar" )
230- bar_symbol .move_to_file (file1 , strategy = "update_all_imports" , include_dependencies = True )
228+ bar_symbol .move_to_file (file1 , strategy = "update_all_imports" , include_dependencies = True , remove_unused_imports = True )
231229
232230 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
233231 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -331,7 +329,7 @@ def test_move_to_file_update_all_imports_without_include_dependencies(tmpdir) ->
331329 file3 = codebase .get_file ("file3.ts" )
332330
333331 bar_symbol = file2 .get_symbol ("bar" )
334- bar_symbol .move_to_file (file1 , strategy = "update_all_imports" , include_dependencies = False )
332+ bar_symbol .move_to_file (file1 , strategy = "update_all_imports" , include_dependencies = False , remove_unused_imports = True )
335333
336334 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
337335 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -393,9 +391,7 @@ def test_move_to_file_add_back_edge(tmpdir) -> None:
393391
394392 # language=typescript
395393 EXPECTED_FILE_2_CONTENT = """
396- export { bar } from 'file3'
397- import { externalDep } from 'file1';
398-
394+ export { bar } from 'file3';
399395function foo() {
400396 return fooDep() + 1;
401397}
@@ -408,8 +404,6 @@ def test_move_to_file_add_back_edge(tmpdir) -> None:
408404 # language=typescript
409405 EXPECTED_FILE_3_CONTENT = """
410406import { externalDep } from 'file1';
411- import { bar } from 'file2';
412-
413407export function baz() {
414408 return bar() + 1;
415409}
@@ -424,9 +418,9 @@ def test_move_to_file_add_back_edge(tmpdir) -> None:
424418"""
425419
426420 # ===============================
427- # TODO: [!HIGH!] Creates circular import for bar between file2 and file3
428- # TODO: [medium] Missing semicolon in import on file3
429421 # TODO: [medium] Why did barDep get changed to export?
422+ # TODO: [low] Missing newline after import
423+ # TODO: [low] Unused import of bar in file3
430424
431425 with get_codebase_session (
432426 tmpdir = tmpdir ,
@@ -442,7 +436,7 @@ def test_move_to_file_add_back_edge(tmpdir) -> None:
442436 file3 = codebase .get_file ("file3.ts" )
443437
444438 bar = file2 .get_function ("bar" )
445- bar .move_to_file (file3 , include_dependencies = True , strategy = "add_back_edge" )
439+ bar .move_to_file (file3 , include_dependencies = True , strategy = "add_back_edge" , remove_unused_imports = True )
446440
447441 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
448442 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -506,7 +500,8 @@ def test_move_to_file_add_back_edge_including_dependencies(tmpdir) -> None:
506500
507501 # language=typescript
508502 EXPECTED_FILE_2_CONTENT = """
509- export { bar } from 'file1'
503+ import { bar } from 'file1';
504+ export { bar };
510505
511506function xyz(): number {
512507 // should stay
@@ -525,8 +520,8 @@ def test_move_to_file_add_back_edge_including_dependencies(tmpdir) -> None:
525520"""
526521
527522 # ===============================
528- # TODO: [medium] Missing semicolon in import on file2
529523 # TODO: [medium] Why is abc exported?
524+ # TODO: [low] Import and export should be changed to a re-export
530525
531526 with get_codebase_session (
532527 tmpdir = tmpdir ,
@@ -542,7 +537,7 @@ def test_move_to_file_add_back_edge_including_dependencies(tmpdir) -> None:
542537 file3 = codebase .get_file ("file3.ts" )
543538
544539 bar_symbol = file2 .get_symbol ("bar" )
545- bar_symbol .move_to_file (file1 , strategy = "add_back_edge" , include_dependencies = True )
540+ bar_symbol .move_to_file (file1 , strategy = "add_back_edge" , include_dependencies = True , remove_unused_imports = True )
546541
547542 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
548543 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -609,7 +604,8 @@ def test_move_to_file_add_back_edge_without_include_dependencies(tmpdir) -> None
609604
610605 # language=typescript
611606 EXPECTED_FILE_2_CONTENT = """
612- export { bar } from 'file1'
607+ import { bar } from 'file1';
608+ export { bar };
613609
614610export function abc(): string {
615611 // dependency, DOES NOT GET MOVED
@@ -633,7 +629,7 @@ def test_move_to_file_add_back_edge_without_include_dependencies(tmpdir) -> None
633629"""
634630
635631 # ===============================
636- # TODO: [medium] Missing semicolon in import on file2
632+ # TODO: [low] Import and export should be changed to a re-export
637633
638634 with get_codebase_session (
639635 tmpdir = tmpdir ,
@@ -649,7 +645,7 @@ def test_move_to_file_add_back_edge_without_include_dependencies(tmpdir) -> None
649645 file3 = codebase .get_file ("file3.ts" )
650646
651647 bar_symbol = file2 .get_symbol ("bar" )
652- bar_symbol .move_to_file (file1 , strategy = "add_back_edge" , include_dependencies = False )
648+ bar_symbol .move_to_file (file1 , strategy = "add_back_edge" , include_dependencies = False , remove_unused_imports = True )
653649
654650 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
655651 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -711,26 +707,18 @@ def test_move_to_file_duplicate_dependencies(tmpdir) -> None:
711707
712708 # language=typescript
713709 EXPECTED_FILE_2_CONTENT = """
714- import { externalDep } from 'file1';
715-
716710function foo() {
717711 return fooDep() + 1;
718712}
719713
720714function fooDep() {
721715 return 24;
722716}
723-
724- export function bar() {
725- return externalDep() + barDep();
726- }
727717"""
728718
729719 # language=typescript
730720 EXPECTED_FILE_3_CONTENT = """
731721import { externalDep } from 'file1';
732- import { bar } from 'file2';
733-
734722export function baz() {
735723 return bar() + 1;
736724}
@@ -745,7 +733,6 @@ def test_move_to_file_duplicate_dependencies(tmpdir) -> None:
745733"""
746734
747735 # ===============================
748- # TODO: [!HIGH!] Incorrect deletion of bar's import and dependency
749736 # TODO: [medium] Why is barDep exported?
750737
751738 with get_codebase_session (
@@ -762,7 +749,7 @@ def test_move_to_file_duplicate_dependencies(tmpdir) -> None:
762749 file3 = codebase .get_file ("file3.ts" )
763750
764751 bar = file2 .get_function ("bar" )
765- bar .move_to_file (file3 , include_dependencies = True , strategy = "duplicate_dependencies" )
752+ bar .move_to_file (file3 , include_dependencies = True , strategy = "duplicate_dependencies" , remove_unused_imports = True )
766753
767754 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
768755 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -866,7 +853,7 @@ def test_move_to_file_duplicate_dependencies_include_dependencies(tmpdir) -> Non
866853 file3 = codebase .get_file ("file3.ts" )
867854
868855 bar_symbol = file2 .get_symbol ("bar" )
869- bar_symbol .move_to_file (file1 , strategy = "duplicate_dependencies" , include_dependencies = True )
856+ bar_symbol .move_to_file (file1 , strategy = "duplicate_dependencies" , include_dependencies = True , remove_unused_imports = True )
870857
871858 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
872859 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -975,7 +962,7 @@ def test_move_to_file_duplicate_dependencies_without_include_dependencies(tmpdir
975962 file3 = codebase .get_file ("file3.ts" )
976963
977964 bar_symbol = file2 .get_symbol ("bar" )
978- bar_symbol .move_to_file (file1 , strategy = "duplicate_dependencies" , include_dependencies = False )
965+ bar_symbol .move_to_file (file1 , strategy = "duplicate_dependencies" , include_dependencies = False , remove_unused_imports = True )
979966
980967 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
981968 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -1036,7 +1023,7 @@ def test_move_to_file_import_star(tmpdir) -> None:
10361023 usage_file = codebase .get_file ("usage.ts" )
10371024
10381025 target_function = source_file .get_function ("targetFunction" )
1039- target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" )
1026+ target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" , remove_unused_imports = True )
10401027
10411028 assert usage_file .content .strip () == EXPECTED_USAGE_FILE_CONTENT .strip ()
10421029
@@ -1085,7 +1072,7 @@ def test_move_to_file_named_import(tmpdir) -> None:
10851072 usage_file = codebase .get_file ("usage.ts" )
10861073
10871074 target_function = source_file .get_function ("targetFunction" )
1088- target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" )
1075+ target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" , remove_unused_imports = True )
10891076
10901077 assert usage_file .content .strip () == EXPECTED_USAGE_FILE_CONTENT .strip ()
10911078
@@ -1209,7 +1196,7 @@ def test_move_to_file_include_type_import_dependencies(tmpdir) -> None:
12091196 dest_file = codebase .get_file ("destination.ts" )
12101197
12111198 target_function = source_file .get_function ("targetFunction" )
1212- target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" )
1199+ target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" , remove_unused_imports = True )
12131200
12141201 assert normalize_imports (dest_file .content .strip ()) == normalize_imports (EXPECTED_DEST_FILE_CONTENT .strip ())
12151202
@@ -1264,7 +1251,7 @@ def test_move_to_file_imports_local_deps(tmpdir) -> None:
12641251 dest_file = codebase .get_file ("destination.ts" )
12651252
12661253 target_function = source_file .get_function ("targetFunction" )
1267- target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" )
1254+ target_function .move_to_file (dest_file , include_dependencies = False , strategy = "update_all_imports" , remove_unused_imports = True )
12681255
12691256 assert normalize_imports (dest_file .content .strip ()) == normalize_imports (EXPECTED_DEST_FILE_CONTENT .strip ())
12701257 assert normalize_imports (source_file .content .strip ()) == normalize_imports (EXPECTED_SOURCE_FILE_CONTENT .strip ())
@@ -1286,8 +1273,8 @@ def test_function_move_to_file_circular_dependency(tmpdir) -> None:
12861273 # ========== [ AFTER ] ==========
12871274 # language=typescript
12881275 EXPECTED_FILE_1_CONTENT = """
1289- export { bar } from 'file2'
1290- export { foo } from 'file2'
1276+ export { bar } from 'file2';
1277+ export { foo } from 'file2';
12911278"""
12921279 # language=typescript
12931280 EXPECTED_FILE_2_CONTENT = """
@@ -1301,7 +1288,6 @@ def test_function_move_to_file_circular_dependency(tmpdir) -> None:
13011288"""
13021289
13031290 # ===============================
1304- # TODO: [low] Missing semicolons
13051291
13061292 with get_codebase_session (
13071293 tmpdir = tmpdir ,
@@ -1315,7 +1301,7 @@ def test_function_move_to_file_circular_dependency(tmpdir) -> None:
13151301 assert foo in bar .dependencies
13161302
13171303 file2 = codebase .create_file ("file2.ts" , "" )
1318- foo .move_to_file (file2 , include_dependencies = True , strategy = "add_back_edge" )
1304+ foo .move_to_file (file2 , include_dependencies = True , strategy = "add_back_edge" , remove_unused_imports = True )
13191305
13201306 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
13211307 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -1338,8 +1324,8 @@ def test_function_move_to_file_lower_upper(tmpdir) -> None:
13381324 # ========== [ AFTER ] ==========
13391325 # language=typescript
13401326 EXPECTED_FILE_1_CONTENT = """
1341- export { bar } from 'File1'
1342- export { foo } from 'File1'
1327+ export { bar } from 'File1';
1328+ export { foo } from 'File1';
13431329"""
13441330
13451331 # language=typescript
@@ -1354,7 +1340,6 @@ def test_function_move_to_file_lower_upper(tmpdir) -> None:
13541340"""
13551341
13561342 # ===============================
1357- # TODO: [low] Missing semicolons
13581343
13591344 with get_codebase_session (
13601345 tmpdir = tmpdir ,
@@ -1368,7 +1353,7 @@ def test_function_move_to_file_lower_upper(tmpdir) -> None:
13681353 assert foo in bar .dependencies
13691354
13701355 file2 = codebase .create_file ("File1.ts" , "" )
1371- foo .move_to_file (file2 , include_dependencies = True , strategy = "add_back_edge" )
1356+ foo .move_to_file (file2 , include_dependencies = True , strategy = "add_back_edge" , remove_unused_imports = True )
13721357
13731358 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
13741359 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -1391,7 +1376,7 @@ def test_function_move_to_file_no_deps(tmpdir) -> None:
13911376 # language=typescript
13921377 EXPECTED_FILE_1_CONTENT = """
13931378import { foo } from 'File2';
1394- export { foo }
1379+ export { foo };
13951380
13961381export function bar(): number {
13971382 return foo() + 1;
@@ -1409,8 +1394,7 @@ def test_function_move_to_file_no_deps(tmpdir) -> None:
14091394
14101395 # ===============================
14111396 # TODO: [medium] Is the extra new lines here expected behavior?
1412- # TODO: [low] Missing semicolons
1413- # TOOD: [low] Import and export should be changed to a re-export
1397+ # TODO: [low] Import and export should be changed to a re-export
14141398
14151399 with get_codebase_session (
14161400 tmpdir = tmpdir ,
@@ -1424,7 +1408,7 @@ def test_function_move_to_file_no_deps(tmpdir) -> None:
14241408 assert foo in bar .dependencies
14251409
14261410 file2 = codebase .create_file ("File2.ts" , "" )
1427- foo .move_to_file (file2 , include_dependencies = False , strategy = "add_back_edge" )
1411+ foo .move_to_file (file2 , include_dependencies = False , strategy = "add_back_edge" , remove_unused_imports = True )
14281412
14291413 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
14301414 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
@@ -1448,7 +1432,7 @@ def test_function_move_to_file_lower_upper_no_deps(tmpdir) -> None:
14481432 # language=typescript
14491433 EXPECTED_FILE_1_CONTENT = """
14501434import { foo } from 'File1';
1451- export { foo }
1435+ export { foo };
14521436
14531437export function bar(): number {
14541438 return foo() + 1;
@@ -1467,8 +1451,7 @@ def test_function_move_to_file_lower_upper_no_deps(tmpdir) -> None:
14671451
14681452 # ===============================
14691453 # TODO: [medium] Is the extra new lines here expected behavior?
1470- # TODO: [low] Missing semicolons
1471- # TOOD: [low] Import and export should be changed to a re-export
1454+ # TODO: [low] Import and export should be changed to a re-export
14721455
14731456 with get_codebase_session (
14741457 tmpdir = tmpdir ,
@@ -1482,7 +1465,7 @@ def test_function_move_to_file_lower_upper_no_deps(tmpdir) -> None:
14821465 assert foo in bar .dependencies
14831466
14841467 file2 = codebase .create_file ("File1.ts" , "" )
1485- foo .move_to_file (file2 , include_dependencies = False , strategy = "add_back_edge" )
1468+ foo .move_to_file (file2 , include_dependencies = False , strategy = "add_back_edge" , remove_unused_imports = True )
14861469
14871470 assert file1 .content .strip () == EXPECTED_FILE_1_CONTENT .strip ()
14881471 assert file2 .content .strip () == EXPECTED_FILE_2_CONTENT .strip ()
0 commit comments