-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
feat: no-restricted-imports support casing #15439
Conversation
|
Hi @gfyoung!, thanks for the Pull Request The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by running Read more about contributing to ESLint here |
dc3b219
to
c1aa87b
Compare
c1aa87b
to
f00f425
Compare
The option makes sense to me 👍, and it would be nice to update the Waiting for more opinions from team members, since this is an enhancement. |
f00f425
to
4e57bc9
Compare
@mdjermanovic: PR has been updated with the requested changes, with tests still passing. 👍 |
This seems reasonable, but before adding new API, I find it helpful to understand the motivation. @gfyoung can you elaborate a bit on what use case you're trying to accomplish with case-sensitive path patterns? |
@btmills: I believe the use case described in the PR description illustrates the motivation. If not, let me know what further information or detail is required. |
@gfyoung the PR description covered a lot of the how but not much of the why. What are you hoping to do with ESLint that you can't today? |
I want to be able to do more granular import restrictions using case-sensitive regular expressions. |
Okay, and what are you hoping to use case-sensitive import restrictions for? |
The example provided in the PR description illustrates a case where I would want to use case-sensitive import restrictions. |
@nzakas: First off, expanding the API for the sake of a theoretical problem would be a waste of time for all of us. I have been waiting to submit this PR for quite some time, as I had to get commits to Without sharing actual code, I thought the example using import * as bots from bots;
import * as botUtils from botUtils; // TODO: all imports should be from `bots` In this case, we want all developers to importing from the |
@gfyoung please understand, we review a lot of PRs, and not all of them are well thought out. We need to ask followup questions and for more examples in order to figure out which ones are worth pursuing and which don’t provide much value to the project. Answering our questions helps a lot, and if the PR description was enough, we wouldn’t ask for more info. |
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.
Looks good, just a couple of suggestions.
Path matching in `.gitignore` can be case-sensitive, and [email protected] supports this as well as maintains support for relative paths, whose support was dropped after 4.0.6 but restored in 5.2.0 (this was a blocker for past upgrades). By default, this rule remains case-insensitive to maintain backwards compatibility with earlier versions. Only by explicitly specifying it in a custom pattern object can it be triggered.
Per member feedback, the allowing of relative paths was not entirely intentional for rules using the `ignore` library. This commit also reverts the utility for creating `ignore` instances.
Per reviewer feedback
734538c
to
aec159f
Compare
@nzakas: I understand the need to request clarification. As a maintainer myself, I can relate to the experience of working through PRs that have not been as well thought out as we would like. That said, suggesting that someone's PR description is a "theoretical problem" before knowing more (e.g., not wanting to divulge actual code) is where some umbrage was taken. IMO prefer to give contributors benefit of the doubt to prove themselves before coming to a conclusion about the PR. Anyhow, I'll leave it at that. Appreciate the feedback so far. 👍 I was able to address one of your feedback points but ran into issues with the other. See my comments in the conversations. |
Question: The |
Yes, that is in part why (it's one of several patches I submitted to the library to make this upgrade here possible). |
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.
LGTM if accepted, thanks!
@gfyoung Im sorry that I didn’t explain well enough. We get a lot of people suggesting rules or changes to rules that are, in fact, theoretical or unlikely enough that it doesn’t make sense to accept. I did not mean to imply that your use case was theoretical, only that we needed more justification. Maintaining all of our rules, and ensuring things like rules don’t contradict each other, takes a lot work, so while we always assume positive intent from contributors (as we did here), we can’t assume that every case should be merged, which is why we asked for more details. |
@btmills do you have the info you need here? |
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.
LGTM, thanks! 💯
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.
LGTM! Thanks for the additional explanation.
Fantastic! Thank you for all the feedback @btmills @mdjermanovic @nzakas 🙏 |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What rule do you want to change?
no-restricted-imports
Does this change cause the rule to produce more or fewer warnings?
By default, the amount of warnings is unchanged. Otherwise, it should be fewer warnings.
How will the change be implemented? (New option, new default behavior, etc.)?
A new option is added, with a default value that maintains backwards-compatibility.
Please provide some example code that this change will affect:
What does the rule currently do for this code?
It will issue warnings for both imports.
What will the rule do after it's changed?
If we add the new option:
The rule will issue a warning ONLY for the second import.
What changes did you make? (Give an overview)
Enhances no-restricted-imports to support more granular import restrictions via case-sensitive pattern matching. By default, this rule remains case-insensitive to maintain backwards compatibility with earlier versions. Only by explicitly specifying it in a custom pattern object (see the added docs) can it be triggered.
Path matching in
.gitignore
can be case-sensitive, and[email protected]
supports this as well as maintains support for relative paths, whose support was dropped after4.0.6
but restored in5.2.0
(this was a blocker for past upgrades).Is there anything you'd like reviewers to focus on?
N/A