rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

Unicode characters (arrows) that indicate priority of found issues not printed correctly #1137

Open miguno opened 3 months ago

miguno commented 3 months ago

Precheck

Environment

Terminal environment:

$ echo $LANG
en_US.utf-8

$ echo $LC_ALL
en_US.utf-8

My terminal (wezterm) with the font I use (Iosevka) does support the respective arrow Unicode characters:

❯ iex
Erlang/OTP 27 [erts-15.0] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Interactive Elixir (1.16.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>  to_string("\u{2192}")
"→"
iex(2)> to_string("\u{2197}")
"↗"

Lastly, even with a "fresh" wezterm setup of all defaults (via wezterm -n) shows the same behavior: credo output has raw Unicode sequences, whereas other uses of the same Unicode characters (e.g. via iex or manually typed) do render correctly.

What were you trying to do?

I want to run a basic credo report with mix credo --strict and see correctly formatted output.

To make it easier to summarize the issue in this discussion, I also include the expected vs. actual output for the following credo command line:

$ mix credo list --format=oneline --strict

FWIW it didn't matter whether or not I added --no-color to the commands.

Expected outcome

I expected that the priority indicator arrows (like → or ↗) would be printed to the terminal, note the left-hand side of the output, right next to where the categories like [R] and [D] are printed.

$ mix credo list --format=oneline --strict
[R] → lib/hello_elixir.ex:1:11 Modules should have a @moduledoc tag.
[D] → lib/hello_elixir.ex:12 Found a TODO tag in a comment: # TODO: Remove
[W] ↗ lib/hello_elixir.ex:20:10 There are identical sub-expressions to the left and to the right of the '&&' operator.

Actual outcome

Instead, the raw Unicode sequence were printed.

$ mix credo list --format=oneline --strict
[R] \x{2192} lib/hello_elixir.ex:1:11 Modules should have a @moduledoc tag.
[D] \x{2192} lib/hello_elixir.ex:12 Found a TODO tag in a comment: # TODO: Remove
[W] \x{2197} lib/hello_elixir.ex:20:10 There are identical sub-expressions to the left and to the right of the '&&' operator.

Here is more verbose output:

$ mix credo --strict
mix credo --strict
Checking 3 source files ...

  Software Design
\x{2503}
\x{2503} [D] \x{2192} Found a TODO tag in a comment: # TODO: Remove
\x{2503}       lib/hello_elixir.ex:12 #(HelloElixir.hello)

  Code Readability
\x{2503}
\x{2503} [R] \x{2192} Modules should have a @moduledoc tag.
\x{2503}       lib/hello_elixir.ex:1:11 #(HelloElixir)

  Warnings - please take a look
\x{2503}
\x{2503} [W] \x{2197} There are identical sub-expressions to the left and to the right of the '&&' operator.
\x{2503}       lib/hello_elixir.ex:20:10 #(HelloElixir.baz)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.06 seconds (0.04s to load, 0.02s running 67 checks on 3 files)
4 mods/funs, found 1 warning, 1 code readability issue, 1 software design suggestion.

Use `mix credo explain` to explain issues, `mix credo --help` for options.

As you can see, the priority-indicating arrows as well as further Unicode sequences are actually printed as \x{2192} etc.

Have you come across this before? I have not found any clearly related issue in the open or the closed GH issues.

miguno commented 3 months ago

I did find a semi-related issue for wezterm, but as far as I can tell the issue I describe above is different.

rrrene commented 2 months ago

Wow. Thanks for the super detailed issue! 🎉 :+1:

I am currently at a loss regarding the origin of this. If Credo can change anything to mitigate this issue, we will 😀