Skip to content

Commit e3d328a

Browse files
authored
v.parser: improve the unused import warning message (add fixing alternatives) (#25880)
1 parent 58477f3 commit e3d328a

13 files changed

+16
-22
lines changed

vlib/v/checker/tests/decompose_interface_err.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/decompose_interface_err.vv:3:8: warning: module 'arrays' is imported but never used
1+
vlib/v/checker/tests/decompose_interface_err.vv:3:8: warning: module 'arrays' is imported but never used. Use `import arrays as _`, to silence this warning, or just remove the unused import line
22
1 | module main
33
2 |
44
3 | import arrays

vlib/v/checker/tests/fn_param_import_sym_conflict.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:1:8: warning: module 'arrays' is imported but never used
1+
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:1:8: warning: module 'arrays' is imported but never used. Use `import arrays as _`, to silence this warning, or just remove the unused import line
22
1 | import arrays
33
| ~~~~~~
44
2 | import maps
55
3 | import strings as strs
6-
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:2:8: warning: module 'maps' is imported but never used
6+
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:2:8: warning: module 'maps' is imported but never used. Use `import maps as _`, to silence this warning, or just remove the unused import line
77
1 | import arrays
88
2 | import maps
99
| ~~~~
1010
3 | import strings as strs
1111
4 |
12-
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:3:8: warning: module 'strs (strings)' is imported but never used
12+
vlib/v/checker/tests/fn_param_import_sym_conflict.vv:3:8: warning: module 'strs (strings)' is imported but never used. Use `import strs (strings) as _`, to silence this warning, or just remove the unused import line
1313
1 | import arrays
1414
2 | import maps
1515
3 | import strings as strs

vlib/v/checker/tests/import_symbol_fn_err.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/import_symbol_fn_err.vv:1:8: warning: module 'crypto' is imported but never used
1+
vlib/v/checker/tests/import_symbol_fn_err.vv:1:8: warning: module 'crypto' is imported but never used. Use `import crypto as _`, to silence this warning, or just remove the unused import line
22
1 | import crypto { userper }
33
| ~~~~~~
44
2 | fn main() {

vlib/v/checker/tests/import_unused_warning.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/import_unused_warning.vv:2:8: warning: module 'time' is imported but never used
1+
vlib/v/checker/tests/import_unused_warning.vv:2:8: warning: module 'time' is imported but never used. Use `import time as _`, to silence this warning, or just remove the unused import line
22
1 | import os as _
33
2 | import time
44
| ~~~~

vlib/v/checker/tests/incorrect_name_module.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/incorrect_name_module.vv:4:8: warning: module 'os' is imported but never used
1+
vlib/v/checker/tests/incorrect_name_module.vv:4:8: warning: module 'os' is imported but never used. Use `import os as _`, to silence this warning, or just remove the unused import line
22
2 |
33
3 | import math as _
44
4 | import os

vlib/v/checker/tests/os_prefix.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/os_prefix.vv:1:8: warning: module 'os' is imported but never used
1+
vlib/v/checker/tests/os_prefix.vv:1:8: warning: module 'os' is imported but never used. Use `import os as _`, to silence this warning, or just remove the unused import line
22
1 | import os
33
| ~~
44
2 |

vlib/v/checker/tests/selective_const_import.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/selective_const_import.vv:1:8: warning: module 'time' is imported but never used
1+
vlib/v/checker/tests/selective_const_import.vv:1:8: warning: module 'time' is imported but never used. Use `import time as _`, to silence this warning, or just remove the unused import line
22
1 | import time { second }
33
| ~~~~
44
vlib/v/checker/tests/selective_const_import.vv:1:15: error: cannot selectively import constant `second` from `time`, import `time` and use `time.second` instead

vlib/v/checker/tests/unused_import_err.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
vlib/v/checker/tests/unused_import_err.vv:1:8: warning: module 'te (term)' is imported but never used
1+
vlib/v/checker/tests/unused_import_err.vv:1:8: warning: module 'te (term)' is imported but never used. Use `import te (term) as _`, to silence this warning, or just remove the unused import line
22
1 | import term as te
33
| ~~~~
44
2 | import te.ui
5-
vlib/v/checker/tests/unused_import_err.vv:2:8: warning: module 'ui (te.ui)' is imported but never used
5+
vlib/v/checker/tests/unused_import_err.vv:2:8: warning: module 'ui (te.ui)' is imported but never used. Use `import ui (te.ui) as _`, to silence this warning, or just remove the unused import line
66
1 | import term as te
77
2 | import te.ui
88
| ~~~~~

vlib/v/checker/tests/var_decl_import_sym_conflict.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
vlib/v/checker/tests/var_decl_import_sym_conflict.vv:1:8: warning: module 'arrays' is imported but never used
1+
vlib/v/checker/tests/var_decl_import_sym_conflict.vv:1:8: warning: module 'arrays' is imported but never used. Use `import arrays as _`, to silence this warning, or just remove the unused import line
22
1 | import arrays
33
| ~~~~~~
44
2 |

vlib/v/parser/module.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ fn (mut p Parser) check_unused_imports() {
8989
if !(alias.len == 1 && alias[0] == `_`) && !p.is_used_import(alias)
9090
&& alias !in p.auto_imports {
9191
mod_alias := if alias == mod { alias } else { '${alias} (${mod})' }
92-
p.warn_with_pos("module '${mod_alias}' is imported but never used", import_m.mod_pos)
92+
p.warn_with_pos("module '${mod_alias}' is imported but never used. Use `import ${mod_alias} as _`, to silence this warning, or just remove the unused import line",
93+
import_m.mod_pos)
9394
}
9495
}
9596
}

0 commit comments

Comments
 (0)