github.com/google/yamlfmt@v0.12.2-0.20240514121411-7f77800e2681/formatters/basic/config.go (about)

     1  // Copyright 2022 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package basic
    16  
    17  import (
    18  	"runtime"
    19  
    20  	"github.com/google/yamlfmt"
    21  )
    22  
    23  type Config struct {
    24  	Indent                 int                    `mapstructure:"indent"`
    25  	IncludeDocumentStart   bool                   `mapstructure:"include_document_start"`
    26  	LineEnding             yamlfmt.LineBreakStyle `mapstructure:"line_ending"`
    27  	LineLength             int                    `mapstructure:"max_line_length"`
    28  	RetainLineBreaks       bool                   `mapstructure:"retain_line_breaks"`
    29  	RetainLineBreaksSingle bool                   `mapstructure:"retain_line_breaks_single"`
    30  	DisallowAnchors        bool                   `mapstructure:"disallow_anchors"`
    31  	ScanFoldedAsLiteral    bool                   `mapstructure:"scan_folded_as_literal"`
    32  	IndentlessArrays       bool                   `mapstructure:"indentless_arrays"`
    33  	DropMergeTag           bool                   `mapstructure:"drop_merge_tag"`
    34  	PadLineComments        int                    `mapstructure:"pad_line_comments"`
    35  }
    36  
    37  func DefaultConfig() *Config {
    38  	lineBreakStyle := yamlfmt.LineBreakStyleLF
    39  	if runtime.GOOS == "windows" {
    40  		lineBreakStyle = yamlfmt.LineBreakStyleCRLF
    41  	}
    42  	return &Config{
    43  		Indent:          2,
    44  		LineEnding:      lineBreakStyle,
    45  		PadLineComments: 1,
    46  	}
    47  }