Skip to content

Commit 19b2225

Browse files
committed
UPDATE: partial revert for ordered frontmatter keys
1 parent bf73f9e commit 19b2225

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/BurntSushi/toml v1.2.1 // indirect
3030
github.com/VividCortex/ewma v1.1.1 // indirect
3131
github.com/antchfx/xpath v1.2.0 // indirect
32+
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b // indirect
3233
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
3334
github.com/fatih/color v1.13.0 // indirect
3435
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ github.com/antchfx/xpath v1.2.0 h1:mbwv7co+x0RwgeGAOHdrKy89GvHaGvxxBtPK0uF9Zr8=
1414
github.com/antchfx/xpath v1.2.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
1515
github.com/bmatcuk/doublestar/v4 v4.0.2 h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA=
1616
github.com/bmatcuk/doublestar/v4 v4.0.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
17+
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b h1:3G9nSrTyBZcQMI9phQK1XvSDCb8E6b1+6E5dcr+R2MU=
18+
github.com/cevaris/ordered_map v0.0.0-20220813181356-34664b69742b/go.mod h1:dcE/RHCVM8522lLVHLcdgxCuQEYE5Zhn6VPXcxALaNs=
1719
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
1820
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
1921
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=

internal/command/frontmatter.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/FileFormatInfo/fflint/internal/shared"
99
"github.com/adrg/frontmatter"
1010
"github.com/spf13/cobra"
11+
yamlv2 "gopkg.in/yaml.v2"
1112
"gopkg.in/yaml.v3"
1213
)
1314

@@ -68,7 +69,7 @@ func frontmatterCheck(f *shared.FileContext) {
6869
}
6970
}
7071

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

@@ -116,8 +117,19 @@ func frontmatterCheck(f *shared.FileContext) {
116117
}
117118

118119
if fmSorted {
120+
sortedData := yamlv2.MapSlice{}
121+
122+
frontmatter.Parse(bytes.NewReader(data), &sortedData)
119123
previousKey := ""
120-
for currentKey := range yamlData {
124+
for _, item := range sortedData {
125+
currentKey, strErr := item.Key.(string)
126+
if !strErr {
127+
f.RecordResult("frontmatterSortedParse", false, map[string]interface{}{
128+
"err": "key is not a string",
129+
"key": fmt.Sprintf("%v", item.Key),
130+
})
131+
continue
132+
}
121133
f.RecordResult("frontmatterSorted", previousKey < currentKey, map[string]interface{}{
122134
"previous": previousKey,
123135
"current": currentKey,

0 commit comments

Comments
 (0)