apheleia icon indicating copy to clipboard operation
apheleia copied to clipboard

Formatter test fails despite the output seems to be the same

Open artemkovalyov opened this issue 3 years ago • 8 comments

Hi, I'm trying to contribute a formatter for Rustywind (tailwindcss). It works in my Emacs and seems to be also working in the test setup that you have but the comparison doesn't path even though the diff shows identical lines.

The only way to make it pass was by trying with an empty file. Other options like having IN and OUT to be the same, etc. - failed. What should I take care of or check for in that diff? I guess it could be something non-printed? Can it be related to the No newline... message from git diff.

I'm stuck and would be really thankful for the hint.

apheleia@206efdc28ed6:/src$ make fmt-test FORMATTERS=rustywind
diff --git a/tmp/apheleia-ft-file-0sc9WE.expected b/tmp/apheleia-ft-file-0WlzpU.actual
index 092f883..3534fe8 100644
--- a/tmp/apheleia-ft-file-0sc9WE.expected
+++ b/tmp/apheleia-ft-file-0WlzpU.actual
@@ -1 +1 @@
-<div class="flex flex-col mx-auto text-white md:flex-row xl:py-10 2xl:py-20 dark:text-purple-500">Fancy test div</div>
+<div class="flex flex-col mx-auto text-white md:flex-row xl:py-10 2xl:py-20 dark:text-purple-500">Fancy test div</div>
\ No newline at end of file
Formatter rustywind did not format as expected
make: *** [Makefile:76: fmt-test] Error 255

artemkovalyov avatar Jul 23 '22 21:07 artemkovalyov

Is the formatter stripping the trailing newline from your file? If so, can that be disabled?

raxod502 avatar Jul 24 '22 00:07 raxod502

@raxod502, I ran several tests and the formatter indeed removes the newline at the end of a file when it's used with --stdin option. I haven't found a way to disable this behavior. When used from the command line it keeps the new line because it probably rewrites the whole file.

I think because it's just sorting CSS classes in a string it usually treats newline in a special way when --stdin option is used. Do you have an idea how to deal with this and if there's a way to make the tests happy?

artemkovalyov avatar Jul 24 '22 11:07 artemkovalyov

I'd submit a bug report upstream - all files on Linux end with a trailing newline and if a tool is producing something else, I'd consider that a bug. If upstream is not willing to fix their implementation, we can add a workaround here, but it seems best to check with them first.

raxod502 avatar Jul 25 '22 00:07 raxod502

@raxod502, I'll do as you say. Let's see about their reply.

artemkovalyov avatar Jul 25 '22 06:07 artemkovalyov

Let's hope for a fast fix:

  • https://github.com/avencera/rustywind/issues/62
  • https://github.com/avencera/rustywind/pull/63

artemkovalyov avatar Jul 25 '22 10:07 artemkovalyov

Heh, seems like upstream might not be the most responsive. If we can't get it fixed there, then I don't think it would be the worst thing to include a wrapper script to append a newline, much like https://github.com/radian-software/apheleia/blob/04366a90dfc1063c4a22ea2e4ccaa48303a457e0/scripts/formatters/apheleia-phpcs works around an exit code issue.

raxod502 avatar Sep 03 '22 17:09 raxod502

Hey @artemkovalyov should be fixed in new release: https://github.com/avencera/rustywind/releases/tag/v0.15.1

praveenperera avatar Sep 06 '22 16:09 praveenperera

Amazing, thank you!

raxod502 avatar Sep 11 '22 00:09 raxod502

This thread is being closed automatically by Tidier because it is labeled with "waiting on response" and has not seen any activity for 90 days. But don't worry—if you have any information that might advance the discussion, leave a comment and I will be happy to reopen the thread :)

raxod502 avatar Dec 11 '22 00:12 raxod502