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

rubocop formatter erases buffer #251

Open
BrianHicks opened this issue Aug 19, 2019 · 5 comments
Open

rubocop formatter erases buffer #251

BrianHicks opened this issue Aug 19, 2019 · 5 comments

Comments

@BrianHicks
Copy link

Using 528b5e4, neovim v0.3.8

When I run :Neoformat using the rubocop formatter, my buffer gets erased. Here's what the output looks like with g:neoformat_verbose = 1:

Neoformat: executable: rufo is not an executable
Neoformat: executable: ruby-beautify is not an executable
Neoformat: ['class Simple', '  def hello', '    "World"', '  end', 'end']
Neoformat: rubocop --auto-correct --stdin "/Users/brianhicks/code/NoRedInk/NoRedInk/simple.rb" 2>/dev/null | sed "1,/^====================$/d"
Neoformat: using stdin
Neoformat: []
Neoformat: [0]
Neoformat: 0

When I run that command in the same shell as vim, it prints to stdout correctly. (rubocop --auto-correct --stdin "simple.rb" 2>/dev/null < simple.rb | sed "1,/^====================$/d")

What else can I give you to help with this? I'd offer to open a PR but I don't have any idea where to look!

@tjaartvdwalt
Copy link

tjaartvdwalt commented Jul 3, 2020

Are you using a ruby manager, like rvm or chruby?

I use chruby, and got a similar problem when my ruby was not correctly set.

Below are the ex commands I run to illustrate what I mean:

:!which ruby
/usr/bin/ruby

:Neoformat
# buffer is deleted

:undo
:Chruby auto

:!which ruby
/home/tjaart/.rubies/ruby-2.6.5/bin/ruby 

:Neoformat
# buffer formatted successfully

@nietaki
Copy link

nietaki commented Jul 6, 2020

In my case the same version of ruby I normally would be (the asdf one):

:!which ruby                                                                                                                                                                                                                                                                                                                        
/home/nietaki/.asdf/shims/ruby

What seems to be causing the problem is invalid Ruby syntax - the formatter instead of giving up and coughing up an error message deletes the buffer contents. Here's the :messages output I got with :let g:neoformat_verbose = 1:

Neoformat: <...source code cut...>
Neoformat: rufo 2> /tmp/neoformat/stderr.log
Neoformat: using stdin
Neoformat: []
Neoformat: [0, 3]
Neoformat: 1
Neoformat: stderr output redirected to file/tmp/neoformat/stderr.log
Neoformat: ['STDIN is invalid code. Error on line:24 syntax error, unexpected tIDENTIFIER, expecting tCONSTANT']
Neoformat: 1
Neoformat: trying next formatter
Neoformat: executable: ruby-beautify is not an executable
Neoformat: <...source code cut...>
Neoformat: rubocop --auto-correct --stdin "<...path cut...>" 2>/dev/null | sed "1,/^====================$/d"
Neoformat: using stdin
Neoformat: []
Neoformat: [0]
Neoformat: 0
Neoformat: rubocop formatted buffer

Fixing the error fixed the formatter

@BrianHicks
Copy link
Author

BrianHicks commented Jul 6, 2020

Are you using a ruby manager, like rvm or chruby?

I was using a Ruby installed via Nix. which ruby returned the right thing outside Vim. I'm not sure about inside.

I can't provide any more help with this, as I've switched to Kakoune some months ago and removed my vim configuration. If someone wanted to go to the effort to reproduce I can give you my dotfiles at the relevant version but they're fairly idiosyncratic—definitely better to reproduce using another person's setup if possible.

@foreverLoveWisdom
Copy link

I somehow get the same problem today. It deletes all of my code. Has anyone found a solution for this?

@iduuck
Copy link

iduuck commented Oct 5, 2021

Sorry for digging this issue out, but I just searched for the solution, and since this is an open issue which has not been closed since, I wanted to share the solution for the people suffering of this problem:

For me, the problem was, that I just set up a new Mac and hence didn't had rubocop installed globally. So, this was the first issue. I think that this is a fundamental issue with Neoformat? The second problem was a mis-configuration in the .rubocop.yml (which appearantly was a wrong target version.

So this said, I don't know, if this is an issue, which needs to be addressed by rubocop, or by the neoformat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants