util

package
v1.1.0-beta.0...-0be1983 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Directives = &analysis.Analyzer{
	Name:             "directives",
	Doc:              "extracts linter directives",
	Run:              doDirectives,
	RunDespiteErrors: true,
	ResultType:       reflect.TypeOf([]Directive{}),
}

Directives is a fact that contains a list of directives.

Functions

func FindOffset

func FindOffset(fileText string, line, column int) int

FindOffset returns the offset of a given position in a file.

func FormatCode

func FormatCode(code string) string

FormatCode is to format code for nogo.

func GetPackageName

func GetPackageName(imports []*ast.ImportSpec, path, defaultName string) string

GetPackageName returns the package name used in this file.

func MakeFakeLoaderPackageInfo

func MakeFakeLoaderPackageInfo(pass *analysis.Pass) *loader.PackageInfo

MakeFakeLoaderPackageInfo creates a fake loader.PackageInfo for a given package.

func ReadFile

func ReadFile(fset *token.FileSet, filename string) ([]byte, *token.File, error)

ReadFile reads a file and adds it to the FileSet so that we can report errors against it using lineStart.

func SkipAnalyzer

func SkipAnalyzer(analyzer *analysis.Analyzer)

SkipAnalyzer updates an analyzer from `staticcheck` and `golangci-linter` to make it work on nogo. They have "lint:ignore" or "nolint" to make the analyzer ignore the code.

func SkipAnalyzerByConfig

func SkipAnalyzerByConfig(analyzer *analysis.Analyzer)

SkipAnalyzerByConfig updates an analyzer to skip files according to `exclude_files`

Types

type Directive

type Directive struct {
	Command   skipType
	Linters   []string
	Directive *ast.Comment
	Node      ast.Node
}

Directive is a comment of the form '//lint:<command> [arguments...]' and `//nolint:<command>`. It represents instructions to the static analysis tool.

func ParseDirectives

func ParseDirectives(files []*ast.File, fset *token.FileSet) []Directive

ParseDirectives extracts all directives from a list of Go files.

Jump to

Keyboard shortcuts

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