Fix all 20 hlint warnings across 5 source files
Build and Deploy / build-and-deploy (push) Successful in 12m38s
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:
+1
-1
@@ -21,7 +21,7 @@ import qualified Fleece.Core as FC
|
||||
import System.Directory (doesFileExist)
|
||||
|
||||
-- | Top-level config.
|
||||
data RouxConfig = RouxConfig
|
||||
newtype RouxConfig = RouxConfig
|
||||
{ rcAnthropic :: Maybe AnthropicConfig
|
||||
}
|
||||
deriving stock (Eq, Show)
|
||||
|
||||
@@ -13,7 +13,7 @@ module Roux.CooklangPrint (
|
||||
import Data.Char (isAlphaNum)
|
||||
import Data.Function ((&))
|
||||
import Data.List.NonEmpty (toList)
|
||||
import Data.Maybe (catMaybes)
|
||||
import Data.Maybe (catMaybes, fromMaybe)
|
||||
import Data.Ratio (denominator, numerator)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
@@ -69,7 +69,7 @@ renderDurationText d =
|
||||
n = numerator amt
|
||||
d' = denominator amt
|
||||
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)
|
||||
|
||||
-- | Render a tag list as a comma-separated string.
|
||||
|
||||
+2
-2
@@ -49,7 +49,7 @@ data SortMode
|
||||
deriving stock (Eq, Show)
|
||||
|
||||
-- | Error type for the import pipeline.
|
||||
data ImportError = ImportError Text
|
||||
newtype ImportError = ImportError Text
|
||||
deriving stock (Eq, Show)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -982,7 +982,7 @@ renderMethodSections sections = do
|
||||
isMethodSection :: Section -> Bool
|
||||
isMethodSection section =
|
||||
case sectionName section of
|
||||
Just n -> not (T.toLower n `elem` ["ingredients", "ingredient"])
|
||||
Just n -> T.toLower n `notElem` ["ingredients", "ingredient"]
|
||||
Nothing -> True
|
||||
|
||||
-- | Extract (section name, body items) from a section for the method column.
|
||||
|
||||
@@ -401,7 +401,7 @@ parseSimpleRational t =
|
||||
case T.splitOn "/" t of
|
||||
-- Fraction: "1/2"
|
||||
[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)
|
||||
_ -> Nothing
|
||||
-- Whole number or decimal: "3", "0.5", or range like "14-18"
|
||||
|
||||
+16
-16
@@ -45,7 +45,7 @@ import System.FilePath (makeRelative, takeBaseName, takeExtension, (</>))
|
||||
import qualified Data.Aeson as A
|
||||
import qualified Data.Aeson.KeyMap as KM
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.Maybe (mapMaybe)
|
||||
import Data.Maybe (fromMaybe, mapMaybe)
|
||||
import qualified Data.Text.Encoding as TE
|
||||
import Roux.Config (AnthropicConfig (..), RouxConfig (..))
|
||||
import qualified Roux.CooklangPrint as CooklangPrint
|
||||
@@ -203,11 +203,11 @@ importHandler recipeDir config _state request respond =
|
||||
"POST" -> do
|
||||
body <- readRequestBody request
|
||||
let params = parseFormBody body
|
||||
url = maybe "" id (lookup "url" params)
|
||||
text = maybe "" id (lookup "text" params)
|
||||
fileB64 = maybe "" id (lookup "file-b64" params)
|
||||
fileName = maybe "" id (lookup "file-name" params)
|
||||
fileMime = maybe "" id (lookup "file-mime" params)
|
||||
url = fromMaybe "" (lookup "url" params)
|
||||
text = fromMaybe "" (lookup "text" params)
|
||||
fileB64 = fromMaybe "" (lookup "file-b64" params)
|
||||
fileName = fromMaybe "" (lookup "file-name" params)
|
||||
fileMime = fromMaybe "" (lookup "file-mime" params)
|
||||
hasFile = not (T.null fileB64)
|
||||
|
||||
putStrLn $
|
||||
@@ -403,7 +403,7 @@ runFileImport recipeDir config originalName _mimeType b64Text = do
|
||||
Nothing ->
|
||||
pure $
|
||||
Left $
|
||||
Html.ImportError $
|
||||
Html.ImportError
|
||||
"LLM import is not configured. Add an anthropic.api_key to the config file."
|
||||
Just anthropicConfig -> do
|
||||
result <- runLLMPipeline recipeDir anthropicConfig (Just sourceUrl) (Just sourcePath) ""
|
||||
@@ -422,7 +422,7 @@ runTextImport recipeDir config text = do
|
||||
Nothing ->
|
||||
pure $
|
||||
Left $
|
||||
Html.ImportError $
|
||||
Html.ImportError
|
||||
"LLM import is not configured. Add an anthropic.api_key to the config file."
|
||||
Just anthropicConfig ->
|
||||
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"
|
||||
return $
|
||||
Left $
|
||||
Html.ImportError $
|
||||
Html.ImportError
|
||||
"Could not determine recipe title from AI output."
|
||||
Just title -> do
|
||||
let filename = CooklangPrint.filenameFromTitle title
|
||||
@@ -570,7 +570,7 @@ watchRecipes dir state changeLog = do
|
||||
"[roux] watchDir callback error: " <> show (e :: SomeException)
|
||||
)
|
||||
-- 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.
|
||||
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
|
||||
Left err -> do
|
||||
putStrLn $ "[roux] parse error in " <> path <> ": " <> err
|
||||
putStrLn $ "[roux] keeping previous version"
|
||||
putStrLn "[roux] keeping previous version"
|
||||
Right _ -> do
|
||||
atomicModifyIORef' state $ \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).
|
||||
lookupRecipe :: FilePath -> Map FilePath Idx.RecipeInfo -> Maybe Idx.RecipeInfo
|
||||
lookupRecipe target recipes =
|
||||
Map.lookup (map toLower (stripCookExt target)) recipes
|
||||
lookupRecipe target =
|
||||
Map.lookup (map toLower (stripCookExt target))
|
||||
|
||||
-- | Strip the .cook extension if present.
|
||||
stripCookExt :: FilePath -> FilePath
|
||||
@@ -666,9 +666,9 @@ uploadImageHandler recipeDir _state request respond =
|
||||
"POST" -> do
|
||||
body <- readRequestBody request
|
||||
let params = parseFormBody body
|
||||
filename = maybe "" id (lookup "filename" params)
|
||||
fileB64 = maybe "" id (lookup "file-b64" params)
|
||||
originalName = maybe "" id (lookup "file-name" params)
|
||||
filename = fromMaybe "" (lookup "filename" params)
|
||||
fileB64 = fromMaybe "" (lookup "file-b64" params)
|
||||
originalName = fromMaybe "" (lookup "file-name" params)
|
||||
if T.null filename
|
||||
then respond (jsonError "Missing 'filename' parameter")
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user