Skip to content

Commit

Permalink
feat: yaml formatting
Browse files Browse the repository at this point in the history
all yaml is now formatted with prettier.
  • Loading branch information
ohlsont committed Dec 30, 2021
1 parent bb162a7 commit 3b58b4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mage/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func All() {
mggolangcilint.GolangciLint,
mggoreview.Goreview,
mgprettier.FormatMarkdown,
mgprettier.FormatYAML,
)
mg.SerialDeps(
mggo.GoModTidy,
Expand Down
16 changes: 16 additions & 0 deletions targets/mgprettier/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func FormatMarkdown(ctx context.Context) error {
return sh.RunV(executable, args...)
}

func FormatYAML(ctx context.Context) error {
logger := mglog.Logger("prettier")
ctx = logr.NewContext(ctx, logger)
prettierrc := filepath.Join(mgtool.GetPath(), "prettier", ".prettierrc.js")
mg.CtxDeps(ctx, mg.F(prepare, prettierrc))
args := []string{
"--config",
"./.tools/prettier/.prettierrc.js",
"--write",
"**/*.y*ml",
"!.tools",
}
logger.Info("formatting YAML files...")
return sh.RunV(executable, args...)
}

func prepare(ctx context.Context, prettierrc string) error {
// Check if npm is installed
if err := sh.Run("npm", "version"); err != nil {
Expand Down

0 comments on commit 3b58b4a

Please sign in to comment.