Skip to content

Commit

Permalink
Use purs-tidy for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
drewolson committed Aug 8, 2021
1 parent 19f990c commit 9f6ef3f
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 199 deletions.
8 changes: 8 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "source",
"width": null
}
173 changes: 30 additions & 143 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
"repository": "https://github.com/drewolson/purescript-biscotti-cookie",
"license": "MIT",
"scripts": {
"ci": "npm run test && npm run format:check",
"ci": "npm run test",
"test": "spago test",
"format": "find src test -name \"*.purs\" | xargs -n1 purty format --write",
"format:check": "find src test -name \"*.purs\" | xargs -n1 purty validate"
"format": "purs-tidy format-in-place 'src/**/*.purs' && purs-tidy format-in-place 'test/**/*.purs'"
},
"devDependencies": {
"purescript": "^0.14.0",
"purescript-language-server": "^0.12.7",
"purty": "^6.2.0",
"spago": "^0.19.1",
"purescript": "^0.14.3",
"purs-tidy": "^0.2.2",
"spago": "^0.20.0",
"ssri": ">=8.0.1"
}
}
18 changes: 9 additions & 9 deletions src/Biscotti/Cookie/Generator.purs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ stringify :: Cookie -> String
stringify cookie =
intercalate "; "
$ catMaybes
[ attr (getName cookie) $ Just (getValue cookie)
, attr domainTag $ getDomain cookie
, attr pathTag $ getPath cookie
, attr expiresTag $ formatDateTime <$> getExpires cookie
, attr maxAgeTag $ show <$> getMaxAge cookie
, attr sameSiteTag $ show <$> getSameSite cookie
, flag secureTag $ getSecure cookie
, flag httpOnlyTag $ getHttpOnly cookie
]
[ attr (getName cookie) $ Just (getValue cookie)
, attr domainTag $ getDomain cookie
, attr pathTag $ getPath cookie
, attr expiresTag $ formatDateTime <$> getExpires cookie
, attr maxAgeTag $ show <$> getMaxAge cookie
, attr sameSiteTag $ show <$> getSameSite cookie
, flag secureTag $ getSecure cookie
, flag httpOnlyTag $ getHttpOnly cookie
]

attr :: String -> Maybe String -> Maybe String
attr name = case _ of
Expand Down
29 changes: 14 additions & 15 deletions src/Biscotti/Cookie/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ instance showSameSite :: Show SameSite where
show Lax = "Lax"
show None = "None"

type CookieFields
= { name :: String
, value :: String
, domain :: Maybe String
, path :: Maybe String
, expires :: Maybe DateTime
, maxAge :: Maybe Int
, sameSite :: Maybe SameSite
, secure :: Boolean
, httpOnly :: Boolean
}
type CookieFields =
{ name :: String
, value :: String
, domain :: Maybe String
, path :: Maybe String
, expires :: Maybe DateTime
, maxAge :: Maybe Int
, sameSite :: Maybe SameSite
, secure :: Boolean
, httpOnly :: Boolean
}

-- | The `Cookie` type
newtype Cookie
= Cookie CookieFields
newtype Cookie = Cookie CookieFields

derive newtype instance eqCookie :: Eq Cookie

Expand Down Expand Up @@ -105,8 +104,8 @@ fromFields = Cookie
expire :: Cookie -> Effect (Either String Cookie)
expire cookie = do
now <- nowDateTime
let
maybeDate = DateTime.adjust (Days $ -1.0) now
let maybeDate = DateTime.adjust (Days $ -1.0) now

case maybeDate of
Nothing -> pure $ Left "Invalid date"
Just yesterday -> pure $ Right $ setExpires yesterday cookie
Expand Down
Loading

0 comments on commit 9f6ef3f

Please sign in to comment.