-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
Add import-style
rule
#232
Conversation
no-direct-import
ruleno-direct-import
rule
This rule accepts options: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/rules/catch-error-name.js See the |
The rule should support enforcing destructuring and using default import, as commented in #211 (comment) So I think the rule needs a better name. It can't have the
|
how about prefer-default-import ? @sindresorhus |
How about |
The How about just |
Another problem is how can I work for the inverse part, can I take an input from user where he will input something like |
Import-style sounds good to me, |
Specifier is the left-hand side. In case of a |
I just Google'd "javascript import specifier" and all the sources claim it's the right part, like: https://nodejs.org/api/esm.html#esm_url_based_paths |
Alright, let's go with |
The rule should accepts an options-object like this: {
defaultExport: [
'path',
'chalk'
],
namedExport: [
'util',
'lodash',
'underscore'
]
} With the above being the default. |
@futpib Or do you think we should do it like this so it's easier to override individual entries? {
defaultExport: {
path: true,
chalk: true
},
namedExport: {
util: true,
lodash: true,
underscore: true
}
} |
I went with what astexplorer and estree call import specifier, and it's the same in the standard. Ok, this is too confusing for a rule name. |
Yes, I prefer the object variant. Would be consistent with what I chose in #237 |
👍, let's go with the object variant. |
Ok thanks, I will come up with a commit soon. |
I'm stuck on how to pass the configurations, I am working in AST Explorer How do I pass options here? @futpib @sindresorhus |
@gurungrahul2 Not sure if you can. But you can hardcode them for testing and remove when you are ready to commit the code. |
What would having something like
mean? |
@gurrrung We are basically modelling a set of strings in JSON here. The benefit of this design is that users can override the build-in defaults. We could merge the user-supplied option with the default one (for example with |
@gurrrung Still interested in finishing this? |
Yes, I'm on it. |
Why would Integration tests blow up. 😕 |
@fisker Would you be able to help review this? |
errors: [buildError({moduleName: 'util', type: 'defaultImport'})] | ||
}, | ||
{ | ||
code: 'const foo = myFunction(\'util\')', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! Thanks for the review. I was a little busy in academic work. Yeah, it shouldn't be error, I'll add the check to throw error only in case of require()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the result of
const promisify = require('utils').promisify;
and dynamic import
(async () => {
const lodash = (await import('lodash')).default;
})();
(async () => {
const {default: lodash} = await import('lodash');
})();
(async () => {
const {chunk} = await import('lodash');
})();
we should add them to tests
Should we also check export {chunk} from 'utils';
export * as default from 'utils';
export {default as default} from 'lodash';
export {default as lodash} from 'lodash';
export * from 'lodash'; |
that's brilliant. I really couldn't thing of this. Can you give me more insight like what should be the behaviour? |
@fisker ^ |
@gurrrung Still interested in finishing this? |
@gurrrung const promisify = require('utils').promisify; I mean we need add test, make sure this pass. (async () => {
const lodash = (await import('lodash')).default;
})();
(async () => {
const {default: lodash} = await import('lodash');
})();
(async () => {
const {chunk} = await import('lodash');
})(); I'm not sure should we support dynamic import?
I suggest we should support |
Nah, not worth the effort. For all our rules, we can stay with the top-level imports.
Agreed |
Closing for lack of activity. |
Fixed #211
Things Done: