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.
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 ¶
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 ¶
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 ¶
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))
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" )