plscheck

module
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: BSD-3-Clause

README

plscheck

Externalized versions of gopls internal analyzers from golang.org/x/tools/gopls/internal/analysis.

Purpose

This package allows you to run gopls analyzers in CI pipelines and other tooling outside of gopls itself. The analyzers in gopls are normally only available within the language server, but this package makes them available as standalone checkers.

Versioning

Tags in this repository always match upstream gopls releases. For example, v0.20.0 in this repository corresponds to gopls/v0.20.0 in golang.org/x/tools.

All dependencies (golang.org/x/tools and golang.org/x/tools/gopls) are pinned to the same version to ensure consistency.

Available Analyzers

  • deprecated - checks for usage of deprecated identifiers
  • embeddirective - validates //go:embed directives
  • errorsastypeshadow - reports shadowing of errors.AsType results in if/else chains
  • fillreturns - suggests fixes for incomplete return statements
  • infertypeargs - suggests removing unnecessary type arguments
  • maprange - suggests using maps.Keys/Values/All for map iteration
  • nonewvars - detects := assignments that don't introduce new variables
  • noresultvalues - checks for return statements with unexpected result values
  • recursiveiter - detects recursive iterator patterns that may cause issues
  • simplifycompositelit - simplifies composite literal types
  • simplifyrange - simplifies range statement expressions
  • simplifyslice - simplifies slice expressions
  • unusedfunc - finds unused functions
  • unusedparams - finds unused function parameters
  • unusedvariable - finds unused variables
  • writestring - detects inefficient string concatenation in WriteString calls
  • yield - checks yield function calls in iterator functions

As of v0.23.0 the modernize suite is no longer copied here: upstream promoted it to golang.org/x/tools/go/analysis/passes/modernize, so import it from there.

Usage

# Install
go install lesiw.io/plscheck/cmd/plscheck@latest

# Run all analyzers
plscheck ./...

# Run specific analyzers
plscheck -unusedparams -unusedvariable ./...

Limitations

Some gopls analyzers (fillstruct, fillswitch) are tightly coupled with gopls internals and are not included as they don't export standalone analyzers suitable for command-line use.

Directories

