-
-
Notifications
You must be signed in to change notification settings - Fork 508
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(lint/noRestrictedImports): add rule #1723
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
CodSpeed Performance ReportMerging #1723 will not alter performanceComparing Summary
|
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 like this rule, but would it be possible to merge this with useImportRestrictions
? It means the logic for the rule should also be put behind a config option, but given the naming I think it would be too confusing to have them both. I think I would call the option for this rule something like bannedModules
if they were combined.
I’m not sure how to put the config inside the rule documentation unfortunately…
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
Btw, we’ve had some discussion in the past about where we want to go with the Unfortunately most of the ideas got blocked on needing project-level analysis (on the roadmap for 2024 now), so only the package private logic ended up being implemented. And there’s no config yet, since we only have one option implemented :) So if you’re okay with adding |
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
/// ```json | ||
/// { | ||
/// "noRestrictedImports": { | ||
/// "options": { | ||
/// "paths": ["lodash"] | ||
/// } | ||
/// } | ||
/// } | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// const lodash = require("lodash"); | ||
/// ``` |
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.
Unfortunately, we don't support setting options in example. We could just document the option. Any idea @ematipico ?
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.
It could be an excellent addition and maybe a good first issue. As for now, we only document the options.
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
8b627ef
to
16e04e9
Compare
16e04e9
to
e34a2c1
Compare
This rule, without options, does nothing. This means that the options are mandatory for this rule, and it is in contrast with all the rules we have. Which means that if I enabled this rule like this: {
"noRestrictedImports": "warn"
} Biome is happy, but the rule is never triggered. I have mixed feelings about creating a rule that only works if options are passed. And our infrastructure/deserialization wasn't designed for this case. I like @arendjr suggestion. We could merge the options/logic of this rule to So here my proposal:
@anonrig @arendjr @Conaclos, how does that sound? @anonrig if you like the idea, would like to take charge of the proposal? |
@ematipico Sounds like a plan! 👍 We may just need to bikeshed a bit about the naming for the |
Always open to bikeshed names! I'm bad at that |
I personally think we should have 1-to-1 correlation when we are migrating existing eslint rules but I'm ok with merging it with another rule as well. |
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 change in the documentation and a nit about the code
crates/biome_js_analyze/src/analyzers/nursery/no_restricted_imports.rs
Outdated
Show resolved
Hide resolved
I have mixed feeling about merging the two rules together. Maybe the name |
e34a2c1
to
ee5a205
Compare
I think this PR is ready to merge. Regarding merging with another rule, we can make that decision later since this is a Nursery linting rule |
Nice, any plan to also support the |
I plan to add this in a future version. |
Adds
no-restricted-imports
rule to Biome.