Documentation
¶
Index ¶
- Variables
- func BoolPtr(b bool) *bool
- func GetCoreRules() []rule.Rule
- func GetPluginRules(pluginName string) []rule.Rule
- func InitDefaultConfig(directory string) error
- func NormalizePluginName(pluginName string) string
- func RegisterAllRules()
- func RulePluginPrefix(ruleName string) string
- type ConfigEntry
- type ConfigLoader
- func (loader *ConfigLoader) LoadConfiguration(configPath string) (RslintConfig, []string, string, error)
- func (loader *ConfigLoader) LoadDefaultRslintConfig() (RslintConfig, string, error)
- func (loader *ConfigLoader) LoadRslintConfig(configPath string) (RslintConfig, string, error)
- func (loader *ConfigLoader) LoadTsConfigsFromRslintConfig(rslintConfig RslintConfig, configDirectory string) ([]string, error)
- type LanguageOptions
- type MergedConfig
- type ParserOptions
- type PluginInfo
- type ProjectPaths
- type RslintConfig
- type RuleConfig
- type RuleRegistry
- func (r *RuleRegistry) GetAllRules() map[string]rule.Rule
- func (r *RuleRegistry) GetEnabledRules(config RslintConfig, filePath string, cwd string, enforcePlugins bool) ([]linter.ConfiguredRule, *MergedConfig)
- func (r *RuleRegistry) GetRule(name string) (rule.Rule, bool)
- func (r *RuleRegistry) Register(ruleName string, ruleImpl rule.Rule)
- type Rules
- type Settings
Constants ¶
This section is empty.
Variables ¶
var GlobalRuleRegistry = NewRuleRegistry()
Global rule registry instance
var KnownPlugins = []PluginInfo{ { RulePrefix: "@typescript-eslint", DeclNames: []string{"@typescript-eslint"}, // contains filtered or unexported fields }, { RulePrefix: "import", DeclNames: []string{"eslint-plugin-import", "import"}, // contains filtered or unexported fields }, { RulePrefix: "react", DeclNames: []string{"react"}, // contains filtered or unexported fields }, }
KnownPlugins is the single source of truth for all supported plugins.
Functions ¶
func GetCoreRules ¶ added in v0.3.0
GetCoreRules returns core ESLint rules (those without a "/" prefix).
func GetPluginRules ¶ added in v0.3.0
GetPluginRules returns only rules under the given plugin namespace (prefix match).
func InitDefaultConfig ¶ added in v0.1.10
InitDefaultConfig initializes a default config file in the directory.
- JS/TS config already exists → error
- Only JSON/JSONC config exists → migrate to JS/TS config and delete JSON
- Nothing exists → create default JS/TS config
func NormalizePluginName ¶ added in v0.3.2
NormalizePluginName converts a plugin declaration name to its rule prefix form. Looks up KnownPlugins; returns the input unchanged if not found.
func RegisterAllRules ¶ added in v0.1.8
func RegisterAllRules()
func RulePluginPrefix ¶ added in v0.3.2
RulePluginPrefix extracts the plugin prefix from a rule name. "@typescript-eslint/no-explicit-any" → "@typescript-eslint" "import/no-unresolved" → "import" "no-debugger" → "" (core rule)
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
Plugins map[string]struct{}
}
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 PluginInfo ¶ added in v0.3.2
type PluginInfo struct {
RulePrefix string // Rule name prefix, e.g. "import"
DeclNames []string // All accepted declaration names, e.g. ["eslint-plugin-import", "import"]
// contains filtered or unexported fields
}
PluginInfo defines a known plugin with its rule prefix and all accepted declaration names.
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 FindNearestConfig ¶ added in v0.3.2
func FindNearestConfig(filePath string, configMap map[string]RslintConfig) (string, RslintConfig)
FindNearestConfig finds the config whose configDirectory is the nearest ancestor of (or exact match for) filePath. It picks the deepest (longest) matching configDirectory, mirroring ESLint v10's per-file config lookup. Returns the configDirectory and the config, or ("", nil) if no config matches.
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, enforcePlugins bool) ([]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). When enforcePlugins is true (JS/TS config), rules with a plugin prefix (e.g. "@typescript-eslint/") are only included if the corresponding plugin is declared in the merged config's Plugins set. Core rules (no "/" prefix) are always included regardless of enforcePlugins. cwd is the config directory used to resolve files/ignores patterns.