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

nufmt produces corrupted code #66

Open
GrabbenD opened this issue Dec 9, 2024 · 1 comment
Open

nufmt produces corrupted code #66

GrabbenD opened this issue Dec 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@GrabbenD
Copy link

GrabbenD commented Dec 9, 2024

Describe the bug

  • Each invocation of nufmt corrupts the code.
  • nufmt inserts a line break at the start of the file if no shebang is present.

Steps To Reproduce

  1. $ touch test.nu ; chmod +x test.nu
    def greet [name] {
      ["hello" $name]
    }
    
    greet "world"
  2. $ cargo install --git https://github.com/nushell/nufmt
  3. $ ~/.cargo/bin/nufmt test.nu

Result

(Note: I had to insert space for line breaks to be shown with Gitbub Markdown)

 
def greet [name]
{["hello" $name ]}greet "world"
 
> nu test.nu

Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[/home/user/me/test.nu:2:17]
 1 │ 
 2 │ def greet [name]
   ·                 ▲
   ·                 ╰── missing block
 3 │ {["hello" $name ]}greet "world"
   ╰────
  help: Usage: def {flags} <def_name> <params> <block> . Use `--help` for more information.

Executing nufmt again results in:

 
def greet [name]
{["hello" $name
]greet
greet
"world"
"world"
 

Expected behavior

Formatted code with a consistent structure, even across subsequent runs

Environment

Arch Linux

> rustc --version
rustc 1.82.0 (f6e511eec 2024-10-15)

> nu --version
0.100.0
@GrabbenD GrabbenD added the bug Something isn't working label Dec 9, 2024
@fdncred
Copy link
Collaborator

fdncred commented Dec 9, 2024

Agreed. This is why the readme says, This project is still very much in beta. Expect bugs, inconsistent behavior. Do not use in productive nushell scripts! I wouldn't even call it alpha or beta. It's very premature. We're looking for people to come along side us and work on it.

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

No branches or pull requests

2 participants