close

no-exports-in-scripts

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-exports-in-scripts': 'error',
    },
  },
]);

Rule Details

Scripts (files whose first line starts with #!) are meant to be executed directly, not imported as modules. Exports in a script mix module and script boundaries and can mislead readers about how the file is intended to run.

Examples of incorrect code for this rule:

#!/usr/bin/env node
export const foo = 1;
#!/usr/bin/env node
export default foo;
#!/usr/bin/env node
const foo = 1;
export {foo};
#!/usr/bin/env node
export {};

Examples of correct code for this rule:

#!/usr/bin/env node
const foo = 1;
console.log(foo);
// #!/usr/bin/env node
export const foo = 1;
console.log('#!/usr/bin/env node');
export const foo = 1;

A file without a shebang is a module, and modules are free to use exports:

export const foo = 1;

Original Documentation