checkmate 0.1.4 → 0.2.0
raw patch · 7 files changed
+150/−25 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +76/−0
- checkmate.cabal +2/−1
- src/Checkmate/Parser/CheckFile.hs +1/−0
- src/Checkmate/Parser/IndentBlock.hs +45/−15
- test/Checkmate/DiscoverSpec.hs +5/−5
- test/Checkmate/Parser/CheckFileSpec.hs +2/−1
- test/Checkmate/Parser/IndentBlockSpec.hs +19/−3
+ CHANGELOG.md view
@@ -0,0 +1,76 @@+Checkmate changelog+===================++Version 0.2.0+-------------++Released on September 25, 2017.++ - Now `CHECK` comments in source codes can be multiline. The following+ patterns are supported:++ - ~~~ c+ /*+ CHECK Lorem ipsum dolor sit amet, per facilis reprimique ut,+ ei agam invenire mel.++ Tacimates nominati vix ut, ea iudicabit prodesset deseruisse duo.+ */+ ~~~++ - ~~~ c+ // CHECK Lorem ipsum dolor sit amet, per facilis reprimique ut,+ // ei agam invenire mel.+ //+ // Tacimates nominati vix ut, ea iudicabit prodesset deseruisse duo.+ ~~~++ - `CHECK` keywords with a colon (i.e. `CHECK:`) became matched.+++Version 0.1.4+-------------++Released on September 21, 2017.++ - Fixed a broken build of `checkmate` binary on the download page.+ It was crashed on Linux distros that glibc is unavailable.+++Version 0.1.3+-------------++Released on September 20, 2017.++ - Fixed a broken build of `checkmate` binary on the download page.+++Version 0.1.2+-------------++Released on September 20, 2017.++ - Fixed a broken build of `checkmate` binary on the download page.+++Version 0.1.1+-------------++Released on September 20, 2017.++### Program++ - Checklist texts generated by `checkmate commonmark`, `checkmate gfm`, and+ `checkmate github` became to have two levels of headings. The top-level+ heading is still the title of the checklist as it has been, and the+ second-level heading is a corresponding file path of its following checks.++### Library++ - Added `Checkmate.Renderer` module.+++Version 0.1.0+-------------++Initial release. Released on September 20, 2017.
checkmate.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: checkmate-version: 0.1.4+version: 0.2.0 synopsis: Generate checklists relevant to a given patch category: Development stability: alpha@@ -18,6 +18,7 @@ cabal-version: >= 1.10 extra-source-files:+ CHANGELOG.md README.md source-repository head
src/Checkmate/Parser/CheckFile.hs view
@@ -41,6 +41,7 @@ bullet <- choice [ string "*" , string "+" , string "-"+ , string "CHECK:" , string "CHECK" , some digitChar >> (string "." <|> string ")") ]
src/Checkmate/Parser/IndentBlock.hs view
@@ -52,40 +52,70 @@ someSpaces :: Parser () someSpaces = skipMany $ oneOf " \t" checkKeyword :: Parser ()- checkKeyword = do- someSpaces- void $ string "CHECK"- someSpaces+ checkKeyword = void $ string "CHECK"+ checkThenSpaces :: Parser ()+ checkThenSpaces = do+ checkKeyword+ (char ':' >> someSpaces) <|> skipSome (oneOf " \t")+ lineCommentStart :: Parser ()+ lineCommentStart =+ choice [void $ oneOf "#%'", void $ string "//", void $ string "--"] lineCommentCheck :: Parser Text lineCommentCheck = do- choice [void $ oneOf "#%'", void $ string "//", void $ string "--"]- checkKeyword+ lineCommentStart+ someSpaces+ checkThenSpaces chars <- many $ noneOf "\n"- return $ pack chars+ nextLines <- many $ try $ do+ void eol+ someSpaces+ lineCommentStart+ someSpaces+ many $ noneOf "\n"+ return $ stripEnd $ pack $ Data.List.unlines $ chars : nextLines blockCommentPairs :: [(String, String)] blockCommentPairs = [ ("/*", "*/"), ("{-", "-}"), ("<!--", "-->"), ("<#", "#>") , ("%{", "%}") ]- blockCommentCheck :: Parser Text- blockCommentCheck = choice $ fmap blockComment blockCommentPairs- blockComment :: (String, String) -> Parser Text- blockComment (start, end) = do+ blockCommentCheck :: Int -> Parser Text+ blockCommentCheck depth =+ choice $ fmap (blockComment depth) blockCommentPairs+ blockComment :: Int -> (String, String) -> Parser Text+ blockComment depth (start, end) = do void $ string start- checkKeyword+ linebreaks <- many $ try $ do+ skipMany $ oneOf " \t\r"+ char '\n'+ innerDepth <- many indent+ checkThenSpaces chars <- manyTill anyChar (string end)- return $ pack chars+ let leftPadding = case linebreaks of+ [] -> depth+ _ -> sum innerDepth+ return $ stripEnd $ pack $ stripLeftPadding leftPadding chars line :: Parser (FilePath, Int, Int, Line) line = do SourcePos filePath lineNo _ <- getPosition widths <- many indent+ let depth = sum widths lineT <- choice [ try $ fmap CheckComment lineCommentCheck- , try $ fmap CheckComment blockCommentCheck+ , try $ CheckComment <$> blockCommentCheck depth , try (some (noneOf "\n") >> return Line) , return EmptyLine ]- return (filePath, read . show . unPos $ lineNo, sum widths, lineT)+ return (filePath, read . show . unPos $ lineNo, depth, lineT)+ stripLeftPadding :: Int -> String -> String+ stripLeftPadding width =+ Data.List.unlines . fmap (lstrip width) . Data.List.lines+ where+ lstrip :: Int -> String -> String+ lstrip _ [] = []+ lstrip 0 txt = txt+ lstrip w (' ' : xs) = lstrip (w - 1) xs+ lstrip w txt@('\t' : xs) = if w >= 8 then lstrip (w - 8) xs else txt+ lstrip _ txt = txt analyzeIndents :: Int -> [(FilePath, (Int, Int), Int, Text)] -> [(FilePath, Int, Int, Line)]
test/Checkmate/DiscoverSpec.hs view
@@ -65,7 +65,7 @@ pyChecklistFixture :: FilePath -> Checklist pyChecklistFixture d = [ Check { checkScope = FileBlock { scopePath = pyPath- , scopeRange = SpanRange 2 23+ , scopeRange = SpanRange 2 24 } , checkOrderIndex = 1 , checkText = "module-level check"@@ -90,22 +90,22 @@ jsChecklistFixture :: FilePath -> Checklist jsChecklistFixture d = [ Check { checkScope = FileBlock { scopePath = jsPath- , scopeRange = SpanRange 2 18+ , scopeRange = SpanRange 2 21 } , checkOrderIndex = 1 , checkText = "global check" } , Check { checkScope = FileBlock { scopePath = jsPath- , scopeRange = SpanRange 10 17+ , scopeRange = SpanRange 10 20 } , checkOrderIndex = 3 , checkText = "function-level check 2" } , Check { checkScope = FileBlock { scopePath = jsPath- , scopeRange = SpanRange 13 14+ , scopeRange = SpanRange 13 17 } , checkOrderIndex = 4- , checkText = "closure check"+ , checkText = "closure check.\nIt can be multiline." } ] where
test/Checkmate/Parser/CheckFileSpec.hs view
@@ -44,6 +44,7 @@ parsed `shouldParse` [] let bulletStyles = [ ("CHECK", "CHECK", "CHECK", "CHECK")+ , ("CHECK:", "CHECK:", "CHECK:", "CHECK:") , ("bullet \"*\"", "*", "*", "*") , ("bullet \"-\"", "-", "-", "-") , ("bullet \"+\"", "+", "+", "+")@@ -86,7 +87,7 @@ g `shouldParse` [Check dir 1 "foo"] it "parses well even if bullet styles are mixed" $ do (dir, parsed) <- parse'- "CHECK foo\nbar\n- baz\nqux\n* quz\n+ a\n1. b\n2) c\nCHECK d"+ "CHECK foo\nbar\n- baz\nqux\n* quz\n+ a\n1. b\n2) c\nCHECK: d" parsed `shouldParse` [ Check dir 1 "foo\nbar" , Check dir 2 "baz\nqux"
test/Checkmate/Parser/IndentBlockSpec.hs view
@@ -10,6 +10,7 @@ import Data.Range.Range import Data.Text import Data.Text.IO+import Text.InterpolatedString.Perl6 import Test.Hspec import Test.Hspec.Megaparsec import Text.Megaparsec@@ -35,6 +36,20 @@ hClose handle parsed <- parseSourceFile filePath return (filePath, parsed)+ it "parses a multiline comment" $ do+ let parsed = parse parser "a.js" [q|+function foo() {+ /*+ CHECK multiline+ test+ test2+ */+ return true;+|]+ parsed `shouldParse`+ [ Check (FileBlock "a.js" $ SpanRange 3 8) 1+ "multiline\ntest\ntest2"+ ] parserSpec :: String@@ -48,10 +63,11 @@ (path, parsed) <- parse' pythonFixture let s = FileBlock path parsed `shouldParse`- [ Check (s $ SpanRange 2 23) 1 "module-level check"+ [ Check (s $ SpanRange 2 24) 1 "module-level check" , Check (s $ SpanRange 6 7) 2 "function-level check" , Check (s $ SpanRange 11 15) 3 "function-level check 2" , Check (s $ SpanRange 14 15) 4 "nested function-level check"- , Check (s $ SpanRange 19 23) 5 "class-level check"- , Check (s $ SpanRange 22 23) 6 "method-level check"+ , Check (s $ SpanRange 19 24) 5 "class-level check"+ , Check (s $ SpanRange 22 24) 6+ "method-level check.\nIt can be multiline." ]