no_default_export

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoDefaultExportRule = rule.Rule{
	Name: "import/no-default-export",
	Run: func(ctx rule.RuleContext, _options []any) rule.RuleListeners {
		reportDefaultExport := func(node *ast.Node) {
			ctx.ReportRange(defaultKeywordRange(ctx.SourceFile, node), preferNamedMessage())
		}

		checkExportDeclaration := func(node *ast.Node) {
			exportDecl := node.AsExportDeclaration()
			if exportDecl == nil ||
				exportDecl.ExportClause == nil ||
				exportDecl.ExportClause.Kind != ast.KindNamedExports {
				return
			}

			namedExports := exportDecl.ExportClause.AsNamedExports()
			if namedExports == nil || namedExports.Elements == nil {
				return
			}

			reportRange := tokenAfterExportKeywordRange(ctx.SourceFile, node)
			for _, specifierNode := range namedExports.Elements.Nodes {
				specifier := specifierNode.AsExportSpecifier()
				if specifier == nil || !ast.ModuleExportNameIsDefault(specifier.Name()) {
					continue
				}

				local := specifier.PropertyName
				if local == nil {
					local = specifier.Name()
				}
				ctx.ReportRange(reportRange, noAliasDefaultMessage(localNameForMessage(local)))
			}
		}

		return rule.RuleListeners{
			ast.KindExportAssignment: func(node *ast.Node) {
				exportAssignment := node.AsExportAssignment()
				if exportAssignment == nil || exportAssignment.IsExportEquals {
					return
				}
				reportDefaultExport(node)
			},
			ast.KindFunctionDeclaration: func(node *ast.Node) {
				if isDefaultExportedDeclaration(node) {
					reportDefaultExport(node)
				}
			},
			ast.KindClassDeclaration: func(node *ast.Node) {
				if isDefaultExportedDeclaration(node) {
					reportDefaultExport(node)
				}
			},
			ast.KindInterfaceDeclaration: func(node *ast.Node) {
				if isDefaultExportedDeclaration(node) {
					reportDefaultExport(node)
				}
			},
			ast.KindEnumDeclaration: func(node *ast.Node) {
				if isDefaultExportedDeclaration(node) {
					reportDefaultExport(node)
				}
			},
			ast.KindExportDeclaration: checkExportDeclaration,
		}
	},
}

See: https://github.com/import-js/eslint-plugin-import/blob/main/src/rules/no-default-export.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