config

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package config provides configuration file support for api-style-spec.

Configuration files are loaded from multiple locations in priority order:

  1. Explicit path via --config flag
  2. .api-style.yaml in current directory
  3. .api-style.yml in current directory
  4. api-style.yaml in current directory

Index

Constants

This section is empty.

Variables

View Source
var ConfigFileNames = []string{
	".api-style.yaml",
	".api-style.yml",
	"api-style.yaml",
	"api-style.yml",
	".api-style.json",
	"api-style.json",
}

ConfigFileNames are the supported config file names in priority order.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Profile is the style profile to use for linting.
	Profile string `yaml:"profile" json:"profile"`

	// Level is the target conformance level (bronze, silver, gold).
	Level string `yaml:"level" json:"level"`

	// Exceptions defines rule exceptions for this project.
	Exceptions []ExceptionConfig `yaml:"exceptions" json:"exceptions"`

	// SeverityOverrides allows changing rule severities.
	// Map of rule ID to severity (error, warn, info, hint).
	SeverityOverrides map[string]string `yaml:"severity-overrides" json:"severityOverrides"`

	// Include defines file patterns to include in linting.
	Include []string `yaml:"include" json:"include"`

	// Exclude defines file patterns to exclude from linting.
	Exclude []string `yaml:"exclude" json:"exclude"`
}

Config represents the api-style-spec configuration file.

func Default

func Default() *Config

Default returns the default configuration.

func Load

func Load() (*Config, error)

Load loads configuration using default search paths. Returns nil config (not an error) if no config file is found.

func LoadFile

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

LoadFile loads configuration from a specific file path.

func LoadOrDefault

func LoadOrDefault() (*Config, error)

LoadOrDefault loads configuration or returns default if not found.

func (*Config) Merge

func (c *Config) Merge(profile, level string, include, exclude []string)

Merge merges CLI flags into this config. CLI flags take precedence.

func (*Config) ToExceptions

func (c *Config) ToExceptions() []types.Exception

ToExceptions converts ExceptionConfigs to types.Exception.

type ExceptionConfig

type ExceptionConfig struct {
	// RuleID is the rule being waived.
	RuleID string `yaml:"rule" json:"rule"`

	// Paths are glob patterns where the exception applies.
	Paths []string `yaml:"paths" json:"paths"`

	// Reason explains why this exception was granted.
	Reason string `yaml:"reason" json:"reason"`
}

ExceptionConfig defines an exception in the config file.

type Loader

type Loader struct {
	// SearchPaths are directories to search for config files.
	SearchPaths []string
}

Loader loads api-style-spec configuration files.

func NewLoader

func NewLoader() *Loader

NewLoader creates a new config loader.

func (*Loader) Load

func (l *Loader) Load() (*Config, error)

Load searches for and loads a configuration file. Returns nil config (not an error) if no config file is found.

func (*Loader) LoadFile

func (l *Loader) LoadFile(path string) (*Config, error)

LoadFile loads configuration from a specific file path.

Jump to

Keyboard shortcuts

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