io

package
v0.0.0-...-235bf4a Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractGoCode

func ExtractGoCode(data []byte) string

The data is normally a combination of go code (with triple quote code blocks marker ```go ... ```) and wording explanation for the recommendation.

func GetFromRemote

func GetFromRemote(ctx context.Context, rawURL string) (string, error)

func MapGoComments

func MapGoComments(f ast.Node) map[string]*StructComment

ast Docs and comments are not binding with the Decl but the relative position of the Node, so we have to handle it specifically.

func MergeField

func MergeField(oldfield, newfield *ast.Field) *ast.Field

func MergeStructComments

func MergeStructComments(oldComments, newComments map[string]*StructComment) map[string]*StructComment

func RebuildCommentPos

func RebuildCommentPos(fwriter io.Writer, fset *token.FileSet, f *ast.File, comments map[string]*StructComment, offset token.Pos) error

func ResetCommentsPos

func ResetCommentsPos(comments *ast.CommentGroup) *ast.CommentGroup

func UpdateGoFile

func UpdateGoFile(ctx context.Context, file string, output *bytes.Buffer) error

UpdateGoFile update the `fileName` gofile with the content in `output`.

func WriteToCache

func WriteToCache(ctx context.Context, dest string, out string, namePattern string) (string, error)

WriteToCache write `out` to a temporary file under `dir`.

Types

type Result

type Result struct {
	Added     []string
	Removed   []string
	Changed   []string
	Unchanged []string
}

func (*Result) Accuracy

func (r *Result) Accuracy() float64

func (*Result) String

func (r *Result) String() string

type Results

type Results []Result

func CompareStruct

func CompareStruct(code, otherCode string, factors ...string) (*Results, error)

If codefactors is given, only compare the go structs whose name match the codefactor list.

func (Results) Accuracy

func (r Results) Accuracy() float64

type StructComment

type StructComment struct {
	Name    *ast.Ident
	Comment *ast.CommentGroup
	Fields  map[string]*ast.CommentGroup
}

func (*StructComment) SetCommentPos

func (s *StructComment) SetCommentPos(offset token.Pos) token.Pos

Jump to

Keyboard shortcuts

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