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

📝 Formatter replaces emojis #2604

Closed
1 task done
melMass opened this issue Apr 25, 2024 · 9 comments
Closed
1 task done

📝 Formatter replaces emojis #2604

melMass opened this issue Apr 25, 2024 · 9 comments
Labels
A-Formatter Area: formatter A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@melMass
Copy link

melMass commented Apr 25, 2024

Environment information

CLI:
  Version:                      1.7.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v20.9.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 true

Formatter:
  Format with errors:           false
  Indent style:                 Tab
  Indent size:                  0
  Indent width:                 0
  Line ending:                  Lf
  Line width:                   80
  Attribute position:           Auto
  Ignore:                       []
  Include:                      []

JavaScript Formatter:
  Enabled:                      false
  JSX quote style:              Double
  Quote properties:             AsNeeded
  Trailing comma:               All
  Semicolons:                   AsNeeded
  Arrow parentheses:            Always
  Bracket spacing:              false
  Bracket same line:            false
  Quote style:                  Single
  Indent style:                 unset
  Indent size:                  unset
  Indent width:                 2
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           Auto

JSON Formatter:
  Enabled:                      true
  Indent style:                 unset
  Indent width:                 unset
  Indent size:                  unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

Workspace:
  Open Documents:               0

Configuration

{
    "$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
    "organizeImports": {
        "enabled": true
    },
    "linter": {
        "enabled": true,
        "rules": {
            "recommended": true
        }
    },
    "formatter": {
        "lineEnding": "lf"
    },
    "javascript": {
        "formatter": {
            "quoteStyle": "single",
            "semicolons": "asNeeded",
            "indentWidth": 2
        }
    }
}

Playground link

https://biomejs.dev/playground/?code=CgBlAHgAcABvAHIAdAAgAGMAbwBuAHMAdAAgAGkAbgBmAG8ATABvAGcAZwBlAHIAIAA9ACAAYwByAGUAYQB0AGUATABvAGcAZwBlAHIAKAAnADkhD%2F4nACwAIAAnAHkAZQBsAGwAbwB3ACcAKQAKAGUAeABwAG8AcgB0ACAAYwBvAG4AcwB0ACAAdwBhAHIAbgBMAG8AZwBnAGUAcgAgAD0AIABjAHIAZQBhAHQAZQBMAG8AZwBnAGUAcgAoACcAoCYP%2FicALAAgACcAbwByAGEAbgBnAGUAJwAsACAAJwB3AGEAcgBuACcAKQAKAGUAeABwAG8AcgB0ACAAYwBvAG4AcwB0ACAAZQByAHIAbwByAEwAbwBnAGcAZQByACAAPQAgAGMAcgBlAGEAdABlAEwAbwBnAGcAZQByACgAJwA92CXdJwAsACAAJwByAGUAZAAnACwAIAAnAGUAcgByAG8AcgAnACkACgBlAHgAcABvAHIAdAAgAGMAbwBuAHMAdAAgAHMAdQBjAGMAZQBzAHMATABvAGcAZwBlAHIAIAA9ACAAYwByAGUAYQB0AGUATABvAGcAZwBlAHIAKAAnAAUnJwAsACAAJwBnAHIAZQBlAG4AJwApAAoACgA%3D

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@melMass
Copy link
Author

melMass commented Apr 25, 2024

I can't reproduce the issue on the playground, but this is what happens in neovim:

biome_emojis

I think it was fixed in #693 but I can't find why it happens

@huijiewei
Copy link

webstorm has same problem

@ematipico ematipico added A-Parser Area: parser A-Formatter Area: formatter S-Bug-confirmed Status: report has been confirmed as a valid bug labels Apr 26, 2024
@redbmk
Copy link

redbmk commented Apr 29, 2024

@melMass are you using ALE to format or something else? I'm using ALE and see this as well, but it doesn't happen when formatting from the CLI

@redbmk
Copy link

redbmk commented Apr 29, 2024

looks like it might have something to do with the way neovim is exporting to stdout:

before:

console.log("⚠️ ")

highlight the line with V, then:

:'<,'>!bunx biome format --stdin-file-path=asdf.ts

after:

console.log("! ");

but if I copy and paste that directly into the console it seems fine:

echo 'console.log("⚠<fe0f> ")' | bunx biome check --apply --stdin-file-path=asdf.ts
console.log("⚠️ ");

I'm not entirely sure where the <fe0f> is coming from, but when I paste into zsh/iterm2 that shows up.

@redbmk
Copy link

redbmk commented Apr 29, 2024

ok it might still have something to do with biome not quite understanding what encoding stdin is in or something...

:'<,'>!cat

leaves it untouched, and:

:'<,'>!cat > temp.ts && bunx biome check --apply temp.ts && cat temp.ts

gives me:

Checked 1 file in 2ms. Fixed 1 file.
console.log("⚠️ ");

@redbmk
Copy link

redbmk commented Apr 29, 2024

Hmm I'm also finding this pretty confusing. Without --apply it seems to print an error but the exit code is still 0. With --apply the output looks identical.

image

When putting them through diff or piping through stdin they do look different though, so I guess it's not actually a neovim issue

image

@redbmk
Copy link

redbmk commented Apr 30, 2024

OK I think I figured it out. I believe biome is trying to strip ansi characters when it detects that the output is not interactive (e.g. to a pipe or a file). In this case its instead converting the emoji into a plain string. As a workaround, if you use --colors=force then it will keep the emoji.

image

A slightly different bug seems to be in the check mode where it prints the output first, then a message saying it would have printed the following content. So it's backwards and it's also reporting an error when there actually shouldn't be one.

image

redbmk added a commit to redbmk/ale that referenced this issue May 13, 2024
biome handles utf8 characters differently between files and stdin, and
in some cases can replace emojis with ascii characters when using stdin

refs: biomejs/biome#2604
@ematipico
Copy link
Member

ematipico commented May 22, 2024

I know we have the issue, but I am unable to replicate it, maybe because I have a shell that supports Ansi? I wished there was a consistent way - at least for me - to get an invalid output.

BTW, if anyone wants to help, we use the termcolor crate to setup the stdout stream. Maybe someone can suggest a better option, among of these variants: https://docs.rs/termcolor/1.4.1/termcolor/enum.ColorChoice.html#variants

@melMass
Copy link
Author

melMass commented May 23, 2024

Sorry I can't track exactly when/how but it's now working properly!
Just to note that it wasn't happening for all emojis but only some.
I'm going to close the issue
Edit: I just saw all redmk messages, I guess it still needs a proper conclusion, feel free to close it

redbmk added a commit to redbmk/ale that referenced this issue Jun 20, 2024
biome handles utf8 characters differently between files and stdin, and
in some cases can replace emojis with ascii characters when using stdin

refs: biomejs/biome#2604
hsanson pushed a commit to dense-analysis/ale that referenced this issue Jun 20, 2024
biome handles utf8 characters differently between files and stdin, and
in some cases can replace emojis with ascii characters when using stdin

refs: biomejs/biome#2604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter A-Parser Area: parser S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests

4 participants