mitranim / sublime-fmt

Sublime Text generic formatter plugin; formats arbitrary code by calling arbitrary executables, such as `gofmt`
The Unlicense
22 stars 1 forks source link

allow matching by file path #11

Open adrian-gierakowski opened 8 months ago

adrian-gierakowski commented 8 months ago

I am working in a monorepo in which different sub-projects use different formatters for the same file types

I would like to enable formatting on save but don't see how I could make formatting conditional on the files path using sublime selectors

could a new setting be added to enable this? Thanks!

mitranim commented 8 months ago

Hmm. My first question would be: what about anonymous buffers? They don't have paths (view.file_path() is None). They only have scope selectors.

adrian-gierakowski commented 8 months ago

Anonymous buffer could match only if given formatter didn’t have a path based condition, or if the condition matched an empty string

mitranim commented 8 months ago

Might be useful to get more details about your use case, such as directory structure, files involved, formatters used. We might come up with other solutions too.

adrian-gierakowski commented 7 months ago

I'm using dprint and prettier for js\ts files and other formatters for other languages. One of the sub-dirs in the monorepo needs to be formatted with prettier.

I started using https://numtide.github.io/treefmt to dispatch do different formatters, however it needs a file path to be able to select the formatter to use.

So I would need sublime-fmt to provide full path of formatted file when running on save. If formatting a buffer without a path, a dummy file name (with extension) could be provided to let treefmt pick the formatter to use.