Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

chore(rome_js_analyze): noSwitchDeclarations #3917

Merged
merged 1 commit into from
Feb 13, 2023
Merged

chore(rome_js_analyze): noSwitchDeclarations #3917

merged 1 commit into from
Feb 13, 2023

Conversation

Conaclos
Copy link
Contributor

@Conaclos Conaclos commented Dec 1, 2022

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.

@Conaclos Conaclos requested review from leops, ematipico, xunilrj and a team as code owners December 1, 2022 18:22
@netlify
Copy link

netlify bot commented Dec 1, 2022

Deploy Preview for docs-rometools canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 2c49a0a
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/63ea9e24bcfa930008c18c8f

@Conaclos Conaclos changed the title chore(rome_js_analyze): noSwitchDeclarations chore(rome_js_analyze): noSwitchDeclarations Dec 1, 2022
Copy link
Contributor

@MichaReiser MichaReiser left a 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",
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. the rule applies to both any switch clauses (including default one)
  2. 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.

Copy link
Contributor

@ematipico ematipico Dec 19, 2022

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.

Copy link
Contributor Author

@Conaclos Conaclos Dec 19, 2022

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.

@Conaclos
Copy link
Contributor Author

Conaclos commented Dec 5, 2022

@MichaReiser

This rule has overlaps with the UseSingleCaseStatement. What's your recommendation on how these rules should (or should not) co-exist?

I could suggest removing useSingleCaseStatement of the recommended rule set, moving the rule to style. The rule has already some negative user feedbacks.

I could also propose to eventually make useSingleCaseStatement obsolete, and adding an option (disabled by default) to useBlock for requiring a block for every non-empty case/default clause.

@ematipico
Copy link
Contributor

ematipico commented Dec 19, 2022

I could also propose to eventually make useSingleCaseStatement obsolete

We could deprecate useSingleCaseStatement in this release cycle and suggest this new rule. This won't create breaking changes.

@leops
Copy link
Contributor

leops commented Dec 21, 2022

I could also propose to eventually make useSingleCaseStatement obsolete

We could deprecate useSingleCaseStatement in this release cycle and suggest this new rule. This won't create breaking changes.

The useSingleCaseStatement rule has already been moved to the style group and removed from the recommended set in 11.0.0. I don't think we should go as far as deprecating it since its use case (enforce that case clause are wrapped in a block) is somewhat different from what noSwitchDeclaration is enforcing (disallow declarations in case clause), and some users may want to keep both rules enabled.

@Conaclos Conaclos requested review from ematipico and xunilrj and removed request for xunilrj and ematipico January 4, 2023 17:56
Copy link
Contributor

@ematipico ematipico left a 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;

@Conaclos Conaclos added this pull request to the merge queue Feb 13, 2023
Merged via the queue into rome:main with commit 3ddaa4b Feb 13, 2023
@Conaclos Conaclos deleted the no_switch_scoped_declarations branch February 13, 2023 20:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants