Skip to content

Commit

Permalink
Merge pull request #1476 from duthils/eof-newline
Browse files Browse the repository at this point in the history
outputs: add trailing newline at the end of JSON files
  • Loading branch information
felixfontein authored Feb 15, 2025
2 parents 618c0ff + 54196f0 commit 8122a30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion functional-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,8 @@ bar: |-
r#"{
"foo": "bar",
"bar": "baz\nbam"
}"#
}
"#
);
}

Expand Down
2 changes: 2 additions & 0 deletions stores/json/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func (store *Store) EmitEncryptedFile(in sops.Tree) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("Error marshaling to json: %s", err)
}
out = append(out, '\n')
return out, nil
}

Expand All @@ -340,6 +341,7 @@ func (store *Store) EmitPlainFile(in sops.TreeBranches) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("Error marshaling to json: %s", err)
}
out = append(out, '\n')
return out, nil
}

Expand Down
18 changes: 12 additions & 6 deletions stores/json/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func TestDecodeJSON(t *testing.T) {
}
}
}
}`
}
`
expected := sops.TreeBranch{
sops.TreeItem{
Key: "glossary",
Expand Down Expand Up @@ -312,7 +313,8 @@ func TestEncodeJSONArrayOfObjects(t *testing.T) {
},
2
]
}`
}
`
store := Store{
config: config.JSONStoreConfig{
Indent: -1,
Expand Down Expand Up @@ -446,7 +448,8 @@ func TestIndentTwoSpaces(t *testing.T) {
},
2
]
}`
}
`
store := Store{
config: config.JSONStoreConfig{
Indent: 2,
Expand Down Expand Up @@ -488,7 +491,8 @@ func TestIndentDefault(t *testing.T) {
},
2
]
}`
}
`
store := Store{
config: config.JSONStoreConfig{
Indent: -1,
Expand Down Expand Up @@ -530,7 +534,8 @@ func TestNoIndent(t *testing.T) {
},
2
]
}`
}
`
store := Store{
config: config.JSONStoreConfig{
Indent: 0,
Expand Down Expand Up @@ -619,7 +624,8 @@ func TestComments(t *testing.T) {
},
2
]
}`
}
`
store := Store{
config: config.JSONStoreConfig{
Indent: 2,
Expand Down

0 comments on commit 8122a30

Please sign in to comment.