Skip to content

Commit

Permalink
add some context to the unused variable warning
Browse files Browse the repository at this point in the history
  • Loading branch information
zth committed Sep 23, 2024
1 parent f6b0038 commit a06fc64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

Warning number 26
/.../fixtures/unused_variable.res:2:7

1 │ let x = {
2 │ let f = 12
3 │ 13
4 │ }

unused variable f.

Fix this by:
- Prepending the variable name with `_` (like `_f`) to ignore that the variable is unused.
- Use the variable somewhere.
4 changes: 4 additions & 0 deletions jscomp/build_tests/super_errors/fixtures/unused_variable.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let x = {
let f = 12
13
}
3 changes: 2 additions & 1 deletion jscomp/ext/warnings.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ let message = function
| All_clauses_guarded ->
"this pattern-matching is not exhaustive.\n\
All clauses in this pattern-matching are guarded."
| Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "."
| Unused_var v | Unused_var_strict v ->
Format.sprintf "unused variable %s.\n\nFix this by:\n- Prepending the variable name with `_` (like `_%s`) to ignore that the variable is unused.\n- Use the variable somewhere." v v
| Wildcard_arg_to_constant_constr ->
"wildcard pattern given as argument to a constant constructor"
| Eol_in_string ->
Expand Down

0 comments on commit a06fc64

Please sign in to comment.