Skip to content

Uncommented nolintlint, now comment is a must while adding a nolint directive. #1215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ linters:
- nilnil
- nlreturn
- noctx
# - nolintlint
- nolintlint
- nosprintfhostport
- perfsprint
- prealloc
Expand All @@ -66,7 +66,7 @@ linters:
- zerologlint
settings:
cyclop:
max-complexity: 10
max-complexity: 12
package-average: 0
errorlint:
errorf: true
Expand Down Expand Up @@ -217,19 +217,19 @@ linters:
- chan
nlreturn:
block-size: 2
# nolintlint:
# # Disable to ensure that all nolint directives actually have an effect.
# # Default: false
# allow-unused: true
# # Exclude following linters from requiring an explanation.
# # Default: []
# allow-no-explanation: [ ]
# # Enable to require an explanation of nonzero length after each nolint directive.
# # Default: false
# require-explanation: true
# # Enable to require nolint directives to mention the specific linter being suppressed.
# # Default: false
# require-specific: true
nolintlint:
# Disable to ensure that all nolint directives actually have an effect.
# Default: false
allow-unused: true
# Exclude following linters from requiring an explanation.
# Default: []
allow-no-explanation: [ ]
# Enable to require an explanation of nonzero length after each nolint directive.
# Default: false
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed.
# Default: false
require-specific: true
prealloc:
simple: true
range-loops: true
Expand Down Expand Up @@ -286,7 +286,7 @@ linters:
disabled: false
- name: cognitive-complexity
arguments:
- 10
- 12
severity: warning
disabled: false
- name: comment-spacings
Expand All @@ -311,7 +311,7 @@ linters:
disabled: false
- name: cyclomatic
arguments:
- 10
- 12
severity: warning
disabled: false
- name: datarace
Expand Down
2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/command.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/grpc/mpi/v1/files.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions internal/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func WaitUntil(

// WaitUntilWithData Implementation of backoff operations that increases the back off period for each retry
// attempt using a randomization function that grows exponentially. This does not allow for parameters.
// nolint: ireturn
//
//nolint:ireturn // must return an interface
func WaitUntilWithData[T any](
ctx context.Context,
backoffSettings *config.BackOff,
Expand All @@ -76,7 +77,7 @@ func WaitUntilWithData[T any](
return backoff.RetryWithData(operation, backoffWithContext)
}

// nolint: ireturn
//nolint:ireturn // must return an interface
func Context(ctx context.Context, backoffSettings *config.BackOff) backoff.BackOffContext {
eb := backoff.NewExponentialBackOff()
eb.InitialInterval = backoffSettings.InitialInterval
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/containermetricsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/nginx/agent/v3/internal/collector/containermetricsreceiver/internal/metadata"
)

// nolint: ireturn
//nolint:ireturn // must return metrics interface
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
Expand All @@ -33,7 +33,7 @@ func NewFactory() receiver.Factory {
)
}

// nolint: ireturn
//nolint:ireturn // must return metrics interface
func createMetricsReceiver(
_ context.Context,
params receiver.Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Config struct {
scraperhelper.ControllerConfig `mapstructure:",squash"`
}

// nolint: ireturn
//nolint:ireturn // must return a default metrics controller interface
func CreateDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
return &Config{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (
"go.opentelemetry.io/collector/scraper"
)

// NewFactory for CPU scraper.
// nolint: ireturn
//nolint:ireturn // must return a CPU scraper interface.
func NewFactory() scraper.Factory {
return scraper.NewFactory(
metadata.Type,
Expand All @@ -25,16 +24,14 @@ func NewFactory() scraper.Factory {
)
}

// createDefaultConfig creates the default configuration for the Scraper.
// nolint: ireturn
//nolint:ireturn // must create the default configuration for the Scraper.
func createDefaultConfig() component.Config {
return &Config{
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}

// createMetricsScraper creates a scraper based on provided config.
// nolint: ireturn
//nolint:ireturn // must create and return a scraper based on provided config.
func createMetricsScraper(
ctx context.Context,
settings scraper.Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func (cs *CPUSource) Collect() (ContainerCPUStats, error) {
return cpuStats, nil
}

// nolint: mnd
func (cs *CPUSource) collectCPUStats() (ContainerCPUStats, error) {
clockTicks, err := clockTicks()
const nanosecondsPerMillisecond = 1000
if err != nil {
return ContainerCPUStats{}, err
}
Expand All @@ -84,7 +84,7 @@ func (cs *CPUSource) collectCPUStats() (ContainerCPUStats, error) {
userKey := V2UserKey
sysKey := V2SystemKey
convertUsage := func(usage float64) float64 {
return usage * 1000
return usage * nanosecondsPerMillisecond
}

if !cs.isCgroupV2 { // cgroup v1
Expand Down Expand Up @@ -161,7 +161,7 @@ func (cs *CPUSource) cpuUsageTimes(filePath, userKey, systemKey string) (*Contai
return cpuTimes, nil
}

// nolint: revive, gocritic
//nolint:revive // cognitive complexity is 14
func systemCPUUsage(clockTicks int) (float64, error) {
lines, err := internal.ReadLines(CPUStatsPath)
if err != nil {
Expand All @@ -170,8 +170,7 @@ func systemCPUUsage(clockTicks int) (float64, error) {

for _, line := range lines {
parts := strings.Fields(line)
switch parts[0] {
case "cpu":
if parts[0] == "cpu" {
if len(parts) < CPUStatsFileLineLength {
return 0, errors.New("unable to process " + CPUStatsPath + ". Invalid number of fields for cpu line")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
)

// NewFactory for CPU scraper.
// nolint: ireturn
//
//nolint:ireturn // must return a CPU scraper
func NewFactory() scraper.Factory {
return scraper.NewFactory(
metadata.Type,
Expand All @@ -26,15 +27,17 @@ func NewFactory() scraper.Factory {
}

// createDefaultConfig creates the default configuration for the Scraper.
// nolint: ireturn
//
//nolint:ireturn // must return a default configuration for scraper
func createDefaultConfig() component.Config {
return &Config{
MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
}
}

// createMetricsScraper creates a scraper based on provided config.
// nolint: ireturn
//
//nolint:ireturn // must return a metric scraper interface
func createMetricsScraper(
ctx context.Context,
settings scraper.Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (ms *MemorySource) Collect() {
}
}

// nolint: unparam
func (ms *MemorySource) VirtualMemoryStatWithContext(ctx context.Context) (*mem.VirtualMemoryStat, error) {
var cgroupStat mem.VirtualMemoryStat
var memoryStat MemoryStat
Expand Down Expand Up @@ -146,16 +145,16 @@ func MemoryLimitInBytes(ctx context.Context, filePath string) (uint64, error) {
return strconv.ParseUint(memTotalString, 10, 64)
}

// nolint: revive, mnd
func CalculateMemoryStat(statFile, cachedKey, sharedKey string) (MemoryStat, error) {
const requiredFields = 2
memoryStat := MemoryStat{}
lines, err := internal.ReadLines(statFile)
if err != nil {
return memoryStat, err
}
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) != 2 {
if len(fields) != requiredFields {
return memoryStat, fmt.Errorf("%+v required 2 fields", fields)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ReadLines(filename string) ([]string, error) {
return ReadLinesOffsetN(filename, 0, -1)
}

// nolint: revive
//nolint:revive // cognitive complexity is 16
func ReadLinesOffsetN(filename string, offset uint, n int) (lines []string, err error) {
f, err := os.Open(filename)
defer func() {
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/logsgzipprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"go.uber.org/zap"
)

// nolint: ireturn
//nolint:ireturn // must return factory processor interface for collector
func NewFactory() processor.Factory {
return processor.NewFactory(
component.MustNewType("logsgzip"),
Expand All @@ -32,7 +32,7 @@ func NewFactory() processor.Factory {
)
}

// nolint: ireturn
//nolint:ireturn // returns a zip processor interface
func createLogsGzipProcessor(_ context.Context,
settings processor.Settings,
cfg component.Config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func BenchmarkGzipProcessor(b *testing.B) {

// Optional: Benchmark with concurrency to simulate real pipeline load
func BenchmarkGzipProcessor_Concurrent(b *testing.B) {
// nolint:unused // concurrent runs require total parallel workers to be specified
//nolint: unused // concurrent runs require total parallel workers to be specified
const workers = 8
logs := generateLogs(1000, 1000)
consumer := &consumertest.LogsSink{}
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/logsgzipprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestGzipProcessorFailure(t *testing.T) {
}
}

// nolint: revive
//nolint:revive // isGzipWriteErr flag is mandatory
func customMockWriter(isGzipWriteErr, isGzipCloseErr bool) *mockGzipWriter {
return &mockGzipWriter{
WriteFunc: func(p []byte) (int, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/nginxossreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"go.opentelemetry.io/collector/scraper/scraperhelper"
)

// nolint: ireturn
//nolint:ireturn // return a factory interface
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
Expand All @@ -30,7 +30,7 @@ func NewFactory() receiver.Factory {
)
}

// nolint: ireturn
//nolint:ireturn // returns a metric interface which is required
func createMetrics(
_ context.Context,
params receiver.Settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type AccessLog struct {
FilePath string `mapstructure:"file_path"`
}

// nolint: ireturn
//nolint:ireturn // Return default interface required by Collector
func CreateDefaultConfig() component.Config {
cfg := scraperhelper.NewDefaultControllerConfig()
cfg.CollectionInterval = defaultCollectInterval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (nls *NginxLogScraper) ID() component.ID {
return component.NewID(metadata.Type)
}

// nolint: unparam
//nolint:unparam //// Result is always nil
func (nls *NginxLogScraper) Start(parentCtx context.Context, _ component.Host) error {
nls.logger.Info("NGINX access log scraper started")
ctx, cancel := context.WithCancel(parentCtx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func TestAccessLogScraper(t *testing.T) {
// Copies the contents of one file to another with the given delay. Used to simulate writing log entries to a log file.
// Reason for nolint: we must use testify's assert instead of require,
// for more info see https://github.com/stretchr/testify/issues/772#issuecomment-945166599
// nolint: testifylint
//
//nolint:testifylint // we must use testify's assert instead of require
func simulateLogging(t *testing.T, sourcePath, destinationPath string, writeDelay time.Duration) {
t.Helper()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func NewConfigWithID(operatorID string) *Config {
}

// Build will build a file input operator from the supplied configuration
// nolint: ireturn
//
//nolint:ireturn // The function returns a specific interface type as required by the OpenTelemetry Collector framework.
func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error) {
logger := set.Logger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.uber.org/zap"
)

// nolint: lll
//nolint:lll // this needs to be in one line
const (
accessLogPattern = `$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"`
accessLogLine = "127.0.0.1 - - [19/May/2022:09:30:39 +0000] \"GET /nginx_status HTTP/1.1\" 200 98 \"-\" \"Go-http-client/1.1\" \"-\"\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
//nolint: gocritic
//nolint:gocritic // this is required for request key
formatVariables = map[string]string{
"$remote_addr": "%{IPORHOST:remote_addr}",
"$remote_user": "%{USERNAME:remote_user}",
Expand Down
Loading