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

Group DeclStmt instead of splitting with empty lines #121

Open
bombsimon opened this issue Mar 15, 2023 · 0 comments
Open

Group DeclStmt instead of splitting with empty lines #121

bombsimon opened this issue Mar 15, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@bombsimon
Copy link
Owner

bombsimon commented Mar 15, 2023

Currently the fixer does not do any rewrite other than adding or removing empty lines. Usually this is the only thing we can do but there are cases where we can do more complex rewrites.

The original idea with declarations should never be cuddled was to convert like this:

FromTo
var foo = 1
var notFoo = 2
var b = 3
var aBitLonger = errors.New("an error")
var (
    foo        = 1
    notFoo     = 2
    b          = 3
    aBitLonger = errors.New("an error")
)

Mostly because it aligns the variables which when a lot of them are stacked (can for someone like me) improve readability.

This was implemented fairly easy in the original PR but after digging deeper with edge cases around comments it became very complex to figure out where comments would end up. Working with comments in general is very annoying due to the fact that they're not a part of the ast. I tried to use dst which helps a lot but even dst can behave different depending on the context in regards to which node a comment gets tied to.

I want to keep tracking this because it would be a nice feature and I think a decent compromise would be to merge all DeclStmt that has no comment or is a single line with a comment after the node since that would probably cover a majority of the cases. Something like this:

FromTo
var a = 1
var b = 2 // This is fine
var c = 3

var (
    d = 4
)
var (
    e = 5 // This should be fine
    f = 6
)

// Comment above
var g = 7
var h = 8
// Comment after

// Comment between with spaces

var i = 9
// Between no spaces
var j = 10
var (
    a = 1
    b = 2 // This is fine
    c = 3
)

var (
    d = 4
    e = 5 // This should be fine
    f = 6
)

// Comment above
var g = 7
var h = 8
// Comment after

// Comment between with spaces

var i = 9
// Between no spaces
var j = 10
@bombsimon bombsimon added the enhancement New feature or request label Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant