lint

package
v3.0.0-...-cfbdf18 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Src   string
	Path  string
	Name  string
	Lines []string
}

func NewFile

func NewFile(name, src string) *File

func Parse

func Parse(path string) (*ast.File, *File, error)

func (*File) LineOf

func (f *File) LineOf(pos token.Pos) int

LineOf computes which line a particular position within a file lands on.

This is not the greatest song in the world.
No, this is just a tribute.
Couldn't remember the greatest song in the world.
No, this is just a tribute!

The word "remember" begins at position 81 within this text, therefor LineOf(81) should return line 3.

type Lint

type Lint interface {
	Lint(tree *ast.File, file *File) *Result
	CheckApplies(tree *ast.File, file *File) bool
}

type Result

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

A Result encodes any unmet expectation laid out by your lint. It consists of a single message, a list of code citations, and a list of lint citations.

The message should be succinct and descriptive of the core issue. This message can only be set in the constructor, NewResult. For example...

"Go style guides suggest not using bare returns in complex functions"

Code citations are the locations within the file that did not meet your expectations. Please see AddCodeCitations for information on how to add these to the Result type. Adding a code citation will result in the file, line number and raw source code appearing in the lint result. For example...

File ../../lints/cabf_br/lint_cab_dv_conflicts_with_locality.go, line 28

func (l *certPolicyConflictsWithLocality) Initialize() error {
	return nil
}

The lint citations are additional information to help the contributor understand why their code failed this lint and, if possible, some hints or resources on how to correct the issue. Every citation will be listed on its own line.

func NewResult

func NewResult(message string) *Result

func RunLint

func RunLint(tree *ast.File, file *File, lint Lint) *Result

func RunLintForFile

func RunLintForFile(path string, lint Lint) (*Result, error)

func RunLints

func RunLints(path string, lints []Lint) ([]*Result, error)

func (*Result) AddCodeCitation

func (r *Result) AddCodeCitation(start, end token.Pos, file *File) *Result

AddCodeCitation takes the starting and ending position of a block of code within a file. Upon calling the String method, every code citation will be printed alongside the result. This code citation lists the file and line of the code in question as well as the raw block of source code.

For example:

File ../../lints/cabf_br/lint_cab_dv_conflicts_with_locality.go, line 28

func (l *certPolicyConflictsWithLocality) Initialize() error {
	return nil
}

func (*Result) SetCitations

func (r *Result) SetCitations(citations ...string) *Result

SetCitations sets a list of citations that users can reference in order to understand the error that they received. Upon calling the String method each citation will be listed on their on own line.

For example:

For more information, please see the following citations.
	https://github.com/zmap/zlint/issues/371
	https://golang.ir/doc/effective_go.html#init

The above links a GitHub issue that discuss the lint in question as well as a link to Golang's magic `init` method (because the lint in question is asking the contributor to implement `init` at a particular spot in the file).

func (*Result) String

func (r *Result) String() string

Jump to

Keyboard shortcuts

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