exports-style
UnreleasedConfiguration
Enforces a consistent CommonJS export style using either module.exports or exports.
Rule details
exports initially refers to the same object as module.exports. Replacing either value breaks that connection, so mixing the two styles can leave properties out of the exported object.
By default, the rule disallows references to the global exports variable. With the "exports" option, it disallows references to module.exports and direct assignments to exports. Locally shadowed variables are ignored.
Examples of incorrect code with the default option:
Examples of correct code with the default option:
Options
The first option selects the style:
"module.exports"(default): requiremodule.exports."exports": requireexportsproperty access and disallow assigning toexportsitself.
The second option is an object with allowBatchAssign, which defaults to false. Setting it to true allows both styles in the same chained assignment.
Examples of correct code with this configuration:
With "exports" and the default allowBatchAssign: false, use property assignments:
Automatic fixes
This rule reports inconsistent export styles without automatic fixes or suggestions. Update the export code manually so you can preserve which object is exported and which references still point to it.
Differences from upstream
Unlike eslint-plugin-n, rslint does not automatically rewrite module.exports to exports. Replacing the exported object and mutating the existing object can produce different results:
Changing the assignment to exports.a = 1 would make the comparison return true. Even replacing module.exports.foo with exports.foo can change behavior when exports is shadowed or the two values no longer refer to the same object.