format

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlignTypeAssign  = "assign"
	AlignTypeField   = "field"
	AlignTypeDisable = "disable"
)
View Source
const (
	FieldLineCommaAdd     = "add"
	FieldLineCommaRemove  = "remove"
	FieldLineCommaDisable = "disable"
)

Variables

View Source
var Align = "field"
View Source
var BadNodeError = errors.New("syntax error")
View Source
var FieldLineComma = "disable"
View Source
var Indent = "    "

Functions

func EqualsAfterFormat

func EqualsAfterFormat(doc1, doc2 string) error

FormatedEquals is used to judge if documents has been changed after formated implementation: ignore all space charactor to compare two strings

func FormatDocument

func FormatDocument(doc *parser.Document) (string, error)

func FormatDocumentWithValidation added in v0.1.4

func FormatDocumentWithValidation(doc *parser.Document, selfValidation bool) (string, error)

func MustFormat

func MustFormat(tplText string, formatter any) string

func MustFormatAnnotation

func MustFormatAnnotation(anno *parser.Annotation, isLast bool) string

func MustFormatAnnotations

func MustFormatAnnotations(annotations *parser.Annotations) string

func MustFormatCPPInclude

func MustFormatCPPInclude(inc *parser.CPPInclude) string

func MustFormatComments

func MustFormatComments(comments []*parser.Comment, indent string) string

TODO(jpf): 多行注释,换行上还需要优化 MustFormatComments formats comments return string doesn't include '\n' end of line

func MustFormatConst

func MustFormatConst(cst *parser.Const) string

func MustFormatConstValue

func MustFormatConstValue(cv *parser.ConstValue, indent string, newLine bool) string

func MustFormatEndLineComments

func MustFormatEndLineComments(comments []*parser.Comment, indent string) string

func MustFormatEnum

func MustFormatEnum(enum *parser.Enum) string

func MustFormatEnumValue

func MustFormatEnumValue(enumValue *parser.EnumValue, space, indent string) string

func MustFormatEnumValues

func MustFormatEnumValues(values []*parser.EnumValue, indent string) string

func MustFormatException

func MustFormatException(excep *parser.Exception) string

func MustFormatField

func MustFormatField(field *parser.Field, space string, indent string, oneline bool) string

func MustFormatFieldType

func MustFormatFieldType(ft *parser.FieldType) string

func MustFormatFields

func MustFormatFields(fields []*parser.Field, indent string) string

func MustFormatFunction

func MustFormatFunction(fn *parser.Function, indent string) string

func MustFormatFunctions

func MustFormatFunctions(fns []*parser.Function, indent string) string

func MustFormatIdentifier

func MustFormatIdentifier(id *parser.Identifier) string

func MustFormatInclude

func MustFormatInclude(inc *parser.Include) string

func MustFormatKeyword

func MustFormatKeyword(kw parser.Keyword) string

func MustFormatLiteral

func MustFormatLiteral(l *parser.Literal, indent string) string

func MustFormatNamespace

func MustFormatNamespace(ns *parser.Namespace) string

func MustFormatOneLineFields

func MustFormatOneLineFields(fields []*parser.Field) string

func MustFormatService

func MustFormatService(svc *parser.Service) string

func MustFormatStruct

func MustFormatStruct(st *parser.Struct) string

func MustFormatThrows

func MustFormatThrows(throws *parser.Throws) string

func MustFormatTypeName

func MustFormatTypeName(tn *parser.TypeName) string

func MustFormatTypedef

func MustFormatTypedef(td *parser.Typedef) string

func MustFormatUnion

func MustFormatUnion(union *parser.Union) string

Types

type ConstFormatter

type ConstFormatter struct {
	Comments        string
	Const           string
	Type            string
	Name            string
	Annotations     string
	Equal           string
	Value           string
	ListSeparator   string
	EndLineComments string
}

type EnumFormatter

type EnumFormatter struct {
	Comments        string
	Enum            string
	Identifier      string
	LCUR            string
	EnumValues      string
	RCUR            string
	Annotations     string
	EndLineComments string
}

type ExceptionFormatter

type ExceptionFormatter struct {
	Comments        string
	Exception       string
	Identifier      string
	LCUR            string
	Fields          string
	RCUR            string
	Annotations     string
	EndLineComments string
}

type FunctionFormatter

type FunctionFormatter struct {
	Oneway          string
	FunctionType    string
	Identifier      string
	LPAR            string
	Args            string
	RPAR            string
	Throws          string
	Annotations     string
	ListSeparator   string
	EndLineComments string
}

type IncludeFormatter

type IncludeFormatter struct {
	Comments        string
	Include         string
	Path            string
	EndLineComments string
}

type NamespaceFormatter

type NamespaceFormatter struct {
	Comments        string
	Namespace       string
	Language        string
	Name            string
	Annotations     string
	EndLineComments string
}

type Options added in v0.1.4

type Options struct {
	// Do not print reformatted sources to standard output.
	// If a file's formatting is different from thriftls's, overwrite it
	// with thrfitls's version.
	Write bool `yaml:"rewrite"`

	// Indent to use. Support: nspace(s), ntab(s). example: 4spaces, 1tab, tab
	// if indent format is invalid or not specified, default is 4spaces
	Indent string `yaml:"indent"`

	// Do not print reformatted sources to standard output.
	// If a file's formatting is different than gofmt's, print diffs
	// to standard output.
	Diff bool `yaml:"diff"`

	// Align enables align option for struct/enum/exception/union fields
	// Options: "field", "assign", "disable"
	// Default is "field" if not set
	Align string `yaml:"alignByAssign"`

	// FieldLineComma represents whether to add or remove comma at the end of field line.
	// Options: "add", "remove", "disable"
	// if choose disable, user input will be retained without modification
	// Default is "disable" if not set
	FieldLineComma string `yaml:"fieldLineComma"`
}

func (*Options) GetIndent added in v0.1.4

func (o *Options) GetIndent() string

func (*Options) InitDefault added in v0.1.6

func (o *Options) InitDefault()

func (*Options) SetFlags added in v0.1.4

func (o *Options) SetFlags()

type ServiceFormatter

type ServiceFormatter struct {
	Comments          string
	Service           string
	Identifier        string
	LCUR              string
	Functions         string
	RCUR              string
	Annotations       string
	EndLineComments   string
	Extends           string
	ExtendServiceName string
}

type StructFormatter

type StructFormatter struct {
	Comments        string
	Struct          string
	Identifier      string
	LCUR            string
	Fields          string
	RCUR            string
	Annotations     string
	EndLineComments string
}

type ThrowFormatter

type ThrowFormatter struct {
	Throw  string
	LPAR   string
	Fields string
	RPAR   string
}

type TypedefFormatter

type TypedefFormatter struct {
	Comments        string
	Typedef         string
	Type            string
	Name            string
	Annotations     string
	EndLineComments string
}

type UnionFormatter

type UnionFormatter struct {
	Comments        string
	Union           string
	Identifier      string
	LCUR            string
	Fields          string
	RCUR            string
	Annotations     string
	EndLineComments string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL