Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Rule to check module.exports consistency #16

Closed
hohy opened this issue Dec 8, 2016 · 3 comments
Closed

Rule to check module.exports consistency #16

hohy opened this issue Dec 8, 2016 · 3 comments
Assignees

Comments

@hohy
Copy link

hohy commented Dec 8, 2016

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 😜

@robertrossmann
Copy link
Member

robertrossmann commented Dec 12, 2016

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!

@robertrossmann robertrossmann self-assigned this Dec 12, 2016
@robertrossmann
Copy link
Member

I managed to implement this and opened a PR: import-js/eslint-plugin-import#721

@robertrossmann
Copy link
Member

🎉 🍻! Will be released in 7.11 soon!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants