sugg

package
v0.4.3-0...-af5a74a Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AvoidInit          = "go.general.avoid_init_function"
	AvoidPrint         = "go.general.avoid_printing_and_logging"
	CustomErrorCreated = "go.general.custom_error_created"
	ErrorfWithoutParam = "go.general.fmt_errorf_without_parameter"
	GoFmt              = "go.general.gofmt_not_used"
	GoLint             = "go.general.golint_not_satisfied"
	LengthSmallerZero  = "go.general.length_smaller_zero_impossible"
	OmittedErrorMsg    = "go.general.omitted_error_message"
	ExtraFunction      = "go.general.remove_extra_function"
	ExtraVar           = "go.general.remove_extra_variable"
	MainFunction       = "go.general.remove_main_function_and_correct_package_name"
	CommentSection     = "go.general.section_about_comments"
	StringsCompare     = "go.general.strings_compare_used"
	TrimSpaceUsed      = "go.general.strings_trim_space_used"
	SyntaxError        = "go.general.syntax_error"
	LenOfStringEqual   = "go.general.taking_length_of_string_to_check_empty"
	UseVarAssignment   = "go.general.use_variable_assignment"
)

general comments

Variables

View Source
var GeneralRegister = Register{
	Funcs: []SuggestionFunc{
		examGoFmt,
		examGoLint,
		examMainFunction,
		examStringLenComparison,
		examNoErrorMsg,
		examErrorfWithoutParams,
		examCustomError,
		examStringsCompare,
	},
	Severity: severity,
}

GeneralRegister registers all suggestion functions for this exercise.

Functions

func Contains

func Contains(comments []Comment, comment Comment) bool

Contains reports if the list of comments includes a certain comment.

func ExamExtraVariable

func ExamExtraVariable(pkg *astrav.Package, suggs Suggester)

ExamExtraVariable checks for a variable that can be inlined

func IsMultiAssignment

func IsMultiAssignment(decl astrav.Node) bool

IsMultiAssignment declaration assigns to multiple variables

Types

type Category

type Category string

Category defines an enumeration of comment categories

const (
	CtgTodo        Category = "todo"
	CtgImprovement Category = "improvement"
	CtgThought     Category = "thought"
	CtgBlock       Category = "block"
)

Category contants

type Comment

type Comment interface {

	// ID returns the comment identifier. e.g. `go.two-fer.missing_share_with_function`
	ID() string

	// Severity reports the severity of the comment.
	Severity() int

	// ToString returns the final comment the way it will be provided to the student.
	// If not already cached this involves pulling the comment from the git repository where it is located.
	ToString() string

	// Category returns the category of the comment.
	Category() Category
	// contains filtered or unexported methods
}

Comment defines a suggestion. A comment to the student.

func NewBlockComment

func NewBlockComment(s string) Comment

NewBlockComment creates a new block comment

func NewComment

func NewComment(s string) Comment

NewComment creates a new comment

func NewPlaceholderComment

func NewPlaceholderComment(comment string, params map[string]string) Comment

NewPlaceholderComment creates a new comment with placeholder(s).

type Register

type Register struct {
	// Funcs a registry of functions to be called. Each function should investigate one pattern and
	// can add one or multiple suggestions if the found pattern needs commenting.
	Funcs []SuggestionFunc

	// Severity defines how severe a comment is. A sum over all comments of 5 means no approval.
	// The maximum for a single comment is 5. A comment with that severity will block approval.
	// When assigning the severity a good guideline is to ask: How many comments of similar severity
	// should block approval?
	// We can be very strict on automated comments since the student has a very fast feedback loop.
	Severity map[string]int
}

Register defines a register type to be provided by every suggerter track implementation. It contains the functions to be called to get

type Suggester

type Suggester interface {
	// AppendUnique adds a suggestion while checking if it exists already.
	// That way it does not matter if the code accidentally adds the same suggestion multiple times.
	AppendUnique(comment string)

	// AppendUniquePH adds a suggestion with placeholders while checking if it exists already.
	AppendUniquePH(commentID string, params map[string]string)

	// ReportError collects provided errors. They will be added to the output file
	// for debugging purpose. Reporting will fail the analyzer with `refer_to_mentor` status.
	// If that is not what you want consider adding a comment to the student instead of an error.
	ReportError(err error)

	// HasSuggestion checks if a comment was added. This should not be used to avoid duplicated.
	// Duplicates are avoided by default. It might however be useful to check if some other algorithm
	// found a certain pattern so it doesn't have to be checked again.
	HasSuggestion(comment string) bool
}

Suggester defines a list of comments including severity information. The reason for this interface is mainly to provide a focused (limited) set of functionality to suggester implementers.

type SuggestionFunc

type SuggestionFunc func(pkg *astrav.Package, suggs Suggester)

SuggestionFunc defines a function checking a solution for a specific problem.

type SuggestionReport

type SuggestionReport struct {
	// contains filtered or unexported fields
}

SuggestionReport is a list of comments including severity information.

func NewSuggestions

func NewSuggestions() *SuggestionReport

NewSuggestions creates a new collection of suggestions.

func (*SuggestionReport) AppendBlock

func (s *SuggestionReport) AppendBlock(commentID string)

AppendBlock adds a block comment if it does not exist.

func (*SuggestionReport) AppendSeverity

func (s *SuggestionReport) AppendSeverity(severity map[string]int)

AppendSeverity adds new severities overwriting existing ones.

func (*SuggestionReport) AppendUnique

func (s *SuggestionReport) AppendUnique(commentID string)

AppendUnique adds a comment if it does not exist.

func (*SuggestionReport) AppendUniquePH

func (s *SuggestionReport) AppendUniquePH(commentID string, params map[string]string)

AppendUniquePH adds a comment with placeholder(s). Uniqueness includes the placeholder(s) and value(s).

func (*SuggestionReport) GetComments

func (s *SuggestionReport) GetComments() ([]Comment, int)

GetComments returns the comments and their severity sum.

func (*SuggestionReport) GetErrors

func (s *SuggestionReport) GetErrors() []error

GetErrors returns a list of errors that occured.

func (*SuggestionReport) HasSuggestion

func (s *SuggestionReport) HasSuggestion(commentID string) bool

HasSuggestion checks if the comment was added already. Params are ignored for comparison.

func (*SuggestionReport) ReportError

func (s *SuggestionReport) ReportError(err error)

ReportError reports an error to the analyzer.

Jump to

Keyboard shortcuts

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