Documentation ¶
Overview ¶
Package internal contains the internals of gosrt.
Index ¶
- func FilterFileComments(file *ast.File, filter func(*ast.CommentGroup) bool) (removed []*ast.CommentGroup)
- func FilterFileDecls(file *ast.File, filter func(ast.Decl) bool)
- func Within(inner, outer ast.Node) bool
- type BaseFile
- func (file *BaseFile) After() []byte
- func (file *BaseFile) Changed() bool
- func (file *BaseFile) Diff(ctx context.Context, now time.Time) (string, error)
- func (file *BaseFile) Print() error
- func (file *BaseFile) String() string
- func (file *BaseFile) Transform(_ context.Context, transformer Transformer) error
- type File
- type FsFile
- type Sorter
- type StdFile
- type Transformer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterFileComments ¶
func FilterFileComments( file *ast.File, filter func(*ast.CommentGroup) bool, ) (removed []*ast.CommentGroup)
FilterFileComments removes each comment from a file’s AST for which the supplied filter returns true. The removed comments are returned.
func FilterFileDecls ¶
FilterFileDecls removes each declaration from a file’s AST for which the supplied filter returns true.
Types ¶
type BaseFile ¶
type BaseFile struct {
// contains filtered or unexported fields
}
BaseFile has common fields and methods for file-like things.
func (*BaseFile) Diff ¶
Diff uses diff(1) to print the differences between the original file and the same file transformed.
Example ¶
if err := os.Setenv("TZ", "UTC0"); err != nil { panic(err) } file := &BaseFile{ after: []byte(`foo baz `), before: []byte(`foo bar `), mtime: time.Unix(0, 0), name: "example", } diff, err := file.Diff(context.Background(), file.mtime) if err != nil { panic(err) } fmt.Println(diff) //nolint:godot // Come on!
Output: diff -u example.orig example --- example.orig 1970-01-01 00:00:00.000000000 +0000 +++ example 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +1,2 @@ foo -bar +baz
type File ¶
type File interface { fmt.Stringer After() []byte Backup(suffix string) error Changed() bool Compare(other File) int Diff(ctx context.Context, now time.Time) (string, error) Print() error Transform(ctx context.Context, transformer Transformer) error Write() error }
File is something file-like.
func AppendFile ¶
AppendFile inserts a File into its sorted position in a slice of Files.
type FsFile ¶
type FsFile struct { BaseFile // contains filtered or unexported fields }
FsFile is a file in a file system.
type Sorter ¶
type Sorter struct {
// contains filtered or unexported fields
}
Sorter can sort a Go file.
func NewSorter ¶
NewSorter returns a new Sorter for some source code. The source is passed on to go/parser.ParseFile.
type StdFile ¶
type StdFile struct {
BaseFile
}
StdFile is a ‘file’ that is read from STDIN and printed to STDOUT.
func NewStdFile ¶
NewStdFile returns a new StdFile whose contents are read from STDIN.
type Transformer ¶
Transformer is a function that takes bytes, transforms them and returns them.