Skip to content

Commit 4700240

Browse files
authored
Refactor Bool property checks to explicit Just True comparisons (#3)
* Refactor Bool property checks to explicit `Just True` comparisons - Replace fromMaybe False maybeProp with (Just True == maybeProp) for clarity and precision - Simplify tryDecodeKey by removing unnecessary do block and using direct case expression - Improve readability by making boolean property checks more explicit - Removed Data.Maybe import Formatting.Rules
1 parent ba68e4f commit 4700240

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/Formatting/Rules.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Core.NodePath (NodeSelector (..))
2525
import Data.Function (on)
2626
import Data.List (find, intercalate)
2727
import Data.Map (Map)
28-
import Data.Maybe (fromMaybe)
2928
import Data.Sequence (Seq (..))
3029
import Data.Text (Text)
3130
import Data.Type.Equality ((:~:) (Refl))
@@ -134,14 +133,14 @@ lookupProp targetKey m =
134133
applyPadLogic :: (Int -> Bool -> Node -> Text) -> Rule -> Node -> Text
135134
applyPadLogic f rs n =
136135
let padAmount = sum $ lookupProp PadAmount rs
137-
padZeros = fromMaybe False $ lookupProp PadZeros rs
136+
padZeros = (Just True == lookupProp PadZeros rs)
138137
in f padAmount padZeros n
139138

140139
noComplexNewLine :: RuleSet -> NC.NodeCursor -> Bool
141140
noComplexNewLine rs cursor =
142141
let ps = findPropertiesForCursor cursor rs
143142
maybeProp = lookupProp NoComplexNewLine ps
144-
in fromMaybe False maybeProp
143+
in (Just True == maybeProp)
145144

146145
comparePC :: NodePatternSelector -> NC.NodeBreadcrumb -> Bool
147146
comparePC AnyKey (NC.ObjectIndexAndKey (_, _)) = True

src/Parsing/DSL.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ patternParser :: Parser NodePattern
5656
patternParser = NodePattern . Seq.fromList <$> MP.some patternSelectorParser
5757

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

6463
propertyParser :: SomeKey -> Parser (SomeKey, SomeProperty)
6564
propertyParser (SomeKey key) = do

0 commit comments

Comments
 (0)