rulesets

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rulesets handles loading, parsing, and merging of Telescope ruleset definitions.

A ruleset controls which rules are enabled, their severity levels, and any custom Spectral rules. Rulesets can extend other rulesets and override individual rule settings.

Built-in Rulesets

Telescope ships with four built-in rulesets accessible via GetBuiltin:

  • telescope:recommended — ~35 commonly useful rules
  • telescope:all — all available rules (~65+)
  • telescope:owasp — security-focused rules
  • telescope:strict — recommended + stricter OWASP enforcement

Loading Custom Rulesets

Custom rulesets are YAML files compatible with Spectral's format:

rs, err := rulesets.LoadFile("my-rules.yaml")

Or from bytes:

rs, err := rulesets.LoadBytes(yamlData)

Severity

ParseSeverity converts severity strings ("error", "warn", "info", "hint", "off") to LSP DiagnosticSeverity values.

Package rulesets provides Spectral/vacuum-compatible ruleset loading, resolution, and merging. Rulesets define which rules are enabled and their severity overrides.

Index

Constants

View Source
const (
	Recommended = "telescope:recommended"
	All         = "telescope:all"
	OWASP       = "telescope:owasp"
	Strict      = "telescope:strict"
)

Built-in ruleset names.

View Source
const SpectralOAS = "spectral:oas"

SpectralOAS is the name of the Spectral OpenAPI built-in ruleset.

Variables

This section is empty.

Functions

func BuildEnabledMap

func BuildEnabledMap(rs *RuleSet) map[string]bool

BuildEnabledMap converts a resolved ruleset into a map of rule ID -> enabled.

func IsNativeRule

func IsNativeRule(spectralID string) bool

IsNativeRule reports whether the given Spectral rule ID has a native Telescope implementation.

func NormalizeRuleID

func NormalizeRuleID(id string) string

NormalizeRuleID resolves deprecated aliases and returns the canonical rule ID. The mapping is owned by barrelman/rulesets/bridge; this wrapper exists so existing telescope call sites can be migrated gradually.

func ParseSeverity

func ParseSeverity(s string) (ctypes.Severity, bool)

ParseSeverity converts a severity string to a core Severity.

func SpectralToTelescopeID

func SpectralToTelescopeID(spectralID string) string

SpectralToTelescopeID returns the native Telescope rule ID for a Spectral OAS rule, or the original ID if no mapping exists.

func TelescopeToSpectralID

func TelescopeToSpectralID(telescopeID string) string

TelescopeToSpectralID returns the Spectral OAS rule ID for a native Telescope rule, or the original ID if no mapping exists.

Types

type RuleDefinition

type RuleDefinition struct {
	Severity    string                 `yaml:"severity,omitempty"`
	Description string                 `yaml:"description,omitempty"`
	Message     string                 `yaml:"message,omitempty"`
	Given       interface{}            `yaml:"given,omitempty"`
	Then        interface{}            `yaml:"then,omitempty"`
	Formats     []string               `yaml:"formats,omitempty"`
	Recommended *bool                  `yaml:"recommended,omitempty"`
	Options     map[string]interface{} `yaml:"options,omitempty"`
}

RuleDefinition defines a rule override within a ruleset. It supports both the full object form and Spectral's shorthand where the value is just a severity string (e.g., `rule-id: error`).

func (*RuleDefinition) UnmarshalYAML

func (rd *RuleDefinition) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML handles Spectral shorthand syntax where a rule value can be:

  • a string: "error", "warn", "info", "hint", "off"
  • a boolean: false (same as "off")
  • an integer: severity code (0=off, 1=error, 2=warn, 3=info, 4=hint)
  • an array: [severity, {options}] (e.g., ["error", {"functionOptions": {...}}])
  • a map: full rule definition object

type RuleSet

type RuleSet struct {
	Name        string                    `yaml:"name,omitempty"`
	Description string                    `yaml:"description,omitempty"`
	Extends     interface{}               `yaml:"extends,omitempty"`
	Rules       map[string]RuleDefinition `yaml:"rules,omitempty"`
}

RuleSet is a loaded ruleset that controls which rules are enabled and their severity settings.

func GetBuiltin

func GetBuiltin(name string) *RuleSet

GetBuiltin returns a resolved ruleset by its built-in name.

func GetSpectralBuiltin

func GetSpectralBuiltin(name string) *RuleSet

GetSpectralBuiltin returns a RuleSet for the given Spectral built-in name. Currently only "spectral:oas" is supported.

func LoadBytes

func LoadBytes(data []byte) (*RuleSet, error)

LoadBytes parses a ruleset from YAML bytes.

func LoadFile

func LoadFile(path string) (*RuleSet, error)

LoadFile loads a ruleset from a YAML file.

func Merge

func Merge(rulesets ...*RuleSet) *RuleSet

Merge combines multiple rulesets, with later rulesets taking priority.

func Resolve

func Resolve(rs *RuleSet, basePath string) (*RuleSet, error)

Resolve fully resolves a ruleset including its extends chain.

type SeverityOverride

type SeverityOverride struct {
	RuleID   string
	Severity ctypes.Severity
	Disabled bool
}

SeverityOverride maps rule IDs to their overridden severity.

func BuildSeverityOverrides

func BuildSeverityOverrides(rs *RuleSet) []SeverityOverride

BuildSeverityOverrides extracts severity overrides from a resolved ruleset.

Jump to

Keyboard shortcuts

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