Skip to content

negative add-constant report when expr is not **ast.Ident** #1007

Closed
@lsytj0413

Description

@lsytj0413

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. I updated revive go install github.com/mgechev/revive@latest
  2. I run it with the following flags & configuration file:
package main

import (
	"context"
	"log/slog"
)

func main() {
	slog.Default().InfoContext(context.Background(), "key1")
	slog.Default().InfoContext(context.Background(), "key1")
	slog.Default().InfoContext(context.Background(), "key1")
	slog.Default().InfoContext(context.Background(), "key1")

	slog.InfoContext(context.Background(), "key2")
	slog.InfoContext(context.Background(), "key2")
	slog.InfoContext(context.Background(), "key2")
	slog.InfoContext(context.Background(), "key2")
}
# flags
golangci-lint run
linters:
  enable:
    - revive

linters-settings:
  revive:
    enable-all-rules: true
    rules:
      - name: add-constant
        severity: warning
        disabled: false
        arguments:
          - maxLitCount: "3"
            ignoreFuncs: 'slog\.*,fmt\.*,InfoContext\.*'

Expected behavior
A clear and concise description of what you expected to happen.

It didn't report "key1" for add-constant.

Logs
If applicable, add screenshots to help explain your problem.

main.go:12:51: add-constant: string literal "key1" appears, at least, 4 times, create a named constant for it (revive)
        slog.Default().InfoContext(context.Background(), "key1")

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 18.04]
  • Version of Go
    go version go1.22.2 darwin/arm64
    golangci-lint has version v1.59.0 built with go1.22.2 from (unknown, modified: ?, mod sum: "h1:st69YDnAH/v2QXDcgUaZ0seQajHScPALBVkyitYLXEk=") on (unknown)

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions