node/exports-style Style
What it does
Enforce either module.exports or exports.
Why is this bad?
module.exports and exports are the same instance by default. But those come to be different if one of them is modified.
module.exports = {
foo: 1,
};
exports.bar = 2;In this case, exports.bar will be lost since only the instance of module.exports will be exported.
Examples
Examples of incorrect code for the "module.exports" option:
exports.foo = 1;
exports.bar = 2;Examples of correct code for the "module.exports" option:
module.exports = {
foo: 1,
bar: 2,
};
module.exports.baz = 3;Examples of incorrect code for the "exports" option:
module.exports = {
foo: 1,
bar: 2,
};
module.exports.baz = 3;Examples of correct code for the "exports" option:
exports.foo = 1;
exports.bar = 2;Configuration
The 1st option
type: "module.exports" | "exports"
"module.exports"
Requires module.exports and disallows exports
"exports"
Requires exports and disallows module.exports
The 2nd option
This option is an object with the following properties:
allowBatchAssign
type: boolean
default: false
If this option is set to true, module.exports = exports = obj are allowed.
How to use
To enable this rule using the config file or in the CLI, you can use:
{
"plugins": ["node"],
"rules": {
"node/exports-style": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["node"],
rules: {
"node/exports-style": "error",
},
});oxlint --deny node/exports-style --node-pluginVersion
This rule was added in vnext.
