auditfile

package
v0.0.0-...-5ef9fcc Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoQuote

func AutoQuote(s string) string

AutoQuote returns s or, if quoting is required for s to appear in a go.mod, the quotation of s.

func ModulePath

func ModulePath(mod []byte) string

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

func MustQuote(s string) bool

MustQuote reports whether s must be quoted in order to appear as a single token in a go.mod line.

func SortTrust

func SortTrust(list []*Trust)

func SortViolation

func SortViolation(list []*Violation)

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

type CommentBlock struct {
	Comments
	Start Position
}

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.

func (*Comments) Comment

func (c *Comments) Comment() *Comments

Comment returns the receiver. This isn't useful by itself, but a Comments struct is embedded into all the expression implementation types, and this gives each of those a Comment method to satisfy the Expr interface.

type ErrorList

type ErrorList []error

func (ErrorList) Error

func (e ErrorList) Error() string

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 {
	Audit     *FileVersion
	Trust     []*Trust
	Violation []*Violation

	Syntax *FileSyntax
}

func Parse

func Parse(file string, data []byte) (parsed *File, err error)

func (File) String

func (f File) String() string

type FileSyntax

type FileSyntax struct {
	Name string // file path
	Comments
	Stmt []Expr
}

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, (*Line).markRemoved 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 FileVersion

type FileVersion struct {
	Version string
	Syntax  *Line
}

type LParen

type LParen struct {
	Comments
	Pos Position
}

An LParen represents the beginning of a parenthesized line block. It is a place to store suffix comments.

func (*LParen) Span

func (x *LParen) Span() (start, end Position)

type LexError

type LexError struct {
	Filename string
	Pos      Position
	Err      error
}

func (LexError) Error

func (e LexError) Error() string

type Line

type Line struct {
	Comments
	Start   Position
	Token   []string
	InBlock bool
	End     Position
}

A Line is a single line of tokens.

func (*Line) Span

func (x *Line) Span() (start, end Position)

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"
)

func (*LineBlock) Span

func (x *LineBlock) Span() (start, end Position)

type ParserError

type ParserError struct {
	Filename string
	Pos      Position
	Err      error
	Verb     string
	ModPath  string
}

func (ParserError) Error

func (e ParserError) Error() string

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 an arbitrary source position in a file, including the file, line, column, and byte offset.

func (Position) String

func (p Position) String() string

type RParen

type RParen struct {
	Comments
	Pos Position
}

An RParen represents the end of a parenthesized line block. It is a place to store whole-line (before) comments.

func (*RParen) Span

func (x *RParen) Span() (start, end Position)

type Trust

type Trust struct {
	Mod       VersionInterval
	Notes     string
	Signature string
	Syntax    *Line
}

func (Trust) String

func (t Trust) String() string

type VersionInterval

type VersionInterval struct {
	Path      string
	Low, High string
}

func (VersionInterval) String

func (v VersionInterval) String() string

type Violation

type Violation Trust

func (Violation) String

func (v Violation) String() string

Jump to

Keyboard shortcuts

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