Skip to content

Latest commit

 

History

History
87 lines (66 loc) · 1.74 KB

group-exports.md

File metadata and controls

87 lines (66 loc) · 1.74 KB

import/group-exports

Reports when named exports are not grouped together in a single export declaration or when multiple assignments to CommonJS module.exports or exports object are present in a single file.

Rationale: An export declaration or module.exports assignment can appear anywhere in the code. By requiring a single export declaration all your exports will remain at one place, making it easier to see what exports a module provides.

Rule Details

This rule warns whenever a single file contains multiple named export declarations or multiple assignments to module.exports (or exports).

Valid

// A single named export declaration -> ok
export const valid = true
const first = true
const second = true

// A single named export declaration -> ok
export {
  first,
  second,
}
// A single exports assignment -> ok
module.exports = {
  first: true,
  second: true
}
const first = true
const second = true

// A single exports assignment -> ok
module.exports = {
  first,
  second,
}
function test() {}
test.property = true
test.another = true

// A single exports assignment -> ok
module.exports = test

Invalid

// Multiple named export statements -> not ok!
export const first = true
export const second = true
// Multiple exports assignments -> not ok!
exports.first = true
exports.second = true
// Multiple exports assignments -> not ok!
module.exports = {}
module.exports.first = true
// Multiple exports assignments -> not ok!
module.exports = () => {}
module.exports.first = true
module.exports.second = true

When Not To Use It

If you do not mind having your exports spread across the file, you can safely turn this rule off.