odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.38k stars 561 forks source link

Odin Code Formatter #820

Closed gingerBill closed 1 year ago

gingerBill commented 3 years ago

Automatic code formatter for the Odin programming language.

Requirements:

Default style overview:

Usage:

gingerBill commented 3 years ago

Ideas for the -simplify flag:

Compound literals of the form:
        []T{T{}, T{}}
can be simplified to:
        []T{{}, {}}

Ranged for loops for the form:
        for x, _ in v {...}
can be simplified to:
        for x in v {...}

Ranged for loops for the form:
        for _ in v {...}
can be simplified to:
        for in v {...}

Slice expressions of the form:
        s[a:len(s)]
can be simplified to:
        s[a:]

Slice expressions of the form:
        s[0:n]
can be simplified to:
        s[:n]

Slice expressions of the form:
        s[:][:]
can be simplified to:
        s[:]
gingerBill commented 3 years ago

Brace styles:

default and 1tbs
    foo :: proc(x: int) -> int {
        if x > 0 {
            return x * 123;
        } else {
            return -x * 345;
        }
    }

allman
    foo :: proc(x: int) -> int 
    {
        if x > 0 
        {
            return x * 123;
        } 
        else 
        {
            return -x * 345;
        }
    }

k&r
    foo :: proc(x: int) -> int 
    {
        if x > 0 {
            return x * 123;
        } else {
            return -x * 345;
        }
    }

stroustrup
    foo :: proc(x: int) -> int {
        if x > 0 {
            return x * 123;
        } 
        else {
            return -x * 345;
        }
    }
ThisDevDane commented 3 years ago

Not sure what discussion category this should be converted to @gingerBill

jasonKercher commented 2 years ago

I'll take this on as long as you are okay with an Odin rookie doing it.

ThisDevDane commented 2 years ago

Odinfmt is already being worked on but you’re welcome to try anyway :)

github-actions[bot] commented 2 years ago

Hello!

I am marking this issue as stale as it has not received any engagement from the community or maintainers 120 days. That does not imply that the issue has no merit! If you feel strongly about this issue

The motivation for this automation is to help prioritize issues in the backlog and not ignore, reject, or belittle anyone..