lightsoutAlpha

index-file-contents

What an index file may hold.

Deterministic checkAdvises by default

The rule

Agents read this text as written when they write and review code.

An index file holds only re-export lines, export { Foo } from '<path>' and export type { Bar } from '<path>', and comments.

  • Re-export each name explicitly, never with export *. List what other packages need, and nothing only the package itself uses.
  • Put executable code in an entry file with its own name, conventionally main.ts, which imports what it runs from the files that declare it.

A package's entry is the list other packages build against. Code in it makes that list hard to read, and a star publishes whatever its target happens to export, so the contract stops being a decision.

Examples

The check flags the incorrect code and passes the correct code. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.

Incorrect

srcfeature
src/index.ts
// Incorrect: a star publishes whatever renderGreeting.ts happens to export, and
// the call is code in the package's entry.
export * from './feature/renderGreeting';
console.log('entry loaded');

Correct

srcfeature
src/index.ts
export { renderGreeting } from './feature/renderGreeting';

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"index-file-contents": "advisory"
}
}

Packs that select it