Skip to content

Autoformatting

Tadeas Kucera edited this page Mar 24, 2020 · 10 revisions

Autoformatting improvements

Our autoformatter has been deployed, but it still needs some adjustments to suit rule writer's needs. Here we would like to collect ideas on how to make it as convenient as possible.

Staging area

Implemented

Removing redundant blank lines (#77)

We keep blank lines in rules during autoformatting because we want to give rule writers some freedom in logically grouping things together. Therefore we don't strictly remove blank lines. However sometimes it is desirable like if you have rule

rule {

    meta:

        key = "value"

    condition:

        true
}

In this case it would make sense to remove them. We need to find the fine line between what is desired and what is not. It could be based on frequency and placement of those blank lines. We don't need to hunt down every single edge case but at least make it usable for the regular cases.

Indenting comments inside rule sections (#81)

Comments inside rule sections are left as they are and their indentation is not modified even though we've modified the indentation of strings. Example:

rule abc
{
    strings:
                // Comments
                $s01 = "Hello"
    condition:
        $s01
}

would be formatted as

rule abc
{
    strings:
                // Comments
        $s01 = "Hello"
    condition:
        $s01
}

but it is desired to reindent the comment too.

New line after conjunctions and and or (#61)

We would like a new line after each and and or conjunction. Both

(
    mutex(/abc/) or mutex(/def/)
)

and

(mutex(/abc/) or mutex(/def/))

shall become this:

(
    mutex(/abc/) or
    mutex(/def/)
)

However, both

(
    mutex(/abc/) or /*comment*/
    mutex(/def/)
)

and

(
    mutex(/abc/) or //comment
    mutex(/def/)
)

should stay the same. Also

mutex(/abc/) or (mutex(/def/))

should become

mutex(/abc/) or
(mutex(/def/))