Fix all 20 hlint warnings across 5 source files
Build and Deploy / build-and-deploy (push) Successful in 12m38s

- Use newtype instead of data for single-field types (RouxConfig, ImportError)
- Replace maybe "" id with fromMaybe "" throughout
- Replace not (x `elem` ys) with x `notElem` ys
- Remove redundant brackets, redundant $, and eta-reduce lookupRecipe
- Use numeric underscore for 1_000_000
This commit is contained in:
2026-05-25 21:30:21 -04:00
parent 67c3b4df6c
commit ed015d3799
5 changed files with 22 additions and 22 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ import qualified Fleece.Core as FC
import System.Directory (doesFileExist) import System.Directory (doesFileExist)
-- | Top-level config. -- | Top-level config.
data RouxConfig = RouxConfig newtype RouxConfig = RouxConfig
{ rcAnthropic :: Maybe AnthropicConfig { rcAnthropic :: Maybe AnthropicConfig
} }
deriving stock (Eq, Show) deriving stock (Eq, Show)
+2 -2
View File
@@ -13,7 +13,7 @@ module Roux.CooklangPrint (
import Data.Char (isAlphaNum) import Data.Char (isAlphaNum)
import Data.Function ((&)) import Data.Function ((&))
import Data.List.NonEmpty (toList) import Data.List.NonEmpty (toList)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes, fromMaybe)
import Data.Ratio (denominator, numerator) import Data.Ratio (denominator, numerator)
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
@@ -69,7 +69,7 @@ renderDurationText d =
n = numerator amt n = numerator amt
d' = denominator amt d' = denominator amt
amount = if d' == 1 then T.pack (show n) else T.pack (show n <> "/" <> show d') amount = if d' == 1 then T.pack (show n) else T.pack (show n <> "/" <> show d')
unit = maybe "" id (durationUnit d) unit = fromMaybe "" (durationUnit d)
in T.strip (amount <> " " <> unit) in T.strip (amount <> " " <> unit)
-- | Render a tag list as a comma-separated string. -- | Render a tag list as a comma-separated string.
+2 -2
View File
@@ -49,7 +49,7 @@ data SortMode
deriving stock (Eq, Show) deriving stock (Eq, Show)
-- | Error type for the import pipeline. -- | Error type for the import pipeline.
data ImportError = ImportError Text newtype ImportError = ImportError Text
deriving stock (Eq, Show) deriving stock (Eq, Show)
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
@@ -982,7 +982,7 @@ renderMethodSections sections = do
isMethodSection :: Section -> Bool isMethodSection :: Section -> Bool
isMethodSection section = isMethodSection section =
case sectionName section of case sectionName section of
Just n -> not (T.toLower n `elem` ["ingredients", "ingredient"]) Just n -> T.toLower n `notElem` ["ingredients", "ingredient"]
Nothing -> True Nothing -> True
-- | Extract (section name, body items) from a section for the method column. -- | Extract (section name, body items) from a section for the method column.
+1 -1
View File
@@ -401,7 +401,7 @@ parseSimpleRational t =
case T.splitOn "/" t of case T.splitOn "/" t of
-- Fraction: "1/2" -- Fraction: "1/2"
[num, den] -> [num, den] ->
case (readInt (num), readInt (den)) of case (readInt num, readInt den) of
(Just n, Just d) | d /= 0 -> Just (toRational n / toRational d) (Just n, Just d) | d /= 0 -> Just (toRational n / toRational d)
_ -> Nothing _ -> Nothing
-- Whole number or decimal: "3", "0.5", or range like "14-18" -- Whole number or decimal: "3", "0.5", or range like "14-18"
+16 -16
View File
@@ -45,7 +45,7 @@ import System.FilePath (makeRelative, takeBaseName, takeExtension, (</>))
import qualified Data.Aeson as A import qualified Data.Aeson as A
import qualified Data.Aeson.KeyMap as KM import qualified Data.Aeson.KeyMap as KM
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import Data.Maybe (mapMaybe) import Data.Maybe (fromMaybe, mapMaybe)
import qualified Data.Text.Encoding as TE import qualified Data.Text.Encoding as TE
import Roux.Config (AnthropicConfig (..), RouxConfig (..)) import Roux.Config (AnthropicConfig (..), RouxConfig (..))
import qualified Roux.CooklangPrint as CooklangPrint import qualified Roux.CooklangPrint as CooklangPrint
@@ -203,11 +203,11 @@ importHandler recipeDir config _state request respond =
"POST" -> do "POST" -> do
body <- readRequestBody request body <- readRequestBody request
let params = parseFormBody body let params = parseFormBody body
url = maybe "" id (lookup "url" params) url = fromMaybe "" (lookup "url" params)
text = maybe "" id (lookup "text" params) text = fromMaybe "" (lookup "text" params)
fileB64 = maybe "" id (lookup "file-b64" params) fileB64 = fromMaybe "" (lookup "file-b64" params)
fileName = maybe "" id (lookup "file-name" params) fileName = fromMaybe "" (lookup "file-name" params)
fileMime = maybe "" id (lookup "file-mime" params) fileMime = fromMaybe "" (lookup "file-mime" params)
hasFile = not (T.null fileB64) hasFile = not (T.null fileB64)
putStrLn $ putStrLn $
@@ -403,7 +403,7 @@ runFileImport recipeDir config originalName _mimeType b64Text = do
Nothing -> Nothing ->
pure $ pure $
Left $ Left $
Html.ImportError $ Html.ImportError
"LLM import is not configured. Add an anthropic.api_key to the config file." "LLM import is not configured. Add an anthropic.api_key to the config file."
Just anthropicConfig -> do Just anthropicConfig -> do
result <- runLLMPipeline recipeDir anthropicConfig (Just sourceUrl) (Just sourcePath) "" result <- runLLMPipeline recipeDir anthropicConfig (Just sourceUrl) (Just sourcePath) ""
@@ -422,7 +422,7 @@ runTextImport recipeDir config text = do
Nothing -> Nothing ->
pure $ pure $
Left $ Left $
Html.ImportError $ Html.ImportError
"LLM import is not configured. Add an anthropic.api_key to the config file." "LLM import is not configured. Add an anthropic.api_key to the config file."
Just anthropicConfig -> Just anthropicConfig ->
runLLMPipeline recipeDir anthropicConfig Nothing Nothing text runLLMPipeline recipeDir anthropicConfig Nothing Nothing text
@@ -474,7 +474,7 @@ runLLMPipeline recipeDir anthropicConfig mSourceUrl mFilePath text = do
putStrLn "[roux] could not extract title from Cooklang output" putStrLn "[roux] could not extract title from Cooklang output"
return $ return $
Left $ Left $
Html.ImportError $ Html.ImportError
"Could not determine recipe title from AI output." "Could not determine recipe title from AI output."
Just title -> do Just title -> do
let filename = CooklangPrint.filenameFromTitle title let filename = CooklangPrint.filenameFromTitle title
@@ -570,7 +570,7 @@ watchRecipes dir state changeLog = do
"[roux] watchDir callback error: " <> show (e :: SomeException) "[roux] watchDir callback error: " <> show (e :: SomeException)
) )
-- Keep the thread alive (watchDir runs the callback on the manager thread) -- Keep the thread alive (watchDir runs the callback on the manager thread)
forever $ threadDelay 1000000 forever $ threadDelay 1_000_000
{- | Re-read a single recipe file and update the shared state. {- | Re-read a single recipe file and update the shared state.
On read/parse errors, logs the error and keeps the previous version. On read/parse errors, logs the error and keeps the previous version.
@@ -596,7 +596,7 @@ reReadRecipe dir path state changeLog = do
Right info -> case Idx.riRecipe info of Right info -> case Idx.riRecipe info of
Left err -> do Left err -> do
putStrLn $ "[roux] parse error in " <> path <> ": " <> err putStrLn $ "[roux] parse error in " <> path <> ": " <> err
putStrLn $ "[roux] keeping previous version" putStrLn "[roux] keeping previous version"
Right _ -> do Right _ -> do
atomicModifyIORef' state $ \m -> atomicModifyIORef' state $ \m ->
(Map.insert key info m, ()) (Map.insert key info m, ())
@@ -624,8 +624,8 @@ handleRequest state request respond = do
-- | Look up a recipe by filename (case-insensitive, .cook extension optional). -- | Look up a recipe by filename (case-insensitive, .cook extension optional).
lookupRecipe :: FilePath -> Map FilePath Idx.RecipeInfo -> Maybe Idx.RecipeInfo lookupRecipe :: FilePath -> Map FilePath Idx.RecipeInfo -> Maybe Idx.RecipeInfo
lookupRecipe target recipes = lookupRecipe target =
Map.lookup (map toLower (stripCookExt target)) recipes Map.lookup (map toLower (stripCookExt target))
-- | Strip the .cook extension if present. -- | Strip the .cook extension if present.
stripCookExt :: FilePath -> FilePath stripCookExt :: FilePath -> FilePath
@@ -666,9 +666,9 @@ uploadImageHandler recipeDir _state request respond =
"POST" -> do "POST" -> do
body <- readRequestBody request body <- readRequestBody request
let params = parseFormBody body let params = parseFormBody body
filename = maybe "" id (lookup "filename" params) filename = fromMaybe "" (lookup "filename" params)
fileB64 = maybe "" id (lookup "file-b64" params) fileB64 = fromMaybe "" (lookup "file-b64" params)
originalName = maybe "" id (lookup "file-name" params) originalName = fromMaybe "" (lookup "file-name" params)
if T.null filename if T.null filename
then respond (jsonError "Missing 'filename' parameter") then respond (jsonError "Missing 'filename' parameter")
else else