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

Fix a false positive for Lint/UselessAccessModifier when using same access modifier inside and outside the included block #11638

Merged
merged 1 commit into from Mar 6, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Feb 28, 2023

This PR is fix a false positive for Lint/UselessAccessModifier when using same access modifier inside and outside the included block.

If an included block is used within a class, as shown below, I think it should not be a violation even if the same access modifier is used inside and outside the included block.

class SomeClass
  included do
    private
    def foo; end
  end
  private
  def bar; end
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 fix-lint_useless_access_modifier branch from 76b2644 to f85371e Compare February 28, 2023 11:27
@ydah ydah changed the title Fix a false positive for Lint/UselessAccessModifier when using same access modifier inside and outside the included block Fix a false positive for Lint/UselessAccessModifier when using same access modifier inside and outside the included block Feb 28, 2023
@ydah ydah force-pushed the fix-lint_useless_access_modifier branch from f85371e to 3a85cb1 Compare February 28, 2023 11:27
@koic
Copy link
Member

koic commented Feb 28, 2023

The included block is a ActiveSupport::Concern's method, right? RuboCop core is for vanilla Ruby. If Rails content will be included in the core, it may be better to include active_support_extensions_enabled? (ActiveSupportExtensionsEnabled config) as a condition.
https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions

Style/HashExcept may be a reference for implementation.

@ydah ydah force-pushed the fix-lint_useless_access_modifier branch from 3a85cb1 to 6bcf0b3 Compare February 28, 2023 13:36
@ydah
Copy link
Member Author

ydah commented Feb 28, 2023

The included block is a ActiveSupport::Concern's method, right? RuboCop core is for vanilla Ruby. If Rails content will be included in the core, it may be better to include active_support_extensions_enabled? (ActiveSupportExtensionsEnabled config) as a condition. https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions

Style/HashExcept may be a reference for implementation.

I was not aware of active_support_extensions_enabled?. Thanks for letting me know about it. I updated this PR.

… access modifier inside and outside the `included` block

This PR is fix a false positive for `Lint/UselessAccessModifier` when using same access modifier inside and outside the `included` block.

If an included block is used within a class, as shown below, I think it should not be a violation even if the same access modifier is used inside and outside the included block.

```ruby
class SomeClass
  included do
    private
    def foo; end
  end
  private
  def bar; end
end
```
@ydah ydah force-pushed the fix-lint_useless_access_modifier branch from 4be47d0 to 0d3c056 Compare March 6, 2023 02:51
@koic
Copy link
Member

koic commented Mar 6, 2023

There may be a better way, but since there are no new parameters added, so there will be no impact on API compatibility. I'm going to merge this PR. Thank you.

@koic koic merged commit 118542b into rubocop:master Mar 6, 2023
@ydah ydah deleted the fix-lint_useless_access_modifier branch March 6, 2023 03:50
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