Skip to content

Commit

Permalink
UPDATE: partial revert for ordered frontmatter keys
Browse files Browse the repository at this point in the history
  • Loading branch information
fileformat committed Mar 10, 2024
1 parent bf73f9e commit 19b2225
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/antchfx/xpath v1.2.0 // indirect
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/antchfx/xpath v1.2.0 h1:mbwv7co+x0RwgeGAOHdrKy89GvHaGvxxBtPK0uF9Zr8=
github.com/antchfx/xpath v1.2.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/bmatcuk/doublestar/v4 v4.0.2 h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA=
github.com/bmatcuk/doublestar/v4 v4.0.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b h1:3G9nSrTyBZcQMI9phQK1XvSDCb8E6b1+6E5dcr+R2MU=
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b/go.mod h1:dcE/RHCVM8522lLVHLcdgxCuQEYE5Zhn6VPXcxALaNs=
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
Expand Down
16 changes: 14 additions & 2 deletions internal/command/frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/FileFormatInfo/fflint/internal/shared"
"github.com/adrg/frontmatter"
"github.com/spf13/cobra"
yamlv2 "gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ func frontmatterCheck(f *shared.FileContext) {
}
}

yamlRawData := make(map[string]any)
yamlRawData := make(map[any]any)
//LATER: maybe flag to require contents?
_, parseErr := frontmatter.MustParse(bytes.NewReader(data), &yamlRawData, formats...)

Expand Down Expand Up @@ -116,8 +117,19 @@ func frontmatterCheck(f *shared.FileContext) {
}

if fmSorted {
sortedData := yamlv2.MapSlice{}

frontmatter.Parse(bytes.NewReader(data), &sortedData)
previousKey := ""
for currentKey := range yamlData {
for _, item := range sortedData {
currentKey, strErr := item.Key.(string)
if !strErr {
f.RecordResult("frontmatterSortedParse", false, map[string]interface{}{
"err": "key is not a string",
"key": fmt.Sprintf("%v", item.Key),
})
continue
}
f.RecordResult("frontmatterSorted", previousKey < currentKey, map[string]interface{}{
"previous": previousKey,
"current": currentKey,
Expand Down

0 comments on commit 19b2225

Please sign in to comment.