Skip to content

Commit 915dc14

Browse files
zthcknitt
andauthored
Add some context to the unused variable warning (#7050)
* add some context to the unused variable warning * changelog * Update jscomp/build_tests/super_errors/expected/unused_variable.res.expected Co-authored-by: Christoph Knittel <ck@cca.io> * Update jscomp/ext/warnings.ml Co-authored-by: Christoph Knittel <ck@cca.io> * add suggestion to remove unused variable --------- Co-authored-by: Christoph Knittel <ck@cca.io>
1 parent e6fc84e commit 915dc14

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#### :nail_care: Polish
2424

25+
- Add some context to error message for unused variables. https://github.com/rescript-lang/rescript-compiler/pull/7050
2526
- Improve error message when passing `children` prop to a component that doesn't accept it. https://github.com/rescript-lang/rescript-compiler/pull/7044
2627
- Improve error messages for pattern matching on option vs non-option, and vice versa. https://github.com/rescript-lang/rescript-compiler/pull/7035
2728
- Improve bigint literal comparison. https://github.com/rescript-lang/rescript-compiler/pull/7029
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
Warning number 26
3+
/.../fixtures/unused_variable.res:2:7
4+
5+
1 │ let x = {
6+
2 │ let f = 12
7+
3 │ 13
8+
4 │ }
9+
10+
unused variable f.
11+
12+
Fix this by:
13+
- Deleting the variable if it's not used anymiore.
14+
- Prepending the variable name with `_` (like `_f`) to ignore that the variable is unused.
15+
- Using the variable somewhere.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let x = {
2+
let f = 12
3+
13
4+
}

jscomp/ext/warnings.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ let message = function
378378
| All_clauses_guarded ->
379379
"this pattern-matching is not exhaustive.\n\
380380
All clauses in this pattern-matching are guarded."
381-
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
381+
| Unused_var v | Unused_var_strict v ->
382+
Format.sprintf "unused variable %s.\n\nFix this by:\n- Deleting the variable if it's not used anymiore.\n- Prepending the variable name with `_` (like `_%s`) to ignore that the variable is unused.\n- Using the variable somewhere." v v
382383
| Wildcard_arg_to_constant_constr ->
383384
"wildcard pattern given as argument to a constant constructor"
384385
| Eol_in_string ->

0 commit comments

Comments
 (0)