Documentation ¶
Index ¶
- Constants
- Variables
- func Contains(comments []Comment, comment Comment) bool
- func ExamExtraVariable(pkg *astrav.Package, suggs Suggester)
- func IsMultiAssignment(decl astrav.Node) bool
- type Category
- type Comment
- type Register
- type Suggester
- type SuggestionFunc
- type SuggestionReport
- func (s *SuggestionReport) AppendBlock(commentID string)
- func (s *SuggestionReport) AppendSeverity(severity map[string]int)
- func (s *SuggestionReport) AppendUnique(commentID string)
- func (s *SuggestionReport) AppendUniquePH(commentID string, params map[string]string)
- func (s *SuggestionReport) GetComments() ([]Comment, int)
- func (s *SuggestionReport) GetErrors() []error
- func (s *SuggestionReport) HasSuggestion(commentID string) bool
- func (s *SuggestionReport) ReportError(err error)
Constants ¶
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 ¶
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 ExamExtraVariable ¶
ExamExtraVariable checks for a variable that can be inlined
func IsMultiAssignment ¶
IsMultiAssignment declaration assigns to multiple variables
Types ¶
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 ¶
NewBlockComment creates a new block comment
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 ¶
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.