close

unambiguous

Added in v0.9.4

Configuration

rslint.config.ts
import { defineConfig, importPlugin } from '@rslint/core';

export default defineConfig([
  importPlugin.configs.recommended,
  {
    rules: {
      'import/unambiguous': 'error',
    },
  },
]);

Rule Details

Require files configured with languageOptions.sourceType: 'module' to contain a top-level import or export declaration. Files configured as script or commonjs are ignored.

Examples of incorrect code for this rule:

(function initialize() {
  console.log('ready');
})();

Examples of correct code for this rule:

import './initialize.js';
export function initialize() {
  console.log('ready');
}
(function initialize() {
  console.log('ready');
})();

export {};

An empty export {} can mark a file that only has side effects as a module. Type-only imports and exports, exported TypeScript declarations, and TypeScript export = also satisfy this rule.

The check follows the upstream declaration-based heuristic. Dynamic import(), import.meta, top-level await, CommonJS assignments, bare TypeScript import = aliases, and export as namespace do not satisfy it. Exports inside a namespace or an ambient module do not count as top-level exports. Empty module files are also reported.

The rule does not provide automatic fixes or suggestions.

Options

This rule has no options.

When Not To Use It

Disable this rule if your environment determines the module format without examining import or export declarations.

Original Documentation