# import/export

> Disallow exporting the same name twice, and `export *` from a file with no named exports

If two files both export `format` and you re-export both with `export *`, JavaScript silently leaves `format` out, and `import { format }` fails somewhere else. If your own file exports `format` too, yours wins and the other one is hidden.

The rule reads the file behind each `export *` and reports every name that's exported more than once. It also reports an `export *` from a file that has no named exports. That line does nothing, because `export *` never passes on a default export.

It reads JavaScript and TypeScript files, including JSX. With an ESLint config it only reads `.js`, `.mjs` and `.cjs` files, unless `settings["import/extensions"]` lists others.

In TypeScript, function overloads are allowed, and so are a type and a value with the same name, and a namespace merged with a function, class or enum.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"import/export" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* file "dates.js" */}
```js
export function format(date) {
  return date.toISOString();
}
```

{/* file "numbers.js" */}
```js
export function format(number) {
  return number.toFixed(2);
}
```

{/* bad {"count": 2} */}
```js
export * from "./dates.js";
export * from "./numbers.js";
```

{/* file "logger.js" */}
```js
export default function log(message) {
  console.log(message);
}
```

{/* bad */}
```js
export * from "./logger.js";
```

{/* bad */}
```ts
const fallback = "en";

export const locale = "de";
export { fallback as locale };
```

Not reported:

{/* file "dates.js" */}
```js
export function format(date) {
  return date.toISOString();
}
```

{/* file "numbers.js" */}
```js
export function format(number) {
  return number.toFixed(2);
}
```

{/* good */}
```js
export { format as formatDate } from "./dates.js";
export * from "./numbers.js";
```

{/* file "logger.js" */}
```js
export default function log(message) {
  console.log(message);
}
```

{/* good */}
```js
export { default as log } from "./logger.js";
```

{/* good */}
```ts
export function parse(input: string): number;
export function parse(input: number): number;
export function parse(input: string | number): number {
  return Number(input);
}

export namespace parse {
  export const radix = 10;
}

export type Level = "info" | "error";
export const Level = { info: "info", error: "error" } as const;
```
