Skip to content
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

Fix hlint suggestions, update hlint.yaml #6680

Merged
merged 2 commits into from
Sep 13, 2020
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
4 changes: 3 additions & 1 deletion .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@
- ignore:
name: "Use camelCase"
within:
- Tests.Writers.Docbook
- Tests.Writers.Native
- Text.Pandoc.Extensions
- Text.Pandoc.Lua.Marshalling.Version
- Text.Pandoc.Lua.Marshaling.Version
- Text.Pandoc.Readers.Odt.ContentReader
- Text.Pandoc.Readers.Odt.Namespaces

Expand Down
2 changes: 1 addition & 1 deletion benchmark/weigh-pandoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ weighWriter :: Pandoc -> String -> (Pandoc -> Text) -> Weigh ()
weighWriter doc name writer = func (name ++ " writer") writer doc

weighReader :: Pandoc -> Text -> (Text -> Pandoc) -> Weigh ()
weighReader doc name reader = do
weighReader doc name reader =
case lookup name writers of
Just (TextWriter writer) ->
let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
Expand Down
7 changes: 3 additions & 4 deletions src/Text/Pandoc/App/CommandLineOptions.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE OverloadedStrings #-}
Expand Down Expand Up @@ -868,9 +869,7 @@ options =
, Option "" ["print-highlight-style"]
(ReqArg
(\arg opt -> do
let write = case optOutputFile opt of
Just f -> B.writeFile f
Nothing -> B.putStr
let write = maybe B.putStr B.writeFile $ optOutputFile opt
sty <- runIOorExplode $ lookupHighlightStyle arg
write $ encodePretty'
defConfig{confIndent = Spaces 4
Expand Down Expand Up @@ -1017,7 +1016,7 @@ lookupHighlightStyle s
deprecatedOption :: String -> String -> IO ()
deprecatedOption o msg =
runIO (report $ Deprecated (T.pack o) (T.pack msg)) >>=
\r -> case r of
\case
Right () -> return ()
Left e -> E.throwIO e

Expand Down
10 changes: 5 additions & 5 deletions src/Text/Pandoc/Class/PandocMonad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ getDefaultReferenceDocx = do
"word/theme/theme1.xml"]
let toLazy = BL.fromChunks . (:[])
let pathToEntry path = do
epochtime <- (floor . utcTimeToPOSIXSeconds) <$> getCurrentTime
epochtime <- floor . utcTimeToPOSIXSeconds <$> getCurrentTime
contents <- toLazy <$> readDataFile ("docx/" ++ path)
return $ toEntry path epochtime contents
datadir <- getUserDataDir
Expand Down Expand Up @@ -536,7 +536,7 @@ getDefaultReferencePptx = do
]
let toLazy = BL.fromChunks . (:[])
let pathToEntry path = do
epochtime <- (floor . utcTimeToPOSIXSeconds) <$> getCurrentTime
epochtime <- floor . utcTimeToPOSIXSeconds <$> getCurrentTime
contents <- toLazy <$> readDataFile ("pptx/" ++ path)
return $ toEntry path epochtime contents
datadir <- getUserDataDir
Expand Down Expand Up @@ -568,11 +568,11 @@ readDataFile fname = do
-- | Read file from from Cabal data directory.
readDefaultDataFile :: PandocMonad m => FilePath -> m B.ByteString
readDefaultDataFile "reference.docx" =
(B.concat . BL.toChunks . fromArchive) <$> getDefaultReferenceDocx
B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceDocx
readDefaultDataFile "reference.pptx" =
(B.concat . BL.toChunks . fromArchive) <$> getDefaultReferencePptx
B.concat . BL.toChunks . fromArchive <$> getDefaultReferencePptx
readDefaultDataFile "reference.odt" =
(B.concat . BL.toChunks . fromArchive) <$> getDefaultReferenceODT
B.concat . BL.toChunks . fromArchive <$> getDefaultReferenceODT
readDefaultDataFile fname =
#ifdef EMBED_DATA_FILES
case lookup (makeCanonical fname) dataFiles of
Expand Down
1 change: 0 additions & 1 deletion src/Text/Pandoc/Image.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, CPP #-}
{-# LANGUAGE ViewPatterns #-}
{- |
Module : Text.Pandoc.Image
Copyright : Copyright (C) 2020 John MacFarlane
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Pandoc/Logging.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Text.Pandoc.Logging
Expand Down Expand Up @@ -51,8 +52,7 @@ instance FromJSON Verbosity where
parseJSON _ = mzero

instance FromYAML Verbosity where
parseYAML = withStr "Verbosity" $ \t ->
case t of
parseYAML = withStr "Verbosity" $ \case
"ERROR" -> return ERROR
"WARNING" -> return WARNING
"INFO" -> return INFO
Expand Down
4 changes: 1 addition & 3 deletions src/Text/Pandoc/Lua/Marshaling/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ peekCaption idx = do
instance Peekable ColWidth where
peek idx = do
width <- Lua.fromOptional <$> Lua.peek idx
return $ case width of
Nothing -> ColWidthDefault
Just w -> ColWidth w
return $ maybe ColWidthDefault ColWidth width

instance Pushable ColWidth where
push = \case
Expand Down
5 changes: 2 additions & 3 deletions src/Text/Pandoc/Lua/Module/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ pushModule = do
-- | Squashes a list of blocks into inlines.
blocksToInlines :: [Block] -> Lua.Optional [Inline] -> PandocLua [Inline]
blocksToInlines blks optSep = liftPandocLua $ do
let sep = case Lua.fromOptional optSep of
Just x -> B.fromList x
Nothing -> Shared.defaultBlocksSeparator
let sep = maybe Shared.defaultBlocksSeparator B.fromList
$ Lua.fromOptional optSep
return $ B.toList (Shared.blocksToInlinesWithSep sep blks)

-- | Convert list of Pandoc blocks into sections using Divs.
Expand Down
5 changes: 3 additions & 2 deletions src/Text/Pandoc/Options.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{- |
Module : Text.Pandoc.Options
Copyright : Copyright (C) 2012-2020 John MacFarlane
Expand Down Expand Up @@ -327,7 +328,7 @@ $(deriveJSON defaultOptions{ constructorTagModifier =
} ''CiteMethod)

$(deriveJSON defaultOptions{ constructorTagModifier =
\t -> case t of
\case
"NoObfuscation" -> "none"
"ReferenceObfuscation" -> "references"
"JavascriptObfuscation" -> "javascript"
Expand Down
4 changes: 2 additions & 2 deletions src/Text/Pandoc/PDF.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- |
Expand Down Expand Up @@ -201,8 +202,7 @@ convertImage opts tmpdir fname = do
(\(e :: E.SomeException) -> return $ Left $
"check that rsvg-convert is in path.\n" <>
tshow e)
_ -> JP.readImage fname >>= \res ->
case res of
_ -> JP.readImage fname >>= \case
Left e -> return $ Left $ T.pack e
Right img ->
E.catch (Right pngOut <$ JP.savePngImage pngOut img) $
Expand Down
16 changes: 7 additions & 9 deletions src/Text/Pandoc/Parsing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,15 @@ romanNumeral upperCase = do
let fivehundred = rchar 'D'
let thousand = rchar 'M'
lookAhead $ choice [one, five, ten, fifty, hundred, fivehundred, thousand]
thousands <- ((1000 *) . length) <$> many thousand
thousands <- (1000 *) . length <$> many thousand
ninehundreds <- option 0 $ try $ hundred >> thousand >> return 900
fivehundreds <- option 0 $ 500 <$ fivehundred
fourhundreds <- option 0 $ try $ hundred >> fivehundred >> return 400
hundreds <- ((100 *) . length) <$> many hundred
hundreds <- (100 *) . length <$> many hundred
nineties <- option 0 $ try $ ten >> hundred >> return 90
fifties <- option 0 (50 <$ fifty)
forties <- option 0 $ try $ ten >> fifty >> return 40
tens <- ((10 *) . length) <$> many ten
tens <- (10 *) . length <$> many ten
nines <- option 0 $ try $ one >> ten >> return 9
fives <- option 0 (5 <$ five)
fours <- option 0 $ try $ one >> five >> return 4
Expand Down Expand Up @@ -951,7 +951,7 @@ tableWith' headerParser rowParser lineParser footerParser = try $ do
then replicate (length aligns) 0.0
else widthsFromIndices numColumns indices
let toRow = Row nullAttr . map B.simpleCell
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]
return (aligns, widths, toHeaderRow <$> heads, map toRow <$> lines')

-- Calculate relative widths of table columns, based on indices
Expand Down Expand Up @@ -1170,7 +1170,7 @@ class HasReaderOptions st where
extractReaderOptions :: st -> ReaderOptions
getOption :: (Stream s m t) => (ReaderOptions -> b) -> ParserT s st m b
-- default
getOption f = (f . extractReaderOptions) <$> getState
getOption f = f . extractReaderOptions <$> getState

instance HasReaderOptions ParserState where
extractReaderOptions = stateOptions
Expand Down Expand Up @@ -1492,10 +1492,8 @@ extractIdClass :: Attr -> Attr
extractIdClass (ident, cls, kvs) = (ident', cls', kvs')
where
ident' = fromMaybe ident (lookup "id" kvs)
cls' = case lookup "class" kvs of
Just cl -> T.words cl
Nothing -> cls
kvs' = filter (\(k,_) -> k /= "id" || k /= "class") kvs
cls' = maybe cls T.words $ lookup "class" kvs
kvs' = filter (\(k,_) -> k /= "id" || k /= "class") kvs

insertIncludedFile' :: (PandocMonad m, HasIncludeFiles st)
=> ParserT a st m (mf Blocks)
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Readers/CSV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ readCSV _opts s =
numcols = length r
toplain = B.simpleCell . B.plain . B.text . T.strip
toRow = Row nullAttr . map toplain
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]
hdrs = toHeaderRow r
rows = map toRow rs
aligns = replicate numcols AlignDefault
Expand Down
1 change: 0 additions & 1 deletion src/Text/Pandoc/Readers/CommonMark.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ViewPatterns #-}
{- |
Module : Text.Pandoc.Readers.CommonMark
Copyright : Copyright (C) 2015-2020 John MacFarlane
Expand Down
22 changes: 11 additions & 11 deletions src/Text/Pandoc/Readers/DocBook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Data.Either (rights)
import Data.Foldable (asum)
import Data.Generics
import Data.List (intersperse,elemIndex)
import Data.Maybe (fromMaybe,catMaybes)
import Data.Maybe (fromMaybe,mapMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Text.HTML.TagSoup.Entity (lookupEntity)
Expand Down Expand Up @@ -781,7 +781,7 @@ parseBlock (Elem e) =
"para" -> parseMixed para (elContent e)
"formalpara" -> do
tit <- case filterChild (named "title") e of
Just t -> (para . strong . (<> str ".")) <$>
Just t -> para . strong . (<> str ".") <$>
getInlines t
Nothing -> return mempty
(tit <>) <$> parseMixed para (elContent e)
Expand Down Expand Up @@ -897,7 +897,7 @@ parseBlock (Elem e) =
parseBlockquote = do
attrib <- case filterChild (named "attribution") e of
Nothing -> return mempty
Just z -> (para . (str "— " <>) . mconcat)
Just z -> para . (str "— " <>) . mconcat
<$>
mapM parseInline (elContent z)
contents <- getBlocks e
Expand Down Expand Up @@ -931,7 +931,7 @@ parseBlock (Elem e) =
_ -> filterChildren isColspec e'
let colnames = case colspecs of
[] -> []
cs -> catMaybes $ map (findAttr (unqual "colname" )) cs
cs -> mapMaybe (findAttr (unqual "colname" )) cs
let isRow x = named "row" x || named "tr" x
headrows <- case filterChild (named "thead") e' of
Just h -> case filterChild isRow h of
Expand Down Expand Up @@ -968,7 +968,7 @@ parseBlock (Elem e) =
in ColWidth . (/ tot) <$> ws'
Nothing -> replicate numrows ColWidthDefault
let toRow = Row nullAttr
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]
return $ table (simpleCaption $ plain capt)
(zip aligns widths)
(TableHead nullAttr $ toHeaderRow headrows)
Expand Down Expand Up @@ -1008,7 +1008,7 @@ parseBlock (Elem e) =
parseMixed :: PandocMonad m => (Inlines -> Blocks) -> [Content] -> DB m Blocks
parseMixed container conts = do
let (ils,rest) = break isBlockElement conts
ils' <- (trimInlines . mconcat) <$> mapM parseInline ils
ils' <- trimInlines . mconcat <$> mapM parseInline ils
let p = if ils' == mempty then mempty else container ils'
case rest of
[] -> return p
Expand Down Expand Up @@ -1036,10 +1036,10 @@ parseEntry cn el = do
case (mStrt, mEnd) of
(Just start, Just end) -> colDistance start end
_ -> 1
(fmap (cell AlignDefault 1 (toColSpan el)) . (parseMixed plain) . elContent) el
(fmap (cell AlignDefault 1 (toColSpan el)) . parseMixed plain . elContent) el

getInlines :: PandocMonad m => Element -> DB m Inlines
getInlines e' = (trimInlines . mconcat) <$>
getInlines e' = trimInlines . mconcat <$>
mapM parseInline (elContent e')

strContentRecursive :: Element -> String
Expand Down Expand Up @@ -1136,7 +1136,7 @@ parseInline (Elem e) =
"strong" -> strong <$> innerInlines
"strikethrough" -> strikeout <$> innerInlines
_ -> emph <$> innerInlines
"footnote" -> (note . mconcat) <$>
"footnote" -> note . mconcat <$>
mapM parseBlock (elContent e)
"title" -> return mempty
"affiliation" -> skip
Expand All @@ -1149,14 +1149,14 @@ parseInline (Elem e) =
lift $ report $ IgnoredElement $ T.pack $ qName (elName e)
return mempty

innerInlines = (trimInlines . mconcat) <$>
innerInlines = trimInlines . mconcat <$>
mapM parseInline (elContent e)
codeWithLang = do
let classes' = case attrValue "language" e of
"" -> []
l -> [l]
return $ codeWith (attrValue "id" e,classes',[]) $ T.pack $ strContentRecursive e
simpleList = (mconcat . intersperse (str "," <> space)) <$> mapM getInlines
simpleList = mconcat . intersperse (str "," <> space) <$> mapM getInlines
(filterChildren (named "member") e)
segmentedList = do
tit <- maybe (return mempty) getInlines $ filterChild (named "title") e
Expand Down
10 changes: 5 additions & 5 deletions src/Text/Pandoc/Readers/Docx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ readDocx :: PandocMonad m
=> ReaderOptions
-> B.ByteString
-> m Pandoc
readDocx opts bytes = do
readDocx opts bytes =
case toArchiveOrFail bytes of
Right archive -> do
Right archive ->
case archiveToDocxWithWarnings archive of
Right (docx, parserWarnings) -> do
mapM_ (P.report . DocxParserWarning) parserWarnings
Expand Down Expand Up @@ -291,9 +291,9 @@ runStyleToTransform rPr' = do
spanWith ("",[],[("dir","ltr")]) . go rPr{isRTL = Nothing}
| Just SupScrpt <- rVertAlign rPr =
superscript . go rPr{rVertAlign = Nothing}
| Just SubScrpt <- rVertAlign rPr = do
| Just SubScrpt <- rVertAlign rPr =
subscript . go rPr{rVertAlign = Nothing}
| Just "single" <- rUnderline rPr = do
| Just "single" <- rUnderline rPr =
Pandoc.underline . go rPr{rUnderline = Nothing}
| otherwise = id
return $ go rPr'
Expand Down Expand Up @@ -658,7 +658,7 @@ bodyPartToBlocks (Tbl cap _ look parts@(r:rs)) = do
rowLength (Docx.Row c) = length c

let toRow = Pandoc.Row nullAttr . map simpleCell
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]

-- pad cells. New Text.Pandoc.Builder will do that for us,
-- so this is for compatibility while we switch over.
Expand Down
12 changes: 3 additions & 9 deletions src/Text/Pandoc/Readers/Docx/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,8 @@ archiveToNotes zf =
>>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
enElem = findEntryByPath "word/endnotes.xml" zf
>>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
fn_namespaces = case fnElem of
Just e -> elemToNameSpaces e
Nothing -> []
en_namespaces = case enElem of
Just e -> elemToNameSpaces e
Nothing -> []
fn_namespaces = maybe [] elemToNameSpaces fnElem
en_namespaces = maybe [] elemToNameSpaces enElem
ns = unionBy (\x y -> fst x == fst y) fn_namespaces en_namespaces
fn = fnElem >>= walkDocument ns >>= elemToNotes ns "footnote"
en = enElem >>= walkDocument ns >>= elemToNotes ns "endnote"
Expand All @@ -420,9 +416,7 @@ archiveToComments :: Archive -> Comments
archiveToComments zf =
let cmtsElem = findEntryByPath "word/comments.xml" zf
>>= (parseXMLDoc . UTF8.toStringLazy . fromEntry)
cmts_namespaces = case cmtsElem of
Just e -> elemToNameSpaces e
Nothing -> []
cmts_namespaces = maybe [] elemToNameSpaces cmtsElem
cmts = elemToComments cmts_namespaces <$> (cmtsElem >>= walkDocument cmts_namespaces)
in
case cmts of
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Readers/DokuWiki.hs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ table = do
else ([], rows)
let attrs = (AlignDefault, ColWidthDefault) <$ transpose rows
let toRow = Row nullAttr . map B.simpleCell
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]
pure $ B.table B.emptyCaption
attrs
(TableHead nullAttr $ toHeaderRow headerRow)
Expand Down
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Readers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ pTable = try $ do
else replicate cols (ColWidth (1.0 / fromIntegral cols))
else widths'
let toRow = Row nullAttr . map B.simpleCell
toHeaderRow l = if null l then [] else [toRow l]
toHeaderRow l = [toRow l | not (null l)]
return $ B.tableWith attribs
(B.simpleCaption $ B.plain caption)
(zip aligns widths)
Expand Down
Loading