mhartington/formatter.nvim

paths with spaces fail to format with prettier config

Closed this issue ยท 11 comments

Failed to run formatter prettier. zsh:1: no matches found: /home/rockerboo/Dropbox (Maestral)/x.md

in the config, I was able to fix by

      args = {
        "--stdin-filepath",
        util.escape_path(util.get_current_buffer_file_path()),
      },

to

      args = {
        "--stdin-filepath",
        string.format("\"%s\"", util.escape_path(util.get_current_buffer_file_path())),,
      },

to put the path into quotes on the args filepath.

@rockerBOO, when I applied the solution what you have shown above, it was running the formatter but there is some other error now.

  • file path is like this /home/lalit/Desktop/project/pages/[post]/animals/[id].js
  • ๐Ÿ› error I am getting
Failed to run formatter sed. zsh no matches found: /home/lalit/Desktop/project/pages/[post]/animals/~formatter_70595_[id].js

The fix suggested was for prettier. Not sure how it would affect other formatters.

I am talking about prettier only.

I knew this would be a problem at some point and I am not sure what the correct solution is since I'm no expert in shell escaping.
@mhartington can you check if the shell escaping functions in the util module are ok?

@rockerBOO can you check out if #183 works for you?

That works for me. Thanks @Hrle97

Closing this since I'll merge the PR once I test it on Windows.

@Hrle97, its still throwing some kind of error for me. As I mentioned in this comment, what kind of file name I have.

  • config for the prettierd
local prettier = function()
  return {
    exe = "prettierd",
    args = {
      -- string.format('"%s"', util.escape_path(util.get_current_buffer_file_path())),
      util.get_current_buffer_file_path(),
    },
    stdin = true,
  }
end

I was thinking that after the fix, I don't need to escape in my config. But, it is still throwing the same error on format on save and that is:

  • 1st error
    Failed to run formatter prettierd. zsh:1: no matches found: /home/lalitmee/projects/project-1/src/pages/hello/[id].js
    
  • 2nd error
    Failed to run formatter sed. zsh:1: no matches found: /home/lalitmee/projects/project-1/src/pages/hello/~formatter_275999_[id].js_
    

I am not sure if there is still something to fix here, or there is something wrong in my config for prettier. Can you please help me?

@lalitmee
Can you try this with #183 :

local prettier = function()
    return {
      exe = "prettierd",
      args = {
        util.escape_path(util.get_current_buffer_file_path()),
      },
      stdin = true,
    }
end

Note that the util.get_current_buffer_file_path() is wrapped with util.escape_path. util.escape_path should do the quote wrapping now.

Would you agree that util needs more documentation?

@lalitmee Can you try this with #183 :

local prettier = function()
    return {
      exe = "prettierd",
      args = {
        util.escape_path(util.get_current_buffer_file_path()),
      },
      stdin = true,
    }
end

Note that the util.get_current_buffer_file_path() is wrapped with util.escape_path. util.escape_path should do the quote wrapping now.

Would you agree that util needs more documentation?

That works for me with #183.

And yeah, I agree that util needs more documentation. I was using that from the first comment. Thanks btw.

no problem ๐Ÿ˜„

i'll add a new issue for util documentation and close this in favor of #183