-
-
Notifications
You must be signed in to change notification settings - Fork 512
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(linter): implement noRestrictedTypes #3585
Conversation
CodSpeed Performance ReportMerging #3585 will degrade performances by 6.22%Comparing Summary
Benchmarks breakdown
|
20bf1dd
to
30cbbd1
Compare
Why can't we just add user options to the old rule with defaults that keep the behavior the same? Is a new rule really necessary? |
I think the idea is that we need to rename the rule to be more consistent with other rules |
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 think that we should follow the lead of TypeScript ESLint that decided to split no-banned-types
into several rules. For now, we could keep noBannedTypes
to ban types like Boolean
, and we could dedicate noReswtrictedTypes
to user-defined types. This will simplify the rule impl and make it more consistent with other noRstricted*
rules.
crates/biome_js_analyze/src/lint/nursery/no_restricted_types.rs
Outdated
Show resolved
Hide resolved
message: String, | ||
fix_with: Option<String>, |
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.
We could make the message optional and generate a default message such as Use <fix_with> type instead
.
Also, I could rename fix_with
with use
.
message: String, | |
fix_with: Option<String>, | |
message: Option<String>, | |
use: Option<String>, |
We could add a validation state that ensures that use
is a valid identifier (a function js_ident
allows checking it) and at least one field is specified (either message
, or use
, or both).
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 renamed the field, not sure about making message
field optional, banning types should be very intentional action and default explanation would not be helpful for other people.
I would like to make option to accept string directly like this
type Options = {
foo: string | { message: string }
}
Though I am not sure how to do that with Serde
crates/biome_js_analyze/src/lint/nursery/no_restricted_types.rs
Outdated
Show resolved
Hide resolved
@minht11 do you need any help to land this PR? |
@ematipico Sorry been bit distracted, will fix up this PR this week. |
It does make sense. Looking into typescript-eslint 8 docs now I see they made this rule only for custom types, when I originally implemented this rule I was referencing ts-eslint 7. I will remove default banned types and leave that functionality for |
ccf4dba
to
1a0271c
Compare
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 to me. I left last suggestions. Once addressed we can merge 🚀
Summary
Closes #3583 Rule allows user to specify types which they want to prevent used in their code. Similar to
noRestrictedGlobals
andnoRestrictedImports
Test Plan
Added snapshots