Documentation
¶
Index ¶
- Variables
- func BoolPtr(b bool) *bool
- func CloneSettings(settings map[string]interface{}) map[string]interface{}
- func DiscoverGapFiles(config RslintConfig, configDir string, fsys vfs.FS, ...) []string
- func DiscoverGapFilesMultiConfig(configMap map[string]RslintConfig, fsys vfs.FS, ...) []string
- func GetCoreRules() []rule.Rule
- func GetPluginRules(pluginName string) []rule.Rule
- func InitDefaultConfig(directory string) error
- func NormalizePluginName(pluginName string) string
- func ParseCLIRuleFlag(input string) (string, interface{}, error)
- func ReadGitignoreAsGlobs(configDir string, fsys vfs.FS) []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: "jest", DeclNames: []string{"eslint-plugin-jest", "jest"}, // 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 CloneSettings ¶ added in v0.4.0
func DiscoverGapFiles ¶ added in v0.4.0
func DiscoverGapFiles( config RslintConfig, configDir string, fsys vfs.FS, programFiles map[string]struct{}, allowFiles []string, allowDirs []string, ) []string
DiscoverGapFiles scans the filesystem for "gap files" — files that match a config entry's `files` pattern but are not in any tsconfig Program. These files get a fallback Program (AST-only, no type info) and only run non-type-aware rules.
Files pass through these filters:
- Match at least one config entry's `files` pattern
- Not in global ignores (directory-level and file-level)
- Not already in programFiles (existing tsconfig Programs)
- Pass GetConfigForFile (would actually receive lint rules)
Uses single-pass fs.WalkDir with directory-level pruning (node_modules, .git, and isDirBlocked patterns are skipped at walk time, not after traversal).
When allowFiles/allowDirs are provided (CLI args), only files within scope.
Returns:
- nil: no config entry has a `files` field → caller uses legacy tsconfig-only behavior
- []: `files` present but no gaps found
- [...]: gap files to create a fallback Program for
func DiscoverGapFilesMultiConfig ¶ added in v0.4.0
func DiscoverGapFilesMultiConfig( configMap map[string]RslintConfig, fsys vfs.FS, programFiles map[string]struct{}, allowFiles []string, allowDirs []string, ) []string
DiscoverGapFilesMultiConfig runs DiscoverGapFiles for each config in a monorepo config map and returns the union of all gap files.
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 ParseCLIRuleFlag ¶ added in v0.4.0
ParseCLIRuleFlag parses a single --rule flag value in ESLint-compatible format. Supported formats:
- "ruleName: error"
- "ruleName: warn"
- "ruleName: off"
- "ruleName: [error, {\"allow\": [\"warn\"]}]"
Returns the rule name and its parsed configuration.
func ReadGitignoreAsGlobs ¶ added in v0.4.0
ReadGitignoreAsGlobs reads .gitignore files relevant to configDir and converts their patterns to rslint glob format suitable for use as global ignore patterns.
It collects patterns from two sources:
- Ancestor .gitignore files: walks UP from configDir to filesystem root, collecting .gitignore patterns at each level. This implements gitignore inheritance (root .gitignore affects all subdirectories).
- Descendant .gitignore files: walks DOWN from configDir, collecting nested .gitignore with directory-scoped prefixes.
Returns nil if no .gitignore files are 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
func BuildCLIRuleEntry ¶ added in v0.4.0
func BuildCLIRuleEntry(flags []string) (*ConfigEntry, error)
BuildCLIRuleEntry converts a list of --rule flag values into a synthetic ConfigEntry with no Files field (matches all files). Returns nil if flags is empty.
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).
Global ignore evaluation happens in two phases:
- Directory-level (isDirBlockedByIgnores): patterns like dir/** block entire directories. Negation (!) cannot override directory-level blocking.
- File-level (isFileIgnored): sequential evaluation with ! negation support for re-inclusion.
After global ignore check, entries are merged in order if their files match and ignores don't. cwd is the directory the config lives in; file paths are resolved relative to it.
type RuleConfig ¶
type RuleConfig struct {
Level string `json:"level,omitempty"` // "error", "warn", "off"
Options interface{} `json:"options,omitempty"` // Rule-specific options (string, map, array, etc.)
}
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() 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 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.