From 8adab239dfe806947f2824020b95226c15c77bcc Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Wed, 28 Oct 2020 12:42:35 -0400 Subject: [PATCH] Add recommended hlint rules for proper isNothing usage (#214) * Add recommended hlint rules for proper isNothing usage * Update changelog.md --- changelog.md | 6 ++++++ esqueleto.cabal | 2 +- src/Database/Esqueleto/Internal/Internal.hs | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6afbc96..6d7e415 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,9 @@ +3.3.4.1 + +- @maxgabriel + - [#214](https://github.com/bitemyapp/esqueleto/pull/214) + - Add suggested hlint rules for proper `isNothing` usage + 3.3.4.0 ======= - @parsonsmatt diff --git a/esqueleto.cabal b/esqueleto.cabal index 1fd0f78..4ebfa8e 100644 --- a/esqueleto.cabal +++ b/esqueleto.cabal @@ -1,7 +1,7 @@ cabal-version: 1.12 name: esqueleto -version: 3.3.4.0 +version: 3.3.4.1 synopsis: Type-safe EDSL for SQL queries on persistent backends. description: @esqueleto@ is a bare bones, type-safe EDSL for SQL queries that works with unmodified @persistent@ SQL backends. Its language closely resembles SQL, so you don't have to learn new concepts, just new syntax, and it's fairly easy to predict the generated SQL and optimize it for your backend. Most kinds of errors committed when writing SQL are caught as compile-time errors---although it is possible to write type-checked @esqueleto@ queries that fail at runtime. . diff --git a/src/Database/Esqueleto/Internal/Internal.hs b/src/Database/Esqueleto/Internal/Internal.hs index 0920806..592b46a 100644 --- a/src/Database/Esqueleto/Internal/Internal.hs +++ b/src/Database/Esqueleto/Internal/Internal.hs @@ -599,6 +599,13 @@ val v = ERaw Never $ const ("?", [toPersistValue v]) -- +----------------+----------------------------------+---------------+ -- -- In SQL, @= NULL@ and @!= NULL@ return NULL instead of true or false. For this reason, you very likely do not want to use @'!=.' Nothing@ in Esqueleto. +-- You may find these @hlint@ rules helpful to enforce this: +-- +-- > - error: {lhs: v ==. nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing} +-- > - error: {lhs: v ==. val Nothing, rhs: Database.Esqueleto.isNothing v, name: Use Esqueleto's isNothing} +-- > - error: {lhs: v !=. nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing} +-- > - error: {lhs: v !=. val Nothing, rhs: not_ (Database.Esqueleto.isNothing v), name: Use Esqueleto's not isNothing} + isNothing :: PersistField typ => SqlExpr (Value (Maybe typ)) -> SqlExpr (Value Bool)