Documentation
¶
Index ¶
- func ListenerOnAllowPattern(kind ast.Kind) ast.Kind
- func ListenerOnExit(kind ast.Kind) ast.Kind
- func ListenerOnNotAllowPattern(kind ast.Kind) ast.Kind
- func ReportNodeWithFixesOrSuggestions(ctx RuleContext, node *ast.Node, fix bool, msg RuleMessage, ...)
- type DiagnosticSeverity
- type DisableManager
- type Rule
- type RuleContext
- type RuleDiagnostic
- type RuleFix
- func RuleFixInsertAfter(node *ast.Node, text string) RuleFix
- func RuleFixInsertBefore(file *ast.SourceFile, node *ast.Node, text string) RuleFix
- func RuleFixRemove(file *ast.SourceFile, node *ast.Node) RuleFix
- func RuleFixRemoveRange(textRange core.TextRange) RuleFix
- func RuleFixReplace(file *ast.SourceFile, node *ast.Node, text string) RuleFix
- func RuleFixReplaceRange(textRange core.TextRange, text string) RuleFix
- type RuleListeners
- type RuleMessage
- type RuleSuggestion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenerOnAllowPattern ¶
TODO(port): better name
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 Rule ¶
type Rule struct {
Name string
RequiresTypeInfo bool
Run func(ctx RuleContext, options any) RuleListeners
}
func CreateRule ¶
type RuleContext ¶
type RuleContext struct {
SourceFile *ast.SourceFile
Settings map[string]interface{}
Program *compiler.Program
TypeChecker *checker.Checker
DisableManager *DisableManager
ReportRange func(textRange core.TextRange, msg RuleMessage)
ReportRangeWithFixes func(textRange core.TextRange, msg RuleMessage, fixes ...RuleFix)
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)
// ReportNodeWithFixesAndSuggestions emits a single diagnostic carrying
// BOTH an autofix and one or more suggestions. Used by rules that follow
// upstream's "promote first suggestion to fix while keeping the
// suggestion" pattern (e.g., ESLint's
// `enableDangerousAutofixThisMayCauseInfiniteLoops` in
// react-hooks/exhaustive-deps).
ReportNodeWithFixesAndSuggestions func(node *ast.Node, msg RuleMessage, fixes []RuleFix, suggestions []RuleSuggestion)
// ReportRangeWithFixesAndSuggestions is the range-keyed twin of
// ReportNodeWithFixesAndSuggestions. Same semantics, anchors the
// diagnostic at an explicit TextRange instead of a node's trimmed
// range.
ReportRangeWithFixesAndSuggestions func(textRange core.TextRange, msg RuleMessage, fixes []RuleFix, 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
// PreFormatted indicates that Message.Description already contains
// structured formatting (e.g. indented continuation lines from tsc diagnostics).
// The renderer will use a simple 2-space indent instead of the │ border style.
PreFormatted bool
}
func (RuleDiagnostic) Fixes ¶
func (d RuleDiagnostic) Fixes() []RuleFix
type RuleFix ¶
func RuleFixInsertBefore ¶
func RuleFixRemove ¶
func RuleFixRemove(file *ast.SourceFile, node *ast.Node) RuleFix
func RuleFixRemoveRange ¶
func RuleFixReplace ¶
type RuleMessage ¶
type RuleMessage struct {
Id string
Description string
// Data exposes the placeholder values that were substituted into
// Description (e.g. ESLint's `report({ data: { type } })`). Downstream
// reporters / IDE clients can use this for structured access. Optional —
// rules that don't carry placeholders may leave it nil.
Data map[string]string
}
type RuleSuggestion ¶
type RuleSuggestion struct {
Message RuleMessage
FixesArr []RuleFix
}
func (RuleSuggestion) Fixes ¶
func (s RuleSuggestion) Fixes() []RuleFix
Click to show internal directories.
Click to hide internal directories.