nolintlint

package
v1.45.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

README

nolintlint

nolintlint is a Go static analysis tool to find ill-formed or insufficiently explained // nolint directives for golangci (or any other linter, using th )

Purpose

To ensure that lint exceptions have explanations. Consider the case below:

import "crypto/md5" //nolint

func hash(data []byte) []byte {
	return md5.New().Sum(data) //nolint
}

In the above case, nolint directives are present but the user has no idea why this is being done or which linter is being suppressed (in this case, gosec recommends against use of md5). nolintlint can require that the code provide an explanation, which might look as follows:

import "crypto/md5" //nolint:gosec // this is not used in a secure application

func hash(data []byte) []byte {
	return md5.New().Sum(data) //nolint:gosec // this result is not used in a secure application
}

nolintlint can also identify cases where you may have written // nolint. Finally nolintlint, can also enforce that you use the machine-readable nolint directive format //nolint and that you mention what linter is being suppressed, as shown above when we write //nolint:gosec.

Documentation

Overview

Package nolintlint provides a linter to ensure that all //nolint directives are followed by explanations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseIssue

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

func (BaseIssue) Position

func (b BaseIssue) Position() token.Position

func (BaseIssue) Replacement

func (b BaseIssue) Replacement() *result.Replacement

type ExtraLeadingSpace

type ExtraLeadingSpace struct {
	BaseIssue
}

func (ExtraLeadingSpace) Details

func (i ExtraLeadingSpace) Details() string

func (ExtraLeadingSpace) String

func (i ExtraLeadingSpace) String() string

type Issue

type Issue interface {
	Details() string
	Position() token.Position
	String() string
	Replacement() *result.Replacement
}

type Linter

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

func NewLinter

func NewLinter(needs Needs, excludes []string) (*Linter, error)

NewLinter creates a linter that enforces that the provided directives fulfill the provided requirements

func (Linter) Run

func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error)

type Needs

type Needs uint
const (
	NeedsMachineOnly Needs = 1 << iota
	NeedsSpecific
	NeedsExplanation
	NeedsUnused
	NeedsAll = NeedsMachineOnly | NeedsSpecific | NeedsExplanation
)

type NoExplanation

type NoExplanation struct {
	BaseIssue
	// contains filtered or unexported fields
}

func (NoExplanation) Details

func (i NoExplanation) Details() string

func (NoExplanation) String

func (i NoExplanation) String() string

type NotMachine

type NotMachine struct {
	BaseIssue
}

func (NotMachine) Details

func (i NotMachine) Details() string

func (NotMachine) String

func (i NotMachine) String() string

type NotSpecific

type NotSpecific struct {
	BaseIssue
}

func (NotSpecific) Details

func (i NotSpecific) Details() string

func (NotSpecific) String

func (i NotSpecific) String() string

type ParseError

type ParseError struct {
	BaseIssue
}

func (ParseError) Details

func (i ParseError) Details() string

func (ParseError) String

func (i ParseError) String() string

type UnusedCandidate

type UnusedCandidate struct {
	BaseIssue
	ExpectedLinter string
}

func (UnusedCandidate) Details

func (i UnusedCandidate) Details() string

func (UnusedCandidate) String

func (i UnusedCandidate) String() string

Jump to

Keyboard shortcuts

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