useq

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

useq

useq is a custom Go analyzer that detects usages of \"%s\" in formatting arguments and suggests using %q instead.

Using it with golangci-lint

Note: v1.1.0 can be used as module plugin, later version will be added as public linters in golangci-lint.

useq can be used with golangci-lint with the module plugin system.

Here's the .custom-gcl.yml:

version: v1.60.1
plugins:
  - module: 'github.com/dhaus67/useq'
    import: 'github.com/dhaus67/useq'
    version: latest

Here's a configuration of useq in .golangci.yml:

linters-settings:
  custom:
    useq:
      type: "module"
      description: "Detects usages of `\"%s\"` in `fmt.Sprintf` calls and suggests using `%q` instead."
      settings:
        functions:
          # A list of functions to validate. The function name needs to be the full qualified name (including potential pointers).
          # By default, `useq` validates fmt and github.com/pkg/errors functions.
          #- github.com/custom/package.MyPrintf              # exported package level function.
          #- (github.com/custom/package.MyStruct).MyPrintf   # exported method of a struct.
          #- (*github.com/custom/package.MyStruct).MyPrintf  # exported method of a struct with a pointer receiver.
linters:
  disable-all: true
  enable:
    - useq

Using it standalone

useq can also be used as a standalone tool. Here's how to install it:

go install github.com/dhaus67/useq/cmd/useq@latest

You can define a config file with your custom functions you want to validate as well:

{
  "functions": [
    "github.com/custom/package.MyPrintf",              # exported package level function.
    "(github.com/custom/package.MyStruct).MyPrintf",   # exported method of a struct.
    "(*github.com/custom/package.MyStruct).MyPrintf"   # exported method of a struct with a pointer receiver.
  ]
}

And pass it as a flag to the linter:

useq -config=path/to/config/file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnalyzer added in v1.2.2

func NewAnalyzer(settings Settings) (*analysis.Analyzer, error)

NewAnalyzer creates a new analyzer with the given settings.

Types

type Settings

type Settings struct {
	// The functions are fully qualified function names including the package (e.g. fmt.Printf).
	Functions []string `json:"functions"`
	// FunctionsPerPackage is a map of package names to the functions that should be checked.
	FunctionsPerPackage functionsPerPackage
}

Settings holds all the settings for the UseqAnalyzer.

func ReadSettingsFromFile added in v1.3.1

func ReadSettingsFromFile(f string) (Settings, error)

ReadSettingsFromFile reads the settings from the given path.

type UseqAnalyzer

type UseqAnalyzer struct {
	Analyzer *analysis.Analyzer
	// contains filtered or unexported fields
}

UseqAnalyzer is the main struct for the linter plugin.

func (*UseqAnalyzer) Compile added in v1.2.0

func (u *UseqAnalyzer) Compile() error

Compile will compile the settings for the analyzer.

Directories

Path Synopsis
cmd
useq command

Jump to

Keyboard shortcuts

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