JohnnyMorganz / StyLua

An opinionated Lua code formatter
Mozilla Public License 2.0
1.5k stars 65 forks source link

feat: Use closest `stylua.toml` config to file being formatted #831

Open gabyx opened 7 months ago

gabyx commented 7 months ago

It would be nice if the formatter can be configured to stop looking for config files when reached a Git root (e.g. git rev-parse --show-toplevel) this will be useful such that when inside a lua repo and inside submodule, we stop at first .stylelua file, somehow it does not stop and merges? with the config file in the main repo, which contains the submodule...

JohnnyMorganz commented 7 months ago

we stop at first .stylelua file, somehow it does not stop and merges

this sounds incorrect to me, we don't merge two stylua files together. That sounds like the underlying issue here, rather than adding something else to stop at git roots.

gabyx commented 7 months ago

Ah maybe you start the discovery of the style file from the current working directory, which IMO is wrong. Could that be the issue here?

JohnnyMorganz commented 7 months ago

Ah yes, that seems more like it. Indeed, we just use the config found at the cwd across all the code.

I have been thinking about this though - maybe we should be using the closest configuration to the file.

I do question why you are running stylua on a sub module though. I typically think sub modules are vendored code, hence should be ignored by style tools, but maybe that is not the case for you.

gabyx commented 7 months ago

Von meinem iPhone gesendetAm 23.12.2023 um 18:32 schrieb JohnnyMorganz @.***>: Ah yes, that seems more like it. Indeed, we just use the config found at the cwd across all the code. I have been thinking about this though - maybe we should be using the closest configuration to the file. I do question why you are running stylua on a sub module though. I typically think sub modules are vendored code, hence should be ignored by style tools, but maybe that is not the case for you.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

gabyx commented 7 months ago

Ehm, hehe 😉 yes thats true, bitbthe astronvim distribution works differently :). But tou are right I meant I always executed the format with the cwd in the submodule and since it has a config file that one should be found, strange, I check again in a few days.

Anyway, all format tools actually do this as far as I know from clang-format - start from the file. Please check again, now a bit unsure.

JohnnyMorganz commented 7 months ago

Yes, I think it is valid still. I will restructure your feature request to "Use closest configuration to file"

gabyx commented 4 months ago

@JohnnyMorganz : Would improve tooling much, since it will pick up the closest .stylelua.toml file and make an astronvim user install much nicer! Looking forward to this. BR