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

feat: More fmt improvements #224

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

wxsBSD
Copy link
Contributor

@wxsBSD wxsBSD commented Oct 12, 2024

This adds support for optional newline before curly brace in the rule declaration.

// This is the default
rule a {

vs

rule a
{

It also adds support for empty lines before and after section headers. Each one is a separate option - you can have them before section headers but not after, vice versa, both, or none.

rule a {

  meta:

    foo = "bar"

vs

// This is the default (no empty lines)
rule a {
  meta:
    foo = "bar"

This also fixes an issue where we were not inserting newlines before meta definitions, so if you had two meta definitions on the same line the formatter left them like that. They are now fixed so that each meta definition goes on a separate line.

This commit adds support for newlines before curly braces in rule declaration.
If "true" it will ensure at most 2 newlines exist before the opening curly
brace. If zero newlines exist it will insert only one, but if 2 or more exist it
will reduce it to exactly 2.

The default for this is "false".
Add support for empty lines before/after section headers to the formatter.

This allows you to have rules like:

```
rule a {

  meta:

    foo = "bar"

  condition:

    true
}
```

Or various combinations of empty lines before/after. It is currently a boolean
option so if you only want it for a specific section we don't support that.
This fixes the case where you have:

```
meta:
  foo = "bar" baz = "pants"
```

Now each meta definition will go on a separate line. I originally thought this
was broken by my work in this branch but it was just never implemented in main.
@wxsBSD
Copy link
Contributor Author

wxsBSD commented Oct 12, 2024

This is more work for #192 - if this is merged I'll follow-up with tests that handle all the options added so far. The formatter is starting to get more complicated with these options and I want to make sure we have good test coverage to help ensure proper functionality as I continue to work on the other requested features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants