asapach / babel-plugin-rewire-exports

Babel plugin for stubbing [ES6, ES2015] module exports
MIT License
66 stars 7 forks source link

Compatibility with eslint-plugin-import #12

Closed oskarer closed 6 years ago

oskarer commented 6 years ago

When doing an import like;

import { rewire$formatNumber, restore } from './utils.js';

eslint-plugin-import is complaining about rewire$formatNumber and restore does not exist in ./utils.js. Is there a way to make this lib make eslint aware of that those functions are available?

asapach commented 6 years ago

Just to confirm, is it import/named rule that is failing?

oskarer commented 6 years ago

@asapach Correct, sorry for not clarifying that!

asapach commented 6 years ago

Does it still complain if you do it like this?

import * as utils from './utils.js';

utils.rewire$formatNumber();
...
utils.restore();
oskarer commented 6 years ago

Nope, that works! It's not covered by the import/named rule.

asapach commented 6 years ago

So will you be fine with using it like that? I think it's a preferred approach for large projects anyway, because you're likely to have multiple modules rewired, and it's easier to distinguish between them:

utils.restore();
services.restore();

You could also try using injector from #8.

oskarer commented 6 years ago

My solution now was doing;

/* eslint-disable import/named */
import {
  rewire$someFunction,
  rewire$anotherFunction,
  restore as restoreSelectors,
} from './utils/selectors';
import {
  rewire$helperFunction,
  restore as restoreHelpers,
} from './utils/helpers';
/* eslint-enable import/named */

The downside of doing import * as is that you don't get tree shaking. However this is not a super big issue in tests so doing your proposed solution will work just fine 👍

asapach commented 6 years ago

Thanks. I'll close the issue then.