-
-
Notifications
You must be signed in to change notification settings - Fork 19
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 option for no-rename-default to exclude some modules #136
Comments
That's a fair point, which is why this rule is included in the "warning" presets. As for
IMHO, it is not a good idea to manually configure for every module that publishes minified dist. |
@meteorlxy How about we proceed this way: Ignore all Three characters provide 199,888 (52 * 62 * 62) possible mangled exports, which is more than sufficient for most modules as they won't have that many exports in one file or chunk. If they do, I chose three characters because two characters only yield 3,224 (52 * 62) possible mangled exports, a number that some icon libraries might easily surpass. However, this introduces another issue: there are popular libraries, such as xo and mem, which have names shorter than three characters, and we want to validate them too. What do you think? |
Rather than hardcode length, is it possible to detect minified modules? Could we make the assumption that a module is minified if there are no newlines in it? |
What about comments then? webpack retains license comments by default even when minified is enabled. And webpack won't hoist those comments either. |
Thus, ignoring exports based on char length it not ideal.
We'd better not rely on those assumptions:
In fact, minified module is only one of the use case of the rule options. It's always better to provide an option for users to configure this rule in a fine-grained manner:
For example, it could be nice to have something like this: {
'import/no-rename-default': [
'warn',
{
modules: [
['markdown-it-anchor', { ignore: true }], // ignore default export name checking
['markdown-it-anchor', { override: 'markdownItAnchor' }], // override default export name to markdownItAnchor
],
},
],
} Don't think it too verbose. You can't imagine how users want to configure rules for large-scale projects. |
It is a common practice to publish minified dist to npm. I personally published more than 20 npm packages that have their dist minified. Explicit configuring all of them is definitely not an option. |
@Zamiell @meteorlxy I have an idea. We could add an option here, and we could only apply this rule for internal modules, not dependencies. |
@SukkaW I think this rule should have a whitelist in exactly the same way as the whitelist that I added here: #142 However, with that said, in my PR here, you said that we should hold off and that it was related to a whitelist. I do not think that is true. Regardless of whether a module is internal or external, if the export is specifically named "default" or "index", then it is obviously a mistake for Thus I think for now we should hard whitelist these two names, and then offer consumers of the ESLint rule the option for further customization. |
The same would apply to any minified or mangled name. It doesn't mean we have to add every word combination with a length of less than three to the whitelist. Also, the last thing I want is for someone to claim they intentionally exported |
This is just my opinion, but I could see some codebases having 3 letter exports that are not minified. Like "car" or "dog" or "cat". Thus I think it is dangerous to whitelist all 3 letter names. However, I think that "default" and "index" belong in a separate category - it is much less likely that those would ever be intended by the author. Why? Because both of these words have specific meanings in JavaScript. |
I support this. This option alone would be a huge improvement for the rule. Ideally it should also support monorepos setups though: in a monorepo, internal package A imports internal package B. But B comes from |
I am against that. You are already using monorepo and separating A and B into two packages. Now A and B are isolated from each other, they behave like npm packages from the package's perspective of view. And if we ignore packages from the current monorepo, what happens if you mangle A's exports |
My point was that while developing in a monorepo, the internal packages will not be minified (it depends on how you setup your environment of course, but that would be counterproductive and wasteful), so they can be linted by the rule. |
This is not true. You'd most likely (and should) import the dist of other packages (instead of their src). So it is actually possible (and most likely) to encounter mangled exports even inside the monorepo. |
Some 3rd party modules may minify the released files. It would be helpful to add an option to exclude those modules manually.
For example, markdown-it-anchor:
Any thoughts? @SukkaW
The text was updated successfully, but these errors were encountered: