ESLint plugin to disallow barrel files.
Barrel files can slow down your build/tests, can cause circular dependencies, and makes tree shaking more difficult.
- jestjs/jest#11234
- vercel/next.js#12557
- https://dev.to/tassiofront/barrel-files-and-why-you-should-stop-using-them-now-bc4
- https://flaming.codes/posts/barrel-files-in-javascript
no-barrel-files
// fail
export * from "./foo";
import Foo from "./foo";
export default Foo;
import Foo from "./foo";
export { Foo };
export { Moo } from './Moo';
export { default as Moo } from './Moo';
// pass
const Foo = 'baz';
function Bar() {}
class Baz {}
export default Foo;
export { Bar, Baz }
import { Moo } from './Moo';
export const Baz = Moo;
npm install eslint-plugin-no-barrel-files --save-dev
This plugin supports both flat config and legacy config.
import noBarrelFiles from "eslint-plugin-no-barrel-files";
export default [
noBarrelFiles.flat,
];
module.exports = {
plugins: ['no-barrel-files'],
rules: {
'no-barrel-files/no-barrel-files': 'error'
}
}
If you need any additional features or you find a bug, feel free to submit a pull request or submit an issue.