Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var NoNamespaceRule = rule.CreateRule(rule.Rule{ Name: "no-namespace", Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { opts := defaultNoNamespaceOptions if options != nil { var optsMap map[string]interface{} var ok bool if optArray, isArray := options.([]interface{}); isArray && len(optArray) > 0 { optsMap, ok = optArray[0].(map[string]interface{}) } else { optsMap, ok = options.(map[string]interface{}) } if ok { if allowDeclarations, ok := optsMap["allowDeclarations"].(bool); ok { opts.AllowDeclarations = utils.Ref(allowDeclarations) } if allowDefinitionFiles, ok := optsMap["allowDefinitionFiles"].(bool); ok { opts.AllowDefinitionFiles = utils.Ref(allowDefinitionFiles) } } } return rule.RuleListeners{ ast.KindModuleDeclaration: func(node *ast.Node) { moduleDecl := node.AsModuleDeclaration() if moduleDecl == nil { return } if moduleDecl.Keyword != ast.KindNamespaceKeyword { return } if opts.AllowDefinitionFiles != nil && *opts.AllowDefinitionFiles && strings.HasSuffix(ctx.SourceFile.FileName(), ".d.ts") { return } if opts.AllowDeclarations != nil && *opts.AllowDeclarations && utils.IncludesModifier(node, ast.KindDeclareKeyword) { return } ctx.ReportNode(moduleDecl.Name(), buildNoNamespaceMessage()) }, } }, })
rule instance check if the namespace is used
Functions ¶
This section is empty.
Types ¶
type NoNamespaceOptions ¶
type NoNamespaceOptions struct {
AllowDeclarations *bool `json:"allowDeclarations"`
AllowDefinitionFiles *bool `json:"allowDefinitionFiles"`
}
rule options
Click to show internal directories.
Click to hide internal directories.