Skip to content

Latest commit

 

History

History
88 lines (63 loc) · 2.11 KB

File metadata and controls

88 lines (63 loc) · 2.11 KB

eslint-plugin-barrels/no-import

💼 This rule is enabled in the ✅ recommended and 🌐 all configs.

Disallow import from barrel files with specific relative path.

Important

The word "specific" is used here for a reason. This rule disallow import from file, that path consist of "one or few moving up". For example, '..' or '../../..'. It means rule allows import from barrel file with path, for instance, '../some-directory-with-barrel', './components' or even './components/index.js(ts)'.

Options

This rule supports the following options:

  • onlySameLevel: boolean, which disallow imports from '..' path only. For example, '../../..' will be allowed with onlySameLevel: "true".

Rule Details

Valid:

import defaultExport from './some.component.ts';
/* eslint barrels/no-import: ["error", { onlySameLevel: false }] */
import { default as alias } from './some.component.ts';
/* eslint barrels/no-import: ["error", { onlySameLevel: false }] */
import { export1 } from './some.component.ts';
/* eslint barrels/no-import: ["error", { onlySameLevel: true }] */
import * as name from '../../..';
import { export1 as alias1 } from './some.component.ts';
/* eslint barrels/no-import: ["error", { onlySameLevel: false }] */
import './some.component.ts';
import * as name from '.';
import * as name from './..';
import * as name from '../index.js(ts)';

Invalid:

import defaultExport from '..';
/* eslint barrels/no-import: ["error", { onlySameLevel: false }] */
import { default as alias } from '..';
import { export1 } from '..';
/* eslint barrels/no-import: ["error", { onlySameLevel: true }] */
import * as name from '..'
import { export1 as alias1 } from '../../..';
import '..';

More test cases you can find in test-cases.ts