# n/exports-style

> Enforce either `module.exports` or `exports` in CommonJS files

A CommonJS file can export through `module.exports` or through its shorthand `exports`. Both start as the same object, but once you assign a new value to `module.exports`, anything you add to `exports` is no longer exported. Sticking to one of the two everywhere avoids that.

{/* 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]
"n/exports-style" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"n/exports-style" = [
  "error",
  "module.exports", # "module.exports" or "exports"
  {
    allowBatchAssign = false,
  },
]
```

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

## Examples

Reported:

{/* bad */}
```js
exports.parse = function parse(text) {
  return JSON.parse(text);
};
```

Not reported:

{/* good */}
```js
module.exports.parse = function parse(text) {
  return JSON.parse(text);
};
```

## Options

```toml bunfig.toml
[lint.rules]
"n/exports-style" = ["error", "exports", { allowBatchAssign = true }]
```

| Option | What it does |
| --- | --- |
| `"module.exports"` (default) | Report every use of `exports`. |
| `"exports"` | Report every use of `module.exports`, and every assignment to `exports` itself. |

The second option is an object:

| Option | Default | What it does |
| --- | --- | --- |
| `allowBatchAssign` | `false` | Allow one statement that assigns to both, such as `module.exports = exports = value`. |

With `"exports"`:

{/* bad {"options": ["exports"], "count": 2} */}
```js
module.exports = { parse };
exports = { parse };
```

{/* good {"options": ["exports"]} */}
```js
exports.parse = parse;
```

With `allowBatchAssign`, you can replace the exported object and keep `exports` pointing at it:

{/* good {"options": ["exports", {"allowBatchAssign": true}]} */}
```js
module.exports = exports = function parse(text) {};
exports.version = "1.0.0";
```

{/* bad {"options": ["exports"]} */}
```js
module.exports = exports = function parse(text) {};
exports.version = "1.0.0";
```
