summaryrefslogtreecommitdiff
path: root/vendor/github.com/google/yamlfmt/formatters
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-24 17:40:45 -0600
committermo khan <mo@mokhan.ca>2025-07-24 17:40:45 -0600
commitd48fe690c3c071cb5c8e3aa4d4672a32230a5e2d (patch)
tree414f9e91877e901cb3de12be6f466cb4929f55ab /vendor/github.com/google/yamlfmt/formatters
parent7257c213887c6a80f727642b016606ec10340ed9 (diff)
refactor: extract job to process relationship updates in background
Diffstat (limited to 'vendor/github.com/google/yamlfmt/formatters')
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/config.go35
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/features.go30
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/features/check.go (renamed from vendor/github.com/google/yamlfmt/formatters/basic/anchors/check.go)4
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/features/force_sequence.go43
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/features/yaml_feature.go31
-rw-r--r--vendor/github.com/google/yamlfmt/formatters/basic/formatter.go16
6 files changed, 121 insertions, 38 deletions
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/config.go b/vendor/github.com/google/yamlfmt/formatters/basic/config.go
index 82e67eb..2a32d05 100644
--- a/vendor/github.com/google/yamlfmt/formatters/basic/config.go
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/config.go
@@ -18,25 +18,28 @@ import (
"runtime"
"github.com/google/yamlfmt"
+ yamlFeatures "github.com/google/yamlfmt/formatters/basic/features"
)
type Config struct {
- Indent int `mapstructure:"indent"`
- IncludeDocumentStart bool `mapstructure:"include_document_start"`
- LineEnding yamlfmt.LineBreakStyle `mapstructure:"line_ending"`
- LineLength int `mapstructure:"max_line_length"`
- RetainLineBreaks bool `mapstructure:"retain_line_breaks"`
- RetainLineBreaksSingle bool `mapstructure:"retain_line_breaks_single"`
- DisallowAnchors bool `mapstructure:"disallow_anchors"`
- ScanFoldedAsLiteral bool `mapstructure:"scan_folded_as_literal"`
- IndentlessArrays bool `mapstructure:"indentless_arrays"`
- DropMergeTag bool `mapstructure:"drop_merge_tag"`
- PadLineComments int `mapstructure:"pad_line_comments"`
- TrimTrailingWhitespace bool `mapstructure:"trim_trailing_whitespace"`
- EOFNewline bool `mapstructure:"eof_newline"`
- StripDirectives bool `mapstructure:"strip_directives"`
- ArrayIndent int `mapstructure:"array_indent"`
- IndentRootArray bool `mapstructure:"indent_root_array"`
+ Indent int `mapstructure:"indent"`
+ IncludeDocumentStart bool `mapstructure:"include_document_start"`
+ LineEnding yamlfmt.LineBreakStyle `mapstructure:"line_ending"`
+ LineLength int `mapstructure:"max_line_length"`
+ RetainLineBreaks bool `mapstructure:"retain_line_breaks"`
+ RetainLineBreaksSingle bool `mapstructure:"retain_line_breaks_single"`
+ DisallowAnchors bool `mapstructure:"disallow_anchors"`
+ ScanFoldedAsLiteral bool `mapstructure:"scan_folded_as_literal"`
+ IndentlessArrays bool `mapstructure:"indentless_arrays"`
+ DropMergeTag bool `mapstructure:"drop_merge_tag"`
+ PadLineComments int `mapstructure:"pad_line_comments"`
+ TrimTrailingWhitespace bool `mapstructure:"trim_trailing_whitespace"`
+ EOFNewline bool `mapstructure:"eof_newline"`
+ StripDirectives bool `mapstructure:"strip_directives"`
+ ArrayIndent int `mapstructure:"array_indent"`
+ IndentRootArray bool `mapstructure:"indent_root_array"`
+ DisableAliasKeyCorrection bool `mapstructure:"disable_alias_key_correction"`
+ ForceArrayStyle yamlFeatures.SequenceStyle `mapstructure:"force_array_style"`
}
func DefaultConfig() *Config {
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/features.go b/vendor/github.com/google/yamlfmt/formatters/basic/features.go
index de736f4..fc933f4 100644
--- a/vendor/github.com/google/yamlfmt/formatters/basic/features.go
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/features.go
@@ -15,9 +15,8 @@
package basic
import (
- "github.com/braydonk/yaml"
"github.com/google/yamlfmt"
- "github.com/google/yamlfmt/formatters/basic/anchors"
+ yamlFeatures "github.com/google/yamlfmt/formatters/basic/features"
"github.com/google/yamlfmt/internal/features"
"github.com/google/yamlfmt/internal/hotfix"
)
@@ -55,24 +54,19 @@ func ConfigureFeaturesFromConfig(config *Config) yamlfmt.FeatureList {
return configuredFeatures
}
-// These features will directly use the `yaml.Node` type and
-// as such are specific to this formatter.
-type YAMLFeatureFunc func(yaml.Node) error
-type YAMLFeatureList []YAMLFeatureFunc
+func ConfigureYAMLFeaturesFromConfig(config *Config) yamlFeatures.YAMLFeatureList {
+ var featureList yamlFeatures.YAMLFeatureList
-func (y YAMLFeatureList) ApplyFeatures(node yaml.Node) error {
- for _, f := range y {
- if err := f(node); err != nil {
- return err
- }
+ if config.DisallowAnchors {
+ featureList = append(featureList, yamlFeatures.Check)
}
- return nil
-}
-func ConfigureYAMLFeaturesFromConfig(config *Config) YAMLFeatureList {
- var features YAMLFeatureList
- if config.DisallowAnchors {
- features = append(features, anchors.Check)
+ if config.ForceArrayStyle != "" {
+ featureList = append(
+ featureList,
+ yamlFeatures.FeatureForceSequenceStyle(config.ForceArrayStyle),
+ )
}
- return features
+
+ return featureList
}
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/anchors/check.go b/vendor/github.com/google/yamlfmt/formatters/basic/features/check.go
index aef3070..368de5c 100644
--- a/vendor/github.com/google/yamlfmt/formatters/basic/anchors/check.go
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/features/check.go
@@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package anchors
+package features
import (
"errors"
"fmt"
- "github.com/braydonk/yaml"
+ "github.com/google/yamlfmt/pkg/yaml"
)
func Check(n yaml.Node) error {
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/features/force_sequence.go b/vendor/github.com/google/yamlfmt/formatters/basic/features/force_sequence.go
new file mode 100644
index 0000000..f3f956c
--- /dev/null
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/features/force_sequence.go
@@ -0,0 +1,43 @@
+// Copyright 2025 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package features
+
+import "github.com/google/yamlfmt/pkg/yaml"
+
+type SequenceStyle string
+
+const (
+ SequenceStyleBlock SequenceStyle = "block"
+ SequenceStyleFlow SequenceStyle = "flow"
+)
+
+func FeatureForceSequenceStyle(style SequenceStyle) YAMLFeatureFunc {
+ var styleVal yaml.Style
+ if style == SequenceStyleFlow {
+ styleVal = yaml.FlowStyle
+ }
+ var forceStyle YAMLFeatureFunc
+ forceStyle = func(n yaml.Node) error {
+ var err error
+ for _, c := range n.Content {
+ if c.Kind == yaml.SequenceNode {
+ c.Style = styleVal
+ }
+ err = forceStyle(*c)
+ }
+ return err
+ }
+ return forceStyle
+}
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/features/yaml_feature.go b/vendor/github.com/google/yamlfmt/formatters/basic/features/yaml_feature.go
new file mode 100644
index 0000000..2657a53
--- /dev/null
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/features/yaml_feature.go
@@ -0,0 +1,31 @@
+// Copyright 2025 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package features
+
+import "github.com/google/yamlfmt/pkg/yaml"
+
+// These features will directly use the `yaml.Node` type and
+// as such are specific to this formatter.
+type YAMLFeatureFunc func(yaml.Node) error
+type YAMLFeatureList []YAMLFeatureFunc
+
+func (y YAMLFeatureList) ApplyFeatures(node yaml.Node) error {
+ for _, f := range y {
+ if err := f(node); err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/vendor/github.com/google/yamlfmt/formatters/basic/formatter.go b/vendor/github.com/google/yamlfmt/formatters/basic/formatter.go
index 26bcc45..1e69bdb 100644
--- a/vendor/github.com/google/yamlfmt/formatters/basic/formatter.go
+++ b/vendor/github.com/google/yamlfmt/formatters/basic/formatter.go
@@ -20,8 +20,9 @@ import (
"errors"
"io"
- "github.com/braydonk/yaml"
"github.com/google/yamlfmt"
+ yamlFeature "github.com/google/yamlfmt/formatters/basic/features"
+ "github.com/google/yamlfmt/pkg/yaml"
"github.com/mitchellh/mapstructure"
)
@@ -30,7 +31,7 @@ const BasicFormatterType string = "basic"
type BasicFormatter struct {
Config *Config
Features yamlfmt.FeatureList
- YAMLFeatures YAMLFeatureList
+ YAMLFeatures yamlFeature.YAMLFeatureList
}
// yamlfmt.Formatter interface
@@ -63,6 +64,10 @@ func (f *BasicFormatter) Format(input []byte) ([]byte, error) {
documents = append(documents, docNode)
}
+ if len(documents) == 0 {
+ return input, nil
+ }
+
// Run all YAML features.
for _, d := range documents {
if err := f.YAMLFeatures.ApplyFeatures(d); err != nil {
@@ -119,6 +124,13 @@ func (f *BasicFormatter) getNewEncoder(buf *bytes.Buffer) *yaml.Encoder {
}
e.SetIndentRootArray(f.Config.IndentRootArray)
+ // Yes I know I could SetCorrectAliasKeys(!f.Config.DisableAliasKeyCorrection)
+ // but I know myself and I know I'll get confused and have to go look up
+ // the source again next time I look and forget.
+ if !f.Config.DisableAliasKeyCorrection {
+ e.SetCorrectAliasKeys(true)
+ }
+
return e
}