For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/import/no-self-import.md.
close

no-self-import

Added in v0.1.8

Configuration

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

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

Rule Details

Disallows a module from importing itself. A module that imports itself creates a circular dependency on itself, which is always a mistake and can cause confusing runtime behavior or errors. This applies to both ES module import statements and CommonJS require() calls.

Loading the current file through a known text or JSON attribute view is not a self module import because that request does not execute the file as JavaScript.

Examples of incorrect code for this rule:

// in file "foo.js"
import foo from './foo';

// in file "index.js"
const index = require('./index');

Examples of correct code for this rule:

// in file "foo.js"
import bar from './bar';

// in file "index.js"
const utils = require('./utils');

Original Documentation