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

--mode check does not detect no trailing newline #743

Closed
uta8a opened this issue Aug 7, 2021 · 0 comments · Fixed by #744
Closed

--mode check does not detect no trailing newline #743

uta8a opened this issue Aug 7, 2021 · 0 comments · Fixed by #744
Labels
bug Something isn't working

Comments

@uta8a
Copy link

uta8a commented Aug 7, 2021

Describe the bug
Related #741 , --mode check does not detect no trailing newline and returns Exit code 0.

To Reproduce
example.hs (no trailing newline file)

main = putStrLn "Hello, world!"

command

$ ./ormolu-Linux -v
ormolu 0.1.4.1 HEAD 7714b5220e3c559a764fc9c68fdfb4f6dc439ec7
using ghc-lib-parser 8.10.2.20200916
$ ./ormolu-Linux --mode check example.hs 
$ echo $?
0

Expected behavior

$ ./ormolu-Linux --mode check example.hs
# Message that there's no trailing newline
$ echo $?
100

Environment

  • OS name + version: Ubuntu 20.04
  • Version of the code: ormolu 0.1.4.1 HEAD 7714b52

Additional context
As amesgen mentioned in #741 , formatting to add trailing newline works fine. Maybe diff detection part does not detect no trailing newline.

Diff detection in --mode check uses diffText function.

ormolu/app/Main.hs

Lines 89 to 91 in 34bdf62

Check ->
case diffText originalInput formattedInput inputFile of
Nothing -> return ExitSuccess

This diffText function uses T.lines

diffText a b path =
if all isBoth xs
then Nothing
else Just (TextDiff path xs)
where
xs = D.getGroupedDiff (T.lines a) (T.lines b)
isBoth = \case
D.Both _ _ -> True
D.First _ -> False
D.Second _ -> False

T.lines works like below, so difference between "no trailing newline Text" with "formatted Text with trailing newline" is ignored?

$ ghci
GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> import qualified Data.Text as T
Prelude T> T.pack "test"
"test"
Prelude T> T.pack "test\n"
"test\n"
Prelude T> T.lines (T.pack "test")
["test"]
Prelude T> T.lines (T.pack "test\n")
["test"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants