shellcheck

package
v0.1.0-dev.20260908061627 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package shellcheck provides shell script analysis operations for the operation graph.

Index

Constants

View Source
const (
	Complexity op.ActionName = "shellcheck.complexity"
	Format     op.ActionName = "shellcheck.format"
	Lint       op.ActionName = "shellcheck.lint"
	Parse      op.ActionName = "shellcheck.parse"
)

Action-name constants for the shellcheck provider's plan-mode actions.

Each constant is the short dotted action label its method dispatches under. Pass these to plan.Plan, op.ReceiverRegistry().BuildAction, RuntimeEnvironment.ActionByName, or WithActionNamed in place of a string literal so a typo is a compile error and rename / find-references work through the constant.

Variables

This section is empty.

Functions

func CollectShellFiles

func CollectShellFiles(path string) ([]string, error)

CollectShellFiles returns all shell files in a path.

Types

type ComplexityFile

type ComplexityFile struct {
	Path          string               `starlark:"path"`
	Functions     []FunctionComplexity `starlark:"functions"`
	TotalCyclo    int                  `starlark:"total_cyclo"`
	FunctionCount int                  `starlark:"function_count"`
}

ComplexityFile holds complexity metrics for a single shell file.

type ComplexityResult

type ComplexityResult struct {
	Files           []ComplexityFile `starlark:"files"`
	TotalCyclomatic int              `starlark:"total_cyclomatic"`
	TotalFunctions  int              `starlark:"total_functions"`
	AvgCyclomatic   float64          `starlark:"avg_cyclomatic"`
	MaxCyclomatic   int              `starlark:"max_cyclomatic"`
	MaxCycloFunc    string           `starlark:"max_cyclo_func"`
	Hotspots        []Hotspot        `starlark:"hotspots"`
}

ComplexityResult holds complexity metrics for shell scripts.

type FormatCheckResult

type FormatCheckResult struct {
	Passed       bool               `starlark:"passed"`
	FilesChecked int                `starlark:"files_checked"`
	FilesFailed  []FormatFailedFile `starlark:"files_failed"`
}

FormatCheckResult holds the outcome of a shfmt check (fix=false).

type FormatFailedFile

type FormatFailedFile struct {
	File string `starlark:"file"`
	Diff string `starlark:"diff"`
}

FormatFailedFile represents a file that failed formatting check.

type FormatFixResult

type FormatFixResult struct {
	FilesChecked   int `starlark:"files_checked"`
	FilesFormatted int `starlark:"files_formatted"`
}

FormatFixResult holds the outcome of a shfmt fix (fix=true).

type FunctionComplexity

type FunctionComplexity struct {
	Name          string `starlark:"name"`
	Line          int    `starlark:"line"`
	Cyclomatic    int    `starlark:"cyclomatic"`
	NestingDepth  int    `starlark:"nesting_depth"`
	LOC           int    `starlark:"loc"`
	ParameterRefs int    `starlark:"parameter_refs"`
}

FunctionComplexity holds complexity metrics for a single function.

type Hotspot

type Hotspot struct {
	Name         string `starlark:"name"`
	File         string `starlark:"file"`
	Line         int    `starlark:"line"`
	Cyclomatic   int    `starlark:"cyclomatic"`
	NestingDepth int    `starlark:"nesting_depth"`
	LOC          int    `starlark:"loc"`
}

Hotspot represents a function exceeding complexity thresholds.

type LintIssue

type LintIssue struct {
	File      string `json:"file"      starlark:"file"`
	Line      int    `json:"line"      starlark:"line"`
	EndLine   int    `json:"endLine"   starlark:"end_line"`
	Column    int    `json:"column"    starlark:"column"`
	EndColumn int    `json:"endColumn" starlark:"end_column"`
	Level     string `json:"level"     starlark:"level"`
	Code      int    `json:"code"      starlark:"code"`
	Message   string `json:"message"   starlark:"message"`
}

LintIssue represents a single shellcheck finding.

type LintResult

type LintResult struct {
	Issues       []LintIssue `starlark:"issues"`
	ErrorCount   int         `starlark:"error_count"`
	WarningCount int         `starlark:"warning_count"`
	InfoCount    int         `starlark:"info_count"`
	StyleCount   int         `starlark:"style_count"`
	TotalCount   int         `starlark:"total_count"`
	Passed       bool        `starlark:"passed"`
}

LintResult holds the outcome of a shellcheck lint run.

type ParseResult

type ParseResult struct {
	Files          []ParsedFile `starlark:"files"`
	TotalFunctions int          `starlark:"total_functions"`
	TotalVariables int          `starlark:"total_variables"`
	TotalLOC       int          `starlark:"total_loc"`
	TotalSLOC      int          `starlark:"total_sloc"`
}

ParseResult holds the parsed structure of shell scripts.

type ParsedFile

type ParsedFile struct {
	Path      string          `starlark:"path"`
	Functions []ShellFunction `starlark:"functions"`
	Variables []ShellVariable `starlark:"variables"`
	Commands  []string        `starlark:"commands"`
	Sources   []string        `starlark:"sources"`
	LOC       int             `starlark:"loc"`
	SLOC      int             `starlark:"sloc"`
	Comments  int             `starlark:"comments"`
	Blanks    int             `starlark:"blanks"`
}

ParsedFile holds the parsed structure of a single shell script.

type Provider

type Provider struct {
	op.ProviderBase
}

Provider provides shell script analysis operations: lint (shellcheck), format (shfmt), parse (structural extraction), and complexity (cyclomatic metrics).

func NewProvider

func NewProvider(ctx *op.RuntimeEnvironment) *Provider

NewProvider creates a shellcheck provider bound to the given context.

func (*Provider) Complexity

func (p *Provider) Complexity(path string) (ComplexityResult, error)

Complexity calculates complexity metrics for shell scripts.

Parameters:

  • `path`: file or directory to analyze

Returns:

  • `ComplexityResult`: per-function cyclomatic complexity, nesting, and hotspots
  • `error`: if path is invalid

func (*Provider) Format

func (p *Provider) Format(path string, indent int, fix bool) (any, error)

Format checks or fixes shell script formatting using shfmt.

+devlore:defaults indent=0,fix=false

Parameters:

  • `path`: file or directory to check/format
  • `indent`: indentation width (defaults to 4 when 0)
  • `fix`: if true, rewrite files in place; if false, check only

Returns:

  • `any`: FormatCheckResult (fix=false) or FormatFixResult (fix=true)
  • `error`: if shfmt is not installed or path is invalid

func (*Provider) Lint

func (p *Provider) Lint(path, severity string) (LintResult, error)

Lint runs shellcheck on shell scripts and returns structured issues.

+devlore:defaults severity="warning"

Parameters:

  • `path`: file or directory to lint
  • `severity`: minimum severity level (error, warning, info, style)

Returns:

  • `LintResult`: issues grouped by severity with pass/fail
  • `error`: if shellcheck is not installed or path is invalid

func (*Provider) Parse

func (p *Provider) Parse(path string) (ParseResult, error)

Parse parses shell scripts and extracts structural information.

Parameters:

  • `path`: file or directory to parse

Returns:

  • `ParseResult`: functions, variables, commands, sources, and line counts
  • `error`: if path is invalid

type ShellFunction

type ShellFunction struct {
	Name      string `starlark:"name"`
	Line      int    `starlark:"line"`
	EndLine   int    `starlark:"end_line"`
	BodyLines int    `starlark:"body_lines"`
}

ShellFunction represents a function defined in a shell script.

type ShellVariable

type ShellVariable struct {
	Name  string `starlark:"name"`
	Line  int    `starlark:"line"`
	Value string `starlark:"value"`
}

ShellVariable represents a variable assignment in a shell script.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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