Documentation
¶
Index ¶
- func AutoQuote(s string) string
- func Format(f *FileSyntax) []byte
- func IsDirectoryPath(ns string) bool
- func ModulePath(mod []byte) string
- func MustQuote(s string) bool
- func ParseGopkgIn(path string) (root, repo, major, subdir string, ok bool)
- type Comment
- type CommentBlock
- type Comments
- type Exclude
- type Expr
- type File
- func (f *File) AddComment(text string)
- func (f *File) AddExclude(path, vers string) error
- func (f *File) AddModuleStmt(path string) error
- func (f *File) AddNewRequire(path, vers string, indirect bool)
- func (f *File) AddReplace(oldPath, oldVers, newPath, newVers string) error
- func (f *File) AddRequire(path, vers string) error
- func (f *File) Cleanup()
- func (f *File) DropExclude(path, vers string) error
- func (f *File) DropReplace(oldPath, oldVers string) error
- func (f *File) DropRequire(path string) error
- func (f *File) Format() ([]byte, error)
- func (f *File) SetRequire(req []*Require)
- func (f *File) SortBlocks()
- type FileSyntax
- type LParen
- type Line
- type LineBlock
- type Module
- type Position
- type RParen
- type Replace
- type Require
- type VersionFixer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoQuote ¶
AutoQuote returns s or, if quoting is required for s to appear in a go.mod, the quotation of s.
func Format ¶
func Format(f *FileSyntax) []byte
func IsDirectoryPath ¶
IsDirectoryPath reports whether the given path should be interpreted as a directory path. Just like on the go command line, relative paths and rooted paths are directory paths; the rest are module paths.
func ModulePath ¶
ModulePath returns the module path from the gomod file text. If it cannot find a module path, it returns an empty string. It is tolerant of unrelated problems in the go.mod file.
func MustQuote ¶
MustQuote reports whether s must be quoted in order to appear as a single token in a go.mod line.
func ParseGopkgIn ¶
ParseGopkgIn splits gopkg.in import paths into their constituent parts
Types ¶
type Comment ¶
type Comment struct {
Start Position
Token string // without trailing newline
Suffix bool // an end of line (not whole line) comment
}
A Comment represents a single // comment.
type CommentBlock ¶
A CommentBlock represents a top-level block of comments separate from any rule.
func (*CommentBlock) Span ¶
func (x *CommentBlock) Span() (start, end Position)
type Comments ¶
type Comments struct {
Before []Comment // whole-line comments before this expression
Suffix []Comment // end-of-line comments after this expression
// For top-level expressions only, After lists whole-line
// comments following the expression.
After []Comment
}
Comments collects the comments associated with an expression.
type Expr ¶
type Expr interface {
// Span returns the start and end position of the expression,
// excluding leading or trailing comments.
Span() (start, end Position)
// Comment returns the comments attached to the expression.
// This method would normally be named 'Comments' but that
// would interfere with embedding a type of the same name.
Comment() *Comments
}
An Expr represents an input element.
type File ¶
type File struct {
Module *Module
Require []*Require
Exclude []*Exclude
Replace []*Replace
Syntax *FileSyntax
}
A File is the parsed, interpreted form of a go.mod file.
func (*File) AddComment ¶
func (*File) AddExclude ¶
func (*File) AddModuleStmt ¶
func (*File) AddNewRequire ¶
func (*File) AddReplace ¶
func (*File) AddRequire ¶
func (*File) Cleanup ¶
func (f *File) Cleanup()
Cleanup cleans up the file f after any edit operations. To avoid quadratic behavior, modifications like DropRequire clear the entry but do not remove it from the slice. Cleanup cleans out all the cleared entries.
func (*File) DropExclude ¶
func (*File) DropReplace ¶
func (*File) DropRequire ¶
func (*File) SetRequire ¶
func (*File) SortBlocks ¶
func (f *File) SortBlocks()
type FileSyntax ¶
A FileSyntax represents an entire go.mod file.
func (*FileSyntax) Cleanup ¶
func (x *FileSyntax) Cleanup()
Cleanup cleans up the file syntax x after any edit operations. To avoid quadratic behavior, removeLine marks the line as dead by setting line.Token = nil but does not remove it from the slice in which it appears. After edits have all been indicated, calling Cleanup cleans out the dead lines.
func (*FileSyntax) Span ¶
func (x *FileSyntax) Span() (start, end Position)
type LParen ¶
An LParen represents the beginning of a parenthesized line block. It is a place to store suffix comments.
type LineBlock ¶
type LineBlock struct {
Comments
Start Position
LParen LParen
Token []string
Line []*Line
RParen RParen
}
A LineBlock is a factored block of lines, like
require ( "x" "y" )
type Position ¶
type Position struct {
Line int // line in input (starting at 1)
LineRune int // rune in line (starting at 1)
Byte int // byte in input (starting at 0)
}
A Position describes the position between two bytes of input.
type RParen ¶
An RParen represents the end of a parenthesized line block. It is a place to store whole-line (before) comments.