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

Support AllowComments option for Style/EmptyElse #10790

Merged

Conversation

ydah
Copy link
Member

@ydah ydah commented Jul 6, 2022

This PR is support AllowComments option for Style/EmptyElse.
The default for this option is false.

In the case of complex conditional statements, we may want to leave else empty or nil and write only the explanation of the else case in the comments.

AllowComments: true will not treat when else as offense if the else with an intentional comment.

@example AllowComments: false (default)

# bad
if condition
  statement
else
  # something comment
  nil
end

# bad
if condition
  statement
else
  # something comment
end

@example AllowComments: true

# good
if condition
  statement
else
  # something comment
  nil
end

# good
if condition
  statement
else
  # something comment
end

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • [-] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@ydah ydah force-pushed the support_enforced_style_comment_for_empty_else branch from 0605a44 to 5b368e3 Compare July 6, 2022 00:41
SupportedStyles:
- empty
- nil
- both
- comment
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps allow_comment would be a better name here? Thinking more about this - probably this shouldn't be a style but rather an option AllowComments that affects all styles.

Copy link
Collaborator

Choose a reason for hiding this comment

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

(false by default)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you very much. I changed to the AllowComments option. I think this is better too.

This PR is support `AllowComments` option for `Style/EmptyElse`.
The default for this option is false.

In the case of complex conditional statements,
we may want to leave `else` empty or nil and
write only the explanation of the `else` case in the comments.

`AllowComments: true` will not treat when `else` as offense
if the `else` with an intentional comment.

### @example AllowComments: false (default)

```ruby
# bad
if condition
  statement
else
  # something comment
  nil
end

# bad
if condition
  statement
else
  # something comment
end
```

### @example AllowComments: true

```ruby
# good
if condition
  statement
else
  # something comment
  nil
end

# good
if condition
  statement
else
  # something comment
end
```
@ydah ydah force-pushed the support_enforced_style_comment_for_empty_else branch from 5b368e3 to 6f9bc56 Compare July 10, 2022 23:25
@ydah ydah changed the title Support EnforcedStyle: comment option for Style/EmptyElse Support AllowComments option for Style/EmptyElse Jul 10, 2022
@ydah ydah changed the title Support AllowComments option for Style/EmptyElse Support AllowComments option for Style/EmptyElse Jul 10, 2022
@bbatsov bbatsov merged commit 4c4b91e into rubocop:master Jul 11, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 11, 2022

Thanks!

@ydah ydah deleted the support_enforced_style_comment_for_empty_else branch July 11, 2022 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants