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

Condition can be a single instruction #28

Open
retailcoder opened this issue Nov 13, 2014 · 4 comments
Open

Condition can be a single instruction #28

retailcoder opened this issue Nov 13, 2014 · 4 comments

Comments

@retailcoder
Copy link
Member

[Suggestion]

When an If block contains only a single instruction, recommend making it a single instruction:

If condition Then
    instruction
End If

Can be written as:

If condition Then instruction

Related: #25 If block body can be on separate line

@retailcoder retailcoder added this to the Code Inspections milestone Nov 13, 2014
@rubberduck203
Copy link
Member

When configuring, I believe #25 and #28 are mutually exclusive. Otherwise, you "correct" the code only to receive another warning. That's confusing for an end user.

@retailcoder
Copy link
Member Author

Not sure. Suggestions are, after all, suggestions. ReSharper does that too - it can suggest to use explicit type declaration on a var declaration, and then to use implicit type declaration; it's up to the user to determine which is best in that context... although making them mutually exclusive can help enforce consistency; let's make all code inspections enabled by default, and let the user configure them and determine which one(s) to deactivate.

@retailcoder
Copy link
Member Author

This inspection + quickfix requires implementing a specialized If block analyzer.

retailcoder added a commit that referenced this issue Feb 10, 2016
sync with merged PR's in main repo
@ThunderFrame
Copy link
Member

meh, I don't like single line If statements in VBA.

You could take this inspection further and create inline If Else statements, but I like those even less.

  • They make eyeballing the code more difficult, you have to check the entire If statement to check it is/isn't an inline If.

  • Adding a second statement to the If, requires multiple operations, whereas a block If just requires a carriage return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants