From 7295b335dfbda17015e68f4c74b81e91007f79b8 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 15 Nov 2021 10:01:32 -0500 Subject: [PATCH] Add docs for `UnusedName` warning (#411) * Add docs for `UnusedName` warning * Update example --- errors/UnusedName.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 errors/UnusedName.md diff --git a/errors/UnusedName.md b/errors/UnusedName.md new file mode 100644 index 0000000..dbe1186 --- /dev/null +++ b/errors/UnusedName.md @@ -0,0 +1,37 @@ +# `UnusedName` Warning + +## Example + +```purescript +module UnusedNameExample where + +plus :: Int -> Int -> Int +plus x y = y -- Name x was introduced but not used. + +ignore :: forall a. a -> Unit +ignore value = unit -- Name value was introduced but not used. +``` + +## Cause + +This warning occurs when a name is introduced but is not used anywhere. + +PureScript warns in this case because it could indicate a bug due to a value not being referenced where it should be. + +## Fix + +If the unused name was unintentional, make use of it to fix the warning: + +```purescript +plus :: Int -> Int -> Int +plus x y = x + y +``` + +If the unused name is intentional, mark the name as unused by prefixing it with a `_`: + +```purescript +ignore :: forall a. a -> Unit +ignore _value = unit +``` + +## Notes