cbfmt
cbfmt copied to clipboard
Config Files of the individual formatters not detected?
Thanks for this small nifty tool.
I was wondering how exactly one can use config files for the specific formatters? For example with stylua.
I runcbfmt as cbfmt --config "$some_path". The specified cbfmt.toml is correctly recognized, since adding / removing lua does make a difference. However, I cannot figure out how to make cbfmt make stylua use a config file.
I have a stylua.toml in the same directory as the cbfmt.toml, and also in the nvim-pwd when executting the formatting command (via null-ls). However, cbfmt-run-stylua does not seem to recognize it since it seems to run on default config.
my config example
[languages]
lua = ["stylua --search-parent-directories -"]
I mean, I could explicitly run add a --config to the cbfmt.toml, but that would be really cumbersome.
I have a
stylua.tomlin the same directory as thecbfmt.toml
The stylua command will be executed from where you run cbfmt. You want to have the config file in that directory. Where cbfmt.toml is does not matter.
and also in the nvim-pwd when executting the formatting command
I assume that is the directory you run cbfmt from? In that case, it should just work. I tested it again now to be sure, and stylua recognizes the config correctly when it is in the same directory I run cbfmt from. (or in a parent directory with -s)
via null-ls
It should not make a difference, but to eliminate as many variables as possible, can you try to just run cbfmt directly?
yeah, so I tried running cbfmt with the command that null-ls does:
# pwd contains the stylua.toml file
cat ./lua/funcs/test.md | cbfmt --stdin-filepath ./lua/funcs/test.md --best-effort --config ../linter-configs/cbfmt.toml
and the output is correctly formatted, stylua used my config file.
When I then run cbfmt from via null-ls, the config file gets ignored. I checked that the pwd in nvim is the same as when I had when in the terminal.
My null-ls config for cbfmt, which should result in the same result as the bash command above:
null_ls.builtins.formatting.cbfmt.with {
extra_args = { "--config", "/Users/chrisgrieser/.config/linter-configs/cbfmt.toml" },
},
So maybe this is somehow null-ls related? But the thing, the cbfmt file is recognized – otherwise cbfmt would not run.
when I explicitly name a config file, it does work though:
# does not recognize stylua config
[languages]
lua = ["stylua --search-parent-directories -"]
# recognizes stylua config
[languages]
lua = ["stylua --config-path=/Users/chrisgrieser/.config/linter-configs/stylua.toml -"]
Yeah sounds like it's an issue with null-ls. Maybe null-ls runs it in the wrong directory?
I'd open an issue over there
okay. weird thing is, that every other formatter works fine in recognizing the respective config files 🤔
But I guess in that case I'll open an issue with null-ls
I'd have asked whether you could take a look at the respective file from null-ls defining the configs, but I noticed that you added it, so I assume there is no issue there 😅