Skip to content
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

Rules for cleaning up case from switch statements of variables in an enum #397

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Satyam1749
Copy link
Contributor

@Satyam1749 Satyam1749 commented Feb 27, 2023

This PR contains rule to cleanup any enum entry from all the variables in that enum. In swift, we use switch in enums to populate computed properties. These rules aims to cleanup any enum entry from all such variables.

example:
Before

enum TestEnum {
   case one
   case two
   case three

   var v1: String {
      switch self {
      case .one:
         return "one"
      case .two:
         return "two"
      case .three:
         return "three"
      }
   }
}

After

enum TestEnum {
   case two
   case three

   var v1: String {
      switch self {
      case .two:
         return "two"
      case .three:
         return "three"
      }
   }
}

case one should be cleaned up by a custom rule which needs to belong to group enum_entry_cleanup, This will cleanup entry of case one from var v1.

@Satyam1749 Satyam1749 linked an issue Feb 27, 2023 that may be closed by this pull request
@Satyam1749 Satyam1749 added New Rules A PR that adds new PiranhaRules Swift labels Feb 27, 2023
@ketkarameya
Copy link
Contributor

I guess after #410 is merged, the limitation would no longer exist.
But it also implies that you might have to update the PR to not use the hack.

Copy link
Contributor

@ketkarameya ketkarameya left a comment

Choose a reason for hiding this comment

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

Did my fix in 410 not work?

# var v1: String {
# switch self {
# case .two, .two:
# return "one"
Copy link
Contributor

Choose a reason for hiding this comment

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

We no longer need this right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Rules A PR that adds new PiranhaRules Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add rules for enum cleanup
2 participants