Skip to content

Refactor Bool property checks to explicit Just True comparisons #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Formatting/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Core.NodePath (NodeSelector (..))
import Data.Function (on)
import Data.List (find, intercalate)
import Data.Map (Map)
import Data.Maybe (fromMaybe)
import Data.Sequence (Seq (..))
import Data.Text (Text)
import Data.Type.Equality ((:~:) (Refl))
Expand Down Expand Up @@ -134,14 +133,14 @@ lookupProp targetKey m =
applyPadLogic :: (Int -> Bool -> Node -> Text) -> Rule -> Node -> Text
applyPadLogic f rs n =
let padAmount = sum $ lookupProp PadAmount rs
padZeros = fromMaybe False $ lookupProp PadZeros rs
padZeros = (Just True == lookupProp PadZeros rs)
in f padAmount padZeros n

noComplexNewLine :: RuleSet -> NC.NodeCursor -> Bool
noComplexNewLine rs cursor =
let ps = findPropertiesForCursor cursor rs
maybeProp = lookupProp NoComplexNewLine ps
in fromMaybe False maybeProp
in (Just True == maybeProp)

comparePC :: NodePatternSelector -> NC.NodeBreadcrumb -> Bool
comparePC AnyKey (NC.ObjectIndexAndKey (_, _)) = True
Expand Down
7 changes: 3 additions & 4 deletions src/Parsing/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ patternParser :: Parser NodePattern
patternParser = NodePattern . Seq.fromList <$> MP.some patternSelectorParser

tryDecodeKey :: [Word8] -> (Text -> Maybe SomeKey) -> Maybe SomeKey
tryDecodeKey bs f = do
case decodeUtf8' (BS.pack bs) of
Right text' -> f text'
Left _ -> Nothing
tryDecodeKey bs f = case decodeUtf8' (BS.pack bs) of
Right text' -> f text'
Left _ -> Nothing

propertyParser :: SomeKey -> Parser (SomeKey, SomeProperty)
propertyParser (SomeKey key) = do
Expand Down