-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since I was only using one simple feature of go 1.20 and nothing unique from go 1.19, it did not really make any sense to require such a new version. Downgrading it will make it easier for pre-commit users or folks installing through `go install`. Implemented an Errors collection type to replicate the errors.Join feature from go 1.20. Fixed a small path matching issue for exclusions.
- Loading branch information
Showing
10 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
- id: yamlfmt | ||
name: yamlfmt | ||
description: This hook uses github.com/google/yamlfmt to format yaml files. Requires golang >1.20 to be installed. | ||
description: This hook uses github.com/google/yamlfmt to format yaml files. Requires golang >1.18 to be installed. | ||
entry: yamlfmt | ||
language: golang | ||
types: [yaml] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/google/yamlfmt | ||
|
||
go 1.20 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/RageCage64/multilinediff v0.2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package collections | ||
|
||
import "errors" | ||
|
||
type Errors []error | ||
|
||
func (errs Errors) Combine() error { | ||
errMessage := "" | ||
|
||
for _, err := range errs { | ||
if err != nil { | ||
errMessage += err.Error() + "\n" | ||
} | ||
} | ||
|
||
if len(errMessage) == 0 { | ||
return nil | ||
} | ||
return errors.New(errMessage) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package collections_test | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/yamlfmt/internal/collections" | ||
) | ||
|
||
func TestErrorsCombine(t *testing.T) { | ||
errs := collections.Errors{ | ||
errors.New("a"), | ||
nil, | ||
errors.New("c"), | ||
} | ||
err := errs.Combine() | ||
if err == nil { | ||
t.Fatal("expected combined err not to be nil") | ||
} | ||
for _, errEl := range errs { | ||
if errEl == nil { | ||
continue | ||
} | ||
if !strings.Contains(err.Error(), errEl.Error()) { | ||
t.Fatalf("expected combined err to contain %v, got: %v", errEl, err) | ||
} | ||
} | ||
} | ||
|
||
func TestErrorsCombineEmpty(t *testing.T) { | ||
errs := collections.Errors{} | ||
err := errs.Combine() | ||
if err != nil { | ||
t.Fatalf("expected combined err to be nil, got: %v", err) | ||
} | ||
} | ||
|
||
func TestErrorsCombineNilElements(t *testing.T) { | ||
errs := collections.Errors{nil, nil, nil} | ||
err := errs.Combine() | ||
if err != nil { | ||
t.Fatalf("expected combined err to be nil, got: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters