Skip to content

Commit

Permalink
Add some context to the unused variable warning (#7050)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
zth and cknitt committed Sep 24, 2024
1 parent e6fc84e commit 915dc14
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#### :nail_care: Polish

- Add some context to error message for unused variables. https://github.com/rescript-lang/rescript-compiler/pull/7050
- Improve error message when passing `children` prop to a component that doesn't accept it. https://github.com/rescript-lang/rescript-compiler/pull/7044
- Improve error messages for pattern matching on option vs non-option, and vice versa. https://github.com/rescript-lang/rescript-compiler/pull/7035
- Improve bigint literal comparison. https://github.com/rescript-lang/rescript-compiler/pull/7029
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

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:
- Deleting the variable if it's not used anymiore.
- Prepending the variable name with `_` (like `_f`) to ignore that the variable is unused.
- Using 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- 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
| Wildcard_arg_to_constant_constr ->
"wildcard pattern given as argument to a constant constructor"
| Eol_in_string ->
Expand Down

0 comments on commit 915dc14

Please sign in to comment.