-
Notifications
You must be signed in to change notification settings - Fork 659
chore(rome_js_analyze): noSwitchDeclarations
#3917
Conversation
✅ Deploy Preview for docs-rometools canceled.Built without sensitive environment variables
|
noSwitchDeclarations
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 rule has overlaps with the UseSingleCaseStatement
. What's your recommendation on how these rules should (or should not) co-exist?
/// | ||
pub(crate) NoSwitchDeclarations { | ||
version: "11.0.0", | ||
name: "noSwitchDeclarations", |
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's your reasoning for using the name noSwitchDeclaration
over ESLint's name?
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 rule applies to both any switch clauses (including default one)
- It is not really declarations at the scope of case/default that are prohibited: it is at the scope of the switch
I first renamed to noSwitchScopedDeclarations
(alternative could be noSwitchHoistedDeclarations
). And then simplified it to noSwitchDeclarations
.
By the way, I am not sure about the plural form.
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.
By the way, I am not sure about the plural form.
It should be singular, in my opinion. The rule is triggered for discriminant inside the switch
, not for the whole switch
. I would suggest noDeclarationInsideSwitch
, which sounds better to me.
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.
noDeclarationInSwitch
could be more consistent with existing rules? (noAssignInExpressions
, ...)
Or noSwitchClauseDeclarations
?
I personally prefer noSwitchDeclarations
because these declarations are hoisted to the switch scope.
crates/rome_js_analyze/src/analyzers/nursery/no_switch_declarations.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/analyzers/nursery/no_switch_declarations.rs
Outdated
Show resolved
Hide resolved
I could suggest removing I could also propose to eventually make |
We could deprecate |
The |
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.
While it's true that we render diagnostics as part of the documentation, we should also test in our test suite for many reasons:
- diagnostics can be seen as plain text, helping the reviewers;
- they help to catch regression tools - in fact if a rule changes group and we forget to change its group in the testing suite, a snapshot test change is triggered;
Summary
This implements ESLint's no-case-declarations under the name
noSwitchDeclarations
.In contrast to ESLint, this rule handles TypeScript declarations (enum, ...).
Test Plan
Uni test and doc-tests included.