hougesen / mdsf

Format markdown code blocks using your favorite code formatters.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

ccoVeille opened this issue ยท comments

```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

Good catch ๐Ÿš€

I believe #154 should fix the issue. It passes tests for both with and without package name ๐Ÿ˜„

I'll check by running on my documentation codebase.

Good catch ๐Ÿš€

I hope you are finding all my feedback useful. I hope I'm a good alpha/beta tester ๐Ÿ˜…

You are an amazing bug finder โค๏ธ

I found a possible edge case

#154 (comment)

I'll check by running on my documentation codebase.

It works as expected