config

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 129 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalRuleRegistry = NewRuleRegistry()

Global rule registry instance

Functions

func BoolPtr added in v0.3.0

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to the given bool value.

func GetAllRulesForPlugin

func GetAllRulesForPlugin(plugin string) []rule.Rule

func GetCoreRules added in v0.3.0

func GetCoreRules() []rule.Rule

GetCoreRules returns core ESLint rules (those without a "/" prefix).

func GetPluginRules added in v0.3.0

func GetPluginRules(pluginName string) []rule.Rule

GetPluginRules returns only rules under the given plugin namespace (prefix match).

func InitDefaultConfig added in v0.1.10

func InitDefaultConfig(directory string) error

InitDefaultConfig initializes a default config file in the directory. - If tsconfig.json exists → rslint.config.ts (ESM syntax, handled by TS loaders) - Otherwise, follows the ESLint convention based on package.json "type" field:

  • "type": "module" → rslint.config.js (ESM syntax, .js is ESM in this context)
  • no "type": "module" → rslint.config.mjs (ESM syntax, .mjs is always ESM)

func RegisterAllRules added in v0.1.8

func RegisterAllRules()

Types

type ConfigEntry

type ConfigEntry struct {
	Files           []string         `json:"files,omitempty"`
	Ignores         []string         `json:"ignores,omitempty"`
	LanguageOptions *LanguageOptions `json:"languageOptions,omitempty"`
	Rules           Rules            `json:"rules"`
	Plugins         []string         `json:"plugins,omitempty"`
	Settings        Settings         `json:"settings,omitempty"`
}

ConfigEntry represents a single configuration entry in the config array

type ConfigLoader

type ConfigLoader struct {
	// contains filtered or unexported fields
}

ConfigLoader handles loading and parsing of rslint and tsconfig files

func NewConfigLoader

func NewConfigLoader(fs vfs.FS, currentDirectory string) *ConfigLoader

NewConfigLoader creates a new configuration loader

func (*ConfigLoader) LoadConfiguration

func (loader *ConfigLoader) LoadConfiguration(configPath string) (RslintConfig, []string, string, error)

LoadConfiguration is a convenience method that loads both rslint and tsconfig configurations

func (*ConfigLoader) LoadDefaultRslintConfig

func (loader *ConfigLoader) LoadDefaultRslintConfig() (RslintConfig, string, error)

LoadDefaultRslintConfig attempts to load default configuration files

func (*ConfigLoader) LoadRslintConfig

func (loader *ConfigLoader) LoadRslintConfig(configPath string) (RslintConfig, string, error)

LoadRslintConfig loads and parses a rslint configuration file. For JSON/JSONC files, a deprecation warning is printed to stderr.

func (*ConfigLoader) LoadTsConfigsFromRslintConfig

func (loader *ConfigLoader) LoadTsConfigsFromRslintConfig(rslintConfig RslintConfig, configDirectory string) ([]string, error)

LoadTsConfigsFromRslintConfig extracts and validates TypeScript configuration paths from rslint config. Returns an empty slice (no error) when no parserOptions.project is specified — this is valid for pure JS projects that don't need explicit TypeScript configuration.

type LanguageOptions

type LanguageOptions struct {
	ParserOptions *ParserOptions `json:"parserOptions,omitempty"`
}

LanguageOptions contains language-specific configuration options

type MergedConfig added in v0.3.0

type MergedConfig struct {
	Rules           map[string]*RuleConfig
	Settings        Settings
	LanguageOptions *LanguageOptions
}

MergedConfig is the final computed configuration for a single file

type ParserOptions

type ParserOptions struct {
	ProjectService *bool        `json:"projectService,omitempty"`
	Project        ProjectPaths `json:"project,omitempty"`
}

ParserOptions contains parser-specific configuration. ProjectService uses *bool to distinguish "not set" (nil) from "explicitly false".

type ProjectPaths added in v0.1.13

type ProjectPaths []string

ProjectPaths represents project paths that can be either a single string or an array of strings

func (*ProjectPaths) UnmarshalJSON added in v0.1.13

func (p *ProjectPaths) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling to support both string and string[] formats

type RslintConfig

type RslintConfig []ConfigEntry

RslintConfig represents the top-level configuration array

func LoadConfigurationWithFallback

func LoadConfigurationWithFallback(configPath string, currentDirectory string, fs vfs.FS) (RslintConfig, []string, string)

LoadConfigurationWithFallback loads configuration and handles errors by printing to stderr and exiting This is for backward compatibility with the existing cmd behavior

func (RslintConfig) GetConfigForFile added in v0.3.0

func (config RslintConfig) GetConfigForFile(filePath string, cwd string) *MergedConfig

GetConfigForFile computes the merged configuration for a file following ESLint flat config semantics. Returns nil if the file is globally ignored or no entry matches (should not be linted). Both JS and JSON configs are processed identically here — any differences in default rule behavior are handled during config loading (see normalizeJSONConfig). cwd is the directory the config lives in; file paths are resolved relative to it for files/ignores glob matching.

type RuleConfig

type RuleConfig struct {
	Level   string                 `json:"level,omitempty"`   // "error", "warn", "off"
	Options map[string]interface{} `json:"options,omitempty"` // Rule-specific options
}

RuleConfig represents individual rule configuration

func (*RuleConfig) GetLevel

func (rc *RuleConfig) GetLevel() string

GetLevel returns the rule level, defaulting to "error" if not specified

func (*RuleConfig) GetOptions

func (rc *RuleConfig) GetOptions() map[string]interface{}

GetOptions returns the rule options, ensuring we return a usable value

func (*RuleConfig) GetSeverity

func (rc *RuleConfig) GetSeverity() rule.DiagnosticSeverity

GetSeverity returns the diagnostic severity for this rule configuration

func (*RuleConfig) IsEnabled

func (rc *RuleConfig) IsEnabled() bool

IsEnabled returns true if the rule is enabled (not "off")

func (*RuleConfig) SetOptions

func (rc *RuleConfig) SetOptions(options map[string]interface{})

SetOptions sets the rule options

type RuleRegistry

type RuleRegistry struct {
	// contains filtered or unexported fields
}

RuleRegistry manages all available rules

func NewRuleRegistry

func NewRuleRegistry() *RuleRegistry

NewRuleRegistry creates a new rule registry

func (*RuleRegistry) GetAllRules

func (r *RuleRegistry) GetAllRules() map[string]rule.Rule

GetAllRules returns all registered rules

func (*RuleRegistry) GetEnabledRules

func (r *RuleRegistry) GetEnabledRules(config RslintConfig, filePath string, cwd string) ([]linter.ConfiguredRule, *MergedConfig)

GetEnabledRules returns rules that are enabled in the configuration for a given file. Returns nil if no config entry matches the file (file should not be linted). cwd is the config directory used to resolve files/ignores patterns.

func (*RuleRegistry) GetRule

func (r *RuleRegistry) GetRule(name string) (rule.Rule, bool)

GetRule returns a rule by name

func (*RuleRegistry) Register

func (r *RuleRegistry) Register(ruleName string, ruleImpl rule.Rule)

Register adds a rule to the registry

type Rules

type Rules map[string]interface{}

Rules represents the rules configuration This can be extended to include specific rule configurations

type Settings added in v0.3.0

type Settings map[string]interface{}

Settings represents shared settings accessible to rules

Jump to

Keyboard shortcuts

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