winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.77k stars 189 forks source link

Minimal implementation of `wing fmt` for whitespace cleanup #6510

Open MarkMcCulloh opened 1 month ago

MarkMcCulloh commented 1 month ago

Use Case

An opinioned formatting tool helps keep code beautiful and frees PRs from formatting nitpicks. We have https://github.com/winglang/wing/issues/475 but it focuses on enforcing certain stylistic things present in the spec. It would be useful to focus on a minimal but useful whitespace formatter.

Proposed Solution

wing fmt defaults to all wing files in the current directory, can otherwise provide a path to do the following:

Additionally, we should expose this formatter in the vscode extension (see here)

Implementation Notes

Ideally this is something that can be implemented solely with the tree-sitter tree to keep it simple.

Component

No response

Community Notes

eladb commented 1 month ago

Would it make sense that by default wing compile will also format?

MarkMcCulloh commented 1 month ago

It would be a pretty bold choice, not sure I've seen any compilers/tools mutate user-created sources automatically during compilation. We could start with a --fix flag, which could also do other things like inserting semicolons.

eladb commented 1 month ago

Sounds good for the CLI, but can we make this the default behavior in VSCode? Format on save?