ESLint Plugin No Barrel Files

raw JSON →
1.3.1 verified Sat Apr 25 auth: no javascript

ESLint plugin (v1.3.1) that disallows barrel files — re-export modules that aggregate and re-export other modules. Barrel files are known to slow down builds/tests, cause circular dependencies, and hinder tree shaking. This plugin provides a single rule `no-barrel-files` that flags patterns like `export * from './foo'` or re-importing a default and re-exporting it. Supports flat config (ESLint 9+) and legacy config (ESLint 8). Actively maintained with TypeScript type declarations. Alternative to manual code review or other linting rules that partially address barrel files.

error Error: Failed to load plugin 'no-barrel-files' declared in '.eslintrc': Cannot find module 'eslint-plugin-no-barrel-files'
cause Plugin not installed or not in node_modules.
fix
Run npm install eslint-plugin-no-barrel-files --save-dev.
error Configuration for rule "no-barrel-files/no-barrel-files" is invalid: Value "error" should be one of 0, 1, 2.
cause Rule severity incorrectly set (e.g., as string 'error' instead of number 2).
fix
Set severity to 2 (or 'error') in an array: ['error'] or 2.
error TypeError: noBarrelFiles.flat is not a function
cause Using deprecated `flat` export which is no longer a function but an array.
fix
Use noBarrelFiles.configs.recommended instead of noBarrelFiles.flat.
breaking In v1.0.0, the flat config export changed from `plugin.flat` to `plugin.configs.recommended`. If using `plugin.flat`, update to `configs.recommended`.
fix Replace `noBarrelFiles.flat` with `noBarrelFiles.configs.recommended` in flat config.
deprecated The `flat` export is deprecated since v1.0.0. It will be removed in a future major version.
fix Use `configs.recommended` instead of `flat`.
gotcha Legacy config users must use the plugin prefix in rule names: `'no-barrel-files/no-barrel-files'`. Using just `'no-barrel-files'` will not work.
fix Set rule name as `'no-barrel-files/no-barrel-files'`.
gotcha The rule does not flag `export { default } from './foo'` (named export with alias 'default'); only `export { default as Moo } from './Moo'` is flagged.
fix If needed, manually audit or extend the rule. Check plugin issue tracker for potential updates.
npm install eslint-plugin-no-barrel-files
yarn add eslint-plugin-no-barrel-files
pnpm add eslint-plugin-no-barrel-files

Shows two ESLint configurations: legacy CommonJS for ESLint 8 and modern ESM flat config for ESLint 9+. Enables the single rule that flags barrel file patterns.

// .eslintrc.cjs (legacy ESLint 8)
module.exports = {
  plugins: ['no-barrel-files'],
  rules: {
    'no-barrel-files/no-barrel-files': 'error'
  }
};

// eslint.config.js (flat ESLint 9+)
import noBarrelFiles from 'eslint-plugin-no-barrel-files';

export default [
  ...noBarrelFiles.configs.recommended,
  {
    rules: {
      // Override or add more rules
    }
  }
];