mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Merge pull request #518 from github/end-with-newline
Check if the patch ends with a newline
This commit is contained in:
commit
1a55c8c750
@ -22,7 +22,10 @@ import Data.Monoid
|
||||
|
||||
-- | Render a diff in the traditional patch format.
|
||||
patch :: Renderer a String
|
||||
patch diff sources = mconcat $ showHunk sources <$> hunks diff sources
|
||||
patch diff sources = case getLast $ foldMap (Last . Just) string of
|
||||
Just c | c /= '\n' -> string ++ "\n\\ No newline at end of file\n"
|
||||
_ -> string
|
||||
where string = mconcat $ showHunk sources <$> hunks diff sources
|
||||
|
||||
-- | A hunk in a patch, including the offset, changes, and context.
|
||||
data Hunk a = Hunk { offset :: Both (Sum Int), changes :: [Change a], trailingContext :: [Row a] }
|
||||
@ -46,11 +49,10 @@ rowIncrement = fmap lineIncrement
|
||||
|
||||
-- | Given the before and after sources, render a hunk to a string.
|
||||
showHunk :: Both SourceBlob -> Hunk (SplitDiff a Info) -> String
|
||||
showHunk blobs hunk = if last sourceHunk /= '\n'
|
||||
then sourceHunk ++ "\n\\\\ No newline at end of file\n"
|
||||
else sourceHunk
|
||||
showHunk blobs hunk = header blobs hunk ++
|
||||
concat (showChange sources <$> changes hunk) ++
|
||||
showLines (snd sources) ' ' (snd <$> trailingContext hunk)
|
||||
where sources = source <$> blobs
|
||||
sourceHunk = header blobs hunk ++ concat (showChange sources <$> changes hunk) ++ showLines (snd sources) ' ' (snd <$> trailingContext hunk)
|
||||
|
||||
-- | Given the before and after sources, render a change to a string.
|
||||
showChange :: Both (Source Char) -> Change (SplitDiff a Info) -> String
|
||||
|
@ -6,4 +6,4 @@ index .. 100644
|
||||
console.log("hello, world");
|
||||
|
||||
+console.log("insertion");
|
||||
\\ No newline at end of file
|
||||
\ No newline at end of file
|
||||
|
Loading…
Reference in New Issue
Block a user