stevearc / conform.nvim

Lightweight yet powerful formatter plugin for Neovim
MIT License
2.72k stars 142 forks source link

feature request: Option to use relative filepaths #349

Closed jeraki closed 3 months ago

jeraki commented 4 months ago

Did you check existing requests?

Describe the feature

Is there a config option to have Conform send a file path relative to the working directory to the formatter? Or alternatively, is there an equivalent of the special $FILEPATH argument that will use a relative path?

I see in conform.runner.build_context, it's using vim.api.nvim_buf_get_name, which returns the absolute path, so I'm guessing it's not possible to do this currently, in which case consider this a feature request!

Provide background

When I use Conform to format Ruby code with RuboCop, it fails and this error is returned by RuboCop:

"-s/--stdin requires exactly one path, relative to the root of the project. RuboCop will use this path to determine which cops are enabled (via eg. Include/Exclude), and so that certain cops like Naming/FileName can be checked."

What is the significance of this feature?

strongly desired

Additional details

No response

sandrodz commented 3 months ago

I've similar issue with phpcbf. I need to run it from project root. My phpcs/phpcbf are dockerised tools, so Absolute path doesn't exist inside the container.

image

I thought CWD would help with this, but it doesn't

  formatters = {
    phpcbf = {
      cwd = require("conform.util").root_file({ ".editorconfig", "composer.json" }),
    },
  }
stevearc commented 3 months ago

You can now use the variable $RELATIVE_FILEPATH in formatter args and it will be a relative path to the file from the cwd.