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

RD should have inspection for Enum Type value is assigned without Enum member reference #2255

Open
ThunderFrame opened this issue Sep 30, 2016 · 1 comment
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Milestone

Comments

@ThunderFrame
Copy link
Member

Types declared as Enum should be assigned with Enum members and not with literal values or ambiguous member return values.

Option Explicit

Private Enum foo
  useprod = 1
  UseDev = 2
  UseUAT = 4
End Enum

Sub foo()
  Dim f As foo

  'Explicit assignments without member reference
  'This code uses the Enum, and depends upon 2 being a valid member
  f = 2
  f = GetAmbiguousFoo

  'Should be something like
  f = UseUAT
  'Or...
  f = useprod Or UseUAT
  'Or...
  f = GetFoo

End Sub

Private Function GetFoo() As foo
  GetFoo = UseUAT
End Function

Private Function GetAmbiguousFoo() As Long
  GetAmbiguousFoo = UseUAT
End Function
@ThunderFrame
Copy link
Member Author

If this inspection does end up being at the Enum member level, then it will need to consider Aliases and/or bitwise usages.

Private Enum foo
  useprod = 1
  UseDev = 2
  UseUAT = 4
  UseProduction = useprod
  UseProdOrDev = useprod Or useDev
End Enum

If UseProduction is used in consuming code, but useprod is never used outside of the Enum, then UseProduction could be removed, but only if usage of UseProduction was changed to use useprod

If neither useprod nor usedev are used in consuming code, but UseProdOrDev is used, then neither useprod nor usedev are necessarily removable.

@Vogel612 Vogel612 added enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. and removed feature-request labels Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Projects
None yet
Development

No branches or pull requests

2 participants