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

golang formatter: problem when code snippet is not a full file #151

Closed
ccoVeille opened this issue Apr 2, 2024 · 7 comments · Fixed by #154
Closed

golang formatter: problem when code snippet is not a full file #151

ccoVeille opened this issue Apr 2, 2024 · 7 comments · Fixed by #154

Comments

@ccoVeille
Copy link
Contributor

ccoVeille commented Apr 2, 2024

```go
var err = errors.New("dddd")

type Whatever struct {
     StartAt                time.Time  `json:"start_at"`
                End                time.Time  `json:"end_at"`
    Delete bool `json:-"`
}
```

golang can only be formatted with tools if the file is valid.

So if the linting doesn't work you can try to add this to the begining of the file

```go
package main

// REMOVE ANYTHING ABOVE THIS

var err = errors.New("dddd")

type Whatever struct {
     StartAt                time.Time  `json:"start_at"`
                End                time.Time  `json:"end_at"`
    Delete bool `json:-"`
}
```

mdsf will then be able to format like this

```go
package main

// REMOVE ANYTHING ABOVE THIS

var err = errors.New("dddd")

type Whatever struct {
	StartAt time.Time `json:"start_at"`
	End     time.Time `json:"end_at"`
	Delete  bool      `json:-"`
}
```

Then if you trim the code then

```go
var err = errors.New("dddd")

type Whatever struct {
	StartAt time.Time `json:"start_at"`
	End     time.Time `json:"end_at"`
	Delete  bool      `json:-"`
}
```

It would be a more fail proof hack but quite an hack

@hougesen
Copy link
Owner

hougesen commented Apr 2, 2024

Good catch 🚀

@hougesen
Copy link
Owner

hougesen commented Apr 2, 2024

I believe #154 should fix the issue. It passes tests for both with and without package name 😄

@ccoVeille
Copy link
Contributor Author

I'll check by running on my documentation codebase.

@ccoVeille
Copy link
Contributor Author

Good catch 🚀

I hope you are finding all my feedback useful. I hope I'm a good alpha/beta tester 😅

@hougesen
Copy link
Owner

hougesen commented Apr 2, 2024

You are an amazing bug finder ❤️

@ccoVeille
Copy link
Contributor Author

I found a possible edge case

#154 (comment)

@ccoVeille
Copy link
Contributor Author

I'll check by running on my documentation codebase.

It works as expected

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 a pull request may close this issue.

2 participants