-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(eslint-plugin): [no-var-requires, no-require-imports] allow option #7710
Merged
JoshuaKGoldberg
merged 5 commits into
typescript-eslint:main
from
Josh-Cena:no-var-requires-package-json
Jan 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc3c317
feat(eslint-plugin): [no-var-requires, no-require-imports] allowPacka…
Josh-Cena 1fca381
Merge branch 'master' into no-var-requires-package-json
Josh-Cena 3f67961
Use allow option
Josh-Cena 449beae
Update snap
Josh-Cena b77f61d
Fix test
Josh-Cena File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I've also seen libraries want to import from
turbo.json
,project.json
, etc. Maybe this should be the standard format from #6017, with docs showing how to use it forpackage.json
files? WDYT?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.
I'm okay with that. What's your proposed API? My thought is something similar to
no-restricted-imports
, with an array ofpaths
.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.
I was thinking the exact format from #4436 -> https://typescript-eslint.io/rules/prefer-readonly-parameter-types.
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.
This looks couunterintuitive as a user, TBH. This API is for types, but what is
"package.json"
as a type? What doessource: "file"
even mean? Withno-restricted-imports
, the API would look like: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 happens if they want to import from a node module, e.g.
import emojis from "emojilib/dist/emoji-en-US.json"
? Should we just have astring[]
as the option to capture all those cases? Feels off to me that we have the big thought-out format and then don't use it... but it is overhead, yes. 🤔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.
ping @Josh-Cena ?
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.
Sorry, I did not forget this 😅 Will try to garner some energy and clear my notifications this afternoon.
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.
@JoshuaKGoldberg I thought about it. Here are my thoughts:
require
. It doesn't change anything aboutimport
—they can still be used as normal.no-restricted-imports
.string[]
as an option. You mean{ ignorePaths: string[] }
? My initial design is{ ignorePaths: TheOptionsOfNoRestrictedImports }
, i.e. it supports multiple ignore paths, each one with a path, a glob, a custom message, etc. But I now think that's hugely unnecessary for an ignore option. So sure, I can do that../foo/data.json
andfoo/data.json
. That means the option has to be more granular than astring[]
; it would at minimum need to be{ ignorePaths: { paths: string[] /* globs */, patterns: string[] /* regexes */ }
. Does that make sense? Am I overthinking it?I'm very curious what your current idea for the option's shape is.
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.
The intent of #6017 was: "RFC: Common format to specify a type or value as a rule option". I was really hoping it'd be usable for situations exactly like this one. But if we're seeing a practical shortcoming of the format -it being too heavy-handed- then I like this as a motivation to improve it. Or maybe it's just irrelevant here...
Maybe just
allow: string[]
orignore: string[]
, where each of the string elements is a regex for now - and only if users ask we expand to that format? It'd be a little verbose to have to say something like"package\.json$"]
, but not the worst thing in the world IMO.Thinking on the sticking point of relativity: from what I can think of either:
package.json
imports (/[.\\\/]*package.json/
)I think having two things to think about, like
paths
andpatterns
from 4., would be a bit much. Is there anything that can only be captured in that system, not the single option?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.
The complicated thing is that sometimes you have tsconfig paths which make things look non-relative. We can't build in any specific assumptions around the path here if we want people to allow local but disallow node_module packages done this way.
So a regex is probably the most flexible option for this so codebases can easily devise some regex that matches their usecase. I'd suspect that most codebases would just want something like you suggested joshg to allow a relative package.json