rule

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenerOnAllowPattern

func ListenerOnAllowPattern(kind ast.Kind) ast.Kind

TODO(port): better name

func ListenerOnExit

func ListenerOnExit(kind ast.Kind) ast.Kind

func ListenerOnNotAllowPattern

func ListenerOnNotAllowPattern(kind ast.Kind) ast.Kind

func ReportNodeWithFixesOrSuggestions

func ReportNodeWithFixesOrSuggestions(ctx RuleContext, node *ast.Node, fix bool, msg RuleMessage, suggestionMsg RuleMessage, fixes ...RuleFix)

Types

type DiagnosticSeverity

type DiagnosticSeverity int

DiagnosticSeverity represents the severity level of a diagnostic

const (
	SeverityError DiagnosticSeverity = iota
	SeverityWarning
	SeverityOff
)

func ParseSeverity

func ParseSeverity(level string) DiagnosticSeverity

ParseSeverity converts a string to DiagnosticSeverity

func (DiagnosticSeverity) Int

func (s DiagnosticSeverity) Int() int

String returns the string representation of the severity

func (DiagnosticSeverity) String

func (s DiagnosticSeverity) String() string

String returns the string representation of the severity

type DisableManager

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

DisableManager tracks which rules are disabled at different locations in a file

func NewDisableManager

func NewDisableManager(sourceFile *ast.SourceFile, comments []*ast.CommentRange) *DisableManager

NewDisableManager creates a new DisableManager for the given source file

func (*DisableManager) IsRuleDisabled

func (dm *DisableManager) IsRuleDisabled(ruleName string, pos int) bool

IsRuleDisabled checks if a rule is disabled at the given position

type ESLintDirective

type ESLintDirective struct {
	Kind      ESLintDirectiveKind
	Line      int
	RuleNames []string
}

ESLintDirective represents an ESLint disable/enable directive

type ESLintDirectiveKind

type ESLintDirectiveKind int
const (
	ESLintDirectiveDisable ESLintDirectiveKind = iota
	ESLintDirectiveEnable
	ESLintDirectiveDisableLine
	ESLintDirectiveDisableNextLine
)

type Rule

type Rule struct {
	Name string
	Run  func(ctx RuleContext, options any) RuleListeners
}

func CreateRule

func CreateRule(r Rule) Rule

type RuleContext

type RuleContext struct {
	SourceFile                 *ast.SourceFile
	Program                    *compiler.Program
	TypeChecker                *checker.Checker
	DisableManager             *DisableManager
	ReportRange                func(textRange core.TextRange, msg RuleMessage)
	ReportRangeWithSuggestions func(textRange core.TextRange, msg RuleMessage, suggestions ...RuleSuggestion)
	ReportNode                 func(node *ast.Node, msg RuleMessage)
	ReportNodeWithFixes        func(node *ast.Node, msg RuleMessage, fixes ...RuleFix)
	ReportNodeWithSuggestions  func(node *ast.Node, msg RuleMessage, suggestions ...RuleSuggestion)
}

type RuleDiagnostic

type RuleDiagnostic struct {
	Range    core.TextRange
	RuleName string
	Message  RuleMessage
	// nil if no fixes were provided
	FixesPtr *[]RuleFix
	// nil if no suggestions were provided
	Suggestions *[]RuleSuggestion
	SourceFile  *ast.SourceFile
	Severity    DiagnosticSeverity
}

func (RuleDiagnostic) Fixes

func (d RuleDiagnostic) Fixes() []RuleFix

type RuleFix

type RuleFix struct {
	Text  string
	Range core.TextRange
}

func RuleFixInsertAfter

func RuleFixInsertAfter(node *ast.Node, text string) RuleFix

func RuleFixInsertBefore

func RuleFixInsertBefore(file *ast.SourceFile, node *ast.Node, text string) RuleFix

func RuleFixRemove

func RuleFixRemove(file *ast.SourceFile, node *ast.Node) RuleFix

func RuleFixRemoveRange

func RuleFixRemoveRange(textRange core.TextRange) RuleFix

func RuleFixReplace

func RuleFixReplace(file *ast.SourceFile, node *ast.Node, text string) RuleFix

func RuleFixReplaceRange

func RuleFixReplaceRange(textRange core.TextRange, text string) RuleFix

type RuleListeners

type RuleListeners map[ast.Kind](func(node *ast.Node))

type RuleMessage

type RuleMessage struct {
	Id          string
	Description string
}

type RuleSuggestion

type RuleSuggestion struct {
	Message  RuleMessage
	FixesArr []RuleFix
}

func (RuleSuggestion) Fixes

func (s RuleSuggestion) Fixes() []RuleFix

Jump to

Keyboard shortcuts

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