default_rule

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT, MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRule = rule.Rule{
	Name: "import/default",
	Run: func(ctx rule.RuleContext, options []any) rule.RuleListeners {
		checkDefault := func(node *ast.Node) {
			importDecl := node.AsImportDeclaration()
			if importDecl.ImportClause == nil {
				return
			}

			defaultSpecifier := importDecl.ImportClause.AsImportClause().Name()
			if defaultSpecifier == nil {
				return
			}

			hasDefault, ok := import_utils.HasDefaultExport(ctx, importDecl.ModuleSpecifier)
			if !ok || hasDefault {
				return
			}

			ctx.ReportNode(defaultSpecifier, rule.RuleMessage{
				Id:          "noDefault",
				Description: fmt.Sprintf("No default export found in imported module %q.", importDecl.ModuleSpecifier.Text()),
			})
		}

		return rule.RuleListeners{
			ast.KindImportDeclaration:   checkDefault,
			ast.KindJSImportDeclaration: checkDefault,
		}
	},
}

DefaultRule ensures a default export is present when a module is imported through a default import.

See: https://github.com/import-js/eslint-plugin-import/blob/main/src/rules/default.js

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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