noctcore-architecture/barrel-purity
A barrel (
index.ts/index.tsx) must contain only re-exports — never local declarations, side effects, or default-exported values.
Recommended preset: error · Autofix: no · Suggestions: no · Type information: not needed
A barrel exists to present a folder’s public surface. The moment it also declares something — a const, a function, a type, a default-exported value — or does something — a side-effect import, a top-level call — the barrel becomes a real module with behavior. Every consumer that imports the folder now silently pulls that behavior in, and the folder no longer has a clean, movable boundary.
What it flags
Section titled “What it flags”Only index.ts / index.tsx (and the other index extensions) are inspected. Each top-level
statement that is not a pure re-export is reported.
export { Card } from './Card'; // named re-exportexport * from './Card.types'; // star re-exportexport * as card from './Card'; // namespace re-exportexport { default as CardView } from './Card'; // default re-exportimport { a } from './a'; // import that feeds a re-exportexport { a }; // ...its matching specifierexport type { Props } from './Card'; // type re-exportimport Card from './Card';export default Card; // re-export of a binding by nameexport const helper = 1; // local declarationexport function build() {} // local declarationexport type T = string; // local declarationexport default () => 1; // a value, not a re-exportimport './styles.css'; // side-effect importconsole.log('hi'); // side-effect statementconst cache = new Map(); // non-export codeAn import that carries bindings is allowed because it feeds a re-export; a specifier-less
import './x' is a side effect and is flagged.
What it does not flag
Section titled “What it does not flag”- Any file that is not an
indexbarrel: ahelper.tsfull of logic is none of this rule’s business. - Pure re-exports in every form shown in the
goodexample, including an import whose bindings feed a specifier-onlyexport { a }andexport default Cardof a binding by name. - Barrels whose path matches an
allowglob.
Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
allow |
string[] |
[] |
Globs (supporting **, *, ?) of barrel paths to exempt entirely. |
'noctcore-architecture/barrel-purity': ['error', { allow: ['**/legacy/**'],}]When not to use it
Section titled “When not to use it”If you deliberately keep small helpers or feature flags inside a package’s index.ts, this rule will
fight you. Prefer moving them into a sibling module and re-exporting — but if you cannot, disable the
rule for those paths via allow.