Path Synopsis
cmd
plscheck command
Package deprecated defines an Analyzer that marks deprecated symbols and package imports.
Package deprecated defines an Analyzer that marks deprecated symbols and package imports.
Package embeddirective defines an Analyzer that validates //go:embed directives.
Package embeddirective defines an Analyzer that validates //go:embed directives.
Package errorsastypeshadow checks for shadowing problems when errors.AsType is used in an if/else chain.
Package errorsastypeshadow checks for shadowing problems when errors.AsType is used in an if/else chain.
Package fillreturns defines an Analyzer that will attempt to automatically fill in a return statement that has missing values with zero value elements.
Package fillreturns defines an Analyzer that will attempt to automatically fill in a return statement that has missing values with zero value elements.
Package fillstruct defines an Analyzer that automatically fills in a struct declaration with zero value elements for each field.
Package fillstruct defines an Analyzer that automatically fills in a struct declaration with zero value elements for each field.
Package fillswitch identifies switches with missing cases.
Package fillswitch identifies switches with missing cases.
internal
fuzzy
Package fuzzy implements a fuzzy matching algorithm.
Package fuzzy implements a fuzzy matching algorithm.
util/cursorutil
Package cursorutil provides utility functions for working with inspector.Cursor.
Package cursorutil provides utility functions for working with inspector.Cursor.
util/safetoken
Package safetoken provides wrappers around methods in go/token, that return errors rather than panicking.
Package safetoken provides wrappers around methods in go/token, that return errors rather than panicking.
xtools/analysis/analyzerutil
Package analyzerutil provides implementation helpers for analyzers.
Package analyzerutil provides implementation helpers for analyzers.
xtools/analysis/typeindex
Package typeindex defines an analyzer that provides a lesiw.io/plscheck/internal/xtools/typesinternal/typeindex.Index.
Package typeindex defines an analyzer that provides a lesiw.io/plscheck/internal/xtools/typesinternal/typeindex.Index.
xtools/astutil
Package astutil provides various AST utility functions for gopls.
Package astutil provides various AST utility functions for gopls.
xtools/flow
Package flow implements a monotone flow analysis framework.
Package flow implements a monotone flow analysis framework.
xtools/graph
Package graph provides a common abstraction for directed graphs and standard graph algorithms.
Package graph provides a common abstraction for directed graphs and standard graph algorithms.
xtools/packagepath
Package packagepath provides metadata operations on package path strings.
Package packagepath provides metadata operations on package path strings.
xtools/refactor
Package refactor provides operators to compute common textual edits for refactoring tools.
Package refactor provides operators to compute common textual edits for refactoring tools.
xtools/stdlib
Package stdlib provides a table of all exported symbols in the standard library, along with the version at which they first appeared.
Package stdlib provides a table of all exported symbols in the standard library, along with the version at which they first appeared.
xtools/typeparams
Package typeparams contains common utilities for writing tools that interact with generic Go code, as introduced with Go 1.18.
Package typeparams contains common utilities for writing tools that interact with generic Go code, as introduced with Go 1.18.
xtools/typesinternal
Package typesinternal provides helpful operators for dealing with go/types:
Package typesinternal provides helpful operators for dealing with go/types:
xtools/typesinternal/typeindex
Package typeindex provides an Index of type information for a package, allowing efficient lookup of, say, whether a given symbol is referenced and, if so, where from; or of the inspector.Cursor for the declaration of a particular types.Object symbol.
Package typeindex provides an Index of type information for a package, allowing efficient lookup of, say, whether a given symbol is referenced and, if so, where from; or of the inspector.Cursor for the declaration of a particular types.Object symbol.
Package maprange defines an Analyzer that checks for redundant use of the functions maps.Keys and maps.Values in "for" statements with "range" clauses.
Package maprange defines an Analyzer that checks for redundant use of the functions maps.Keys and maps.Values in "for" statements with "range" clauses.
cmd/maprange command
The maprange command applies the lesiw.io/plscheck/maprange analysis to the specified packages of Go source code.
The maprange command applies the lesiw.io/plscheck/maprange analysis to the specified packages of Go source code.
Package nonewvars defines an Analyzer that applies suggested fixes to errors of the type "no new variables on left side of :=".
Package nonewvars defines an Analyzer that applies suggested fixes to errors of the type "no new variables on left side of :=".
Package noresultvalues defines an Analyzer that applies suggested fixes to errors of the type "no result values expected".
Package noresultvalues defines an Analyzer that applies suggested fixes to errors of the type "no result values expected".
Package recursiveiter defines an Analyzer that checks for mistakes in iterators for recursive data structures.
Package recursiveiter defines an Analyzer that checks for mistakes in iterators for recursive data structures.
Package simplifycompositelit defines an Analyzer that simplifies composite literals.
Package simplifycompositelit defines an Analyzer that simplifies composite literals.
Package simplifyrange defines an Analyzer that simplifies range statements.
Package simplifyrange defines an Analyzer that simplifies range statements.
Package simplifyslice defines an Analyzer that simplifies slice statements.
Package simplifyslice defines an Analyzer that simplifies slice statements.
Package unusedfunc defines an analyzer that checks for unused functions and methods
Package unusedfunc defines an analyzer that checks for unused functions and methods
Package unusedparams defines an analyzer that checks for unused parameters of functions.
Package unusedparams defines an analyzer that checks for unused parameters of functions.
cmd command
The unusedparams command runs the unusedparams analyzer.
The unusedparams command runs the unusedparams analyzer.
Package unusedvariable defines an analyzer that checks for unused variables.
Package unusedvariable defines an analyzer that checks for unused variables.
Package writestring defines an Analyzer that detects inefficient string concatenation in uses of WriteString.
Package writestring defines an Analyzer that detects inefficient string concatenation in uses of WriteString.
Package yield defines an Analyzer that checks for mistakes related to the yield function used in iterators.
Package yield defines an Analyzer that checks for mistakes related to the yield function used in iterators.

Jump to

Keyboard shortcuts

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