Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/named for module.exports? #1145

Open
cbrwizard opened this issue Jul 30, 2018 · 10 comments · May be fixed by #1226
Open

import/named for module.exports? #1145

cbrwizard opened this issue Jul 30, 2018 · 10 comments · May be fixed by #1226

Comments

@cbrwizard
Copy link

cbrwizard commented Jul 30, 2018

Hey, is there any way to enable the import/named rule for module.exports?

Eg:

//lib.js
const toExport = true

module.exports = {
  toExport,
}


//user.js
const {toEpxort} = require('./lib') // here I want it to throw a lint error

console.log(toEpxort)
@ljharb
Copy link
Member

ljharb commented Jul 30, 2018

It should, i'd expect.

@cbrwizard
Copy link
Author

I'd definitely love that, as we haven't migrated backend code to ES6 imports yet. Looks like it doesn't work right now. Tried with this setting:

"import/named": [2, { "commonjs": true }],

@vikr01
Copy link
Contributor

vikr01 commented Oct 24, 2018

Should a case like this be ignored?

if(foo === bar) {
  module.exports.foo = bar;
}

I assume we should only check the top-level module.exports/exports.

And also stranger cases like this:

Object.assign(module.exports, {
  foo: 'bar'
});

@ljharb
Copy link
Member

ljharb commented Oct 24, 2018

I’m not worried about the stranger cases. Code that does that should be refactored to use a single static module.exports assignment.

@polgfred
Copy link

polgfred commented Jan 2, 2019

Any idea when this will get merged in?

@polgfred
Copy link

polgfred commented Jan 2, 2019

Sorry, I was referring to the open PR (#1222).

@ljharb
Copy link
Member

ljharb commented Jan 2, 2019

ahhh, i didn't remember there was one :-) I've got it on my list to rereview.

@polgfred
Copy link

polgfred commented Jan 3, 2019

Actually #1226 (commonjs exports) is the relevant one for this issue.

@fabioelizandro
Copy link

Is there anything I can help with this feature? I want to put this rule in place on my projects and in my option this feature suits really well eslint-plugin-import project

@ljharb
Copy link
Member

ljharb commented Aug 5, 2021

@fabioelizandro if you comment a link to an updated branch on #1226, then I can pull in the changes and we can get it moving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants