lint

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package lint provides code analysis functionality for Scriptling scripts. It can detect syntax errors and potential issues without executing the code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LintError

type LintError struct {
	// File is the source file name (may be empty for inline code).
	File string `json:"file,omitempty"`
	// Line is the 1-based line number where the issue was found.
	Line int `json:"line"`
	// Column is the 1-based column number (if available, 0 if not).
	Column int `json:"column,omitempty"`
	// Message is a human-readable description of the issue.
	Message string `json:"message"`
	// Severity indicates how serious the issue is.
	Severity Severity `json:"severity"`
	// Code is an optional error code for programmatic handling.
	Code string `json:"code,omitempty"`
}

LintError represents a single lint finding.

func (LintError) String

func (e LintError) String() string

String returns a formatted string representation of the lint error.

type Options

type Options struct {
	// Filename is used for error messages when linting inline code.
	Filename string
}

Options configures the behavior of the linter.

type Result

type Result struct {
	// Errors is the list of lint errors found.
	Errors []LintError `json:"errors"`
	// FilesChecked is the number of files that were linted.
	FilesChecked int `json:"files_checked"`
	// HasErrors is true if any errors with severity "error" were found.
	HasErrors bool `json:"has_errors"`
}

Result contains the results of linting one or more files.

func Lint

func Lint(source string, opts *Options) *Result

Lint analyzes Scriptling source code and returns any issues found. The code is parsed but not executed, making this safe for untrusted input.

Parameters:

  • source: The Scriptling source code to analyze
  • opts: Optional configuration (can be nil for defaults)

Returns a Result containing any issues found.

Example:

result := lint.Lint(`x = 1 + `, nil)
if result.HasIssues() {
    fmt.Println(result.String())
}

func LintFile

func LintFile(filename string) (*Result, error)

LintFile reads and analyzes a Scriptling file. This is a convenience wrapper around Lint that reads the file first.

Parameters:

  • filename: Path to the Scriptling file to analyze

Returns a Result containing any issues found, or an error if the file cannot be read.

Example:

result, err := lint.LintFile("script.py")
if err != nil {
    log.Fatal(err)
}
if result.HasErrors {
    fmt.Println(result.String())
    os.Exit(1)
}

func LintFiles

func LintFiles(filenames []string) (*Result, error)

LintFiles analyzes multiple Scriptling files. All files are linted even if some have errors.

Parameters:

  • filenames: Paths to the Scriptling files to analyze

Returns a combined Result containing all issues found.

Example:

result, err := lint.LintFiles([]string{"a.py", "b.py"})
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Checked %d files, found %d issues\n",
    result.FilesChecked, len(result.Errors))

func (Result) HasIssues

func (r Result) HasIssues() bool

HasIssues returns true if any lint errors were found.

func (Result) String

func (r Result) String() string

String returns a formatted summary of all lint errors.

type Severity

type Severity string

Severity represents the severity level of a lint error.

const (
	// SeverityError indicates a syntax error that prevents parsing.
	SeverityError Severity = "error"
	// SeverityWarning indicates a potential issue that doesn't prevent parsing.
	SeverityWarning Severity = "warning"
	// SeverityInfo indicates informational messages.
	SeverityInfo Severity = "info"
)

Jump to

Keyboard shortcuts

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