internal

package
v1.64.8 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

README

nolintlint

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

Purpose

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

import "crypto/md5" //nolint:all

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

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:all and that you mention what linter is being suppressed, as shown above when we write //nolint:gosec.

Documentation

Overview

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

Index

Constants

View Source
const LinterName = "nolintlint"

Variables

This section is empty.

Functions

This section is empty.

Types

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(pass *analysis.Pass) ([]goanalysis.Issue, error)

type Needs

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

Jump to

Keyboard shortcuts

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