Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal implementation of wing fmt for whitespace cleanup #6510

Open
4 tasks
MarkMcCulloh opened this issue May 17, 2024 · 3 comments
Open
4 tasks

Minimal implementation of wing fmt for whitespace cleanup #6510

MarkMcCulloh opened this issue May 17, 2024 · 3 comments
Labels
⌨️ cli CLI ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl

Comments

@MarkMcCulloh
Copy link
Contributor

MarkMcCulloh commented May 17, 2024

Use Case

An opinioned formatting tool helps keep code beautiful and frees PRs from formatting nitpicks.
We have #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:

  • Remove trailing whitespace per line
  • Remove extra whitespace between between most tokens on the same line
    • let x = 2; becomes let x = 2;
  • Add single whitespace between most tokens
    • let x=2; becomes let x = 2;
    • func(a,b) should become func(a, b)
  • Indenting for { at end of line and unindenting for }
    • Tabs?

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

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Discord.
@MarkMcCulloh MarkMcCulloh added ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl labels May 17, 2024
@eladb
Copy link
Contributor

eladb commented May 17, 2024

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

@MarkMcCulloh
Copy link
Contributor Author

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
Copy link
Contributor

eladb commented May 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌨️ cli CLI ✨ enhancement New feature or request needs-discussion Further discussion is needed prior to impl
Projects
Status: 🤝 Backlog - handoff to owners
Development

No branches or pull requests

3 participants