Rule to check module.exports consistency
Closed this issue ยท 3 comments
I would like to have a eslint rule that checks if the modules are exported in consistent way in all modules.
Now you can export functions in one module like this:
// first you declare and implement all the functions
function findById() { ... do something ...}
function findAll() {}
function incrementViews() {}
module.exports = { // and then all the functions are exported at once
findById,
findAll,
incrementViews
}
and in other module, you can export functions directly when declaring them:
// export the function with the implementation in one line
module.exports.findById = function findById() {
... do something ...
}
module.exports.findAll = function findAll() {
... do something ...
}
module.exports.incrementViews = function incrementViews() {
... do something ...
}
I'm not sure if this kind of rule exists in eslint, but I think it would be nice to have it and this rule would be more important than checking if a comment starts with capital letter ๐
I like the idea. Basically, what you want is a rule which checks for a single assignment to module.exports or a single export statement (with one extra export default statement allowed, since they are mutually exclusive) in modules.
I will look around if this rule is already implemented somewhere and if not, I will try to submit a proposal to ESLint. Thanks for the idea!
I managed to implement this and opened a PR: import-js/eslint-plugin-import#721
๐ ๐ป! Will be released in 7.11 soon!