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 #11957] Add cop Lint/ExplicitPublicAccessModifier #12974

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

Conversation

yoshiyoshiharu
Copy link

@yoshiyoshiharu yoshiyoshiharu commented Jun 8, 2024

Fix #11957

This PR adds a Lint/ExplicitPublicAccessModifier.
It warns explicit usage of public which might be surprising for developers accustomed to placing private methods at the bottom of a class.


  • 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.

@yoshiyoshiharu yoshiyoshiharu marked this pull request as draft June 8, 2024 08:34
@yoshiyoshiharu yoshiyoshiharu force-pushed the add-explicit-public-access-modifier-cop branch 3 times, most recently from 1ccb963 to 3584b09 Compare June 9, 2024 04:10
This commit adds a `Lint/ExplicitPublicAccessModifier` cop.

It warns explicit usage of `public` which might be surprising for developers accustomed
to placing private methods at the bottom of a class.
@yoshiyoshiharu yoshiyoshiharu force-pushed the add-explicit-public-access-modifier-cop branch from 3584b09 to 6cba5a2 Compare June 9, 2024 06:19
@yoshiyoshiharu yoshiyoshiharu marked this pull request as ready for review June 9, 2024 06:27
@koic
Copy link
Member

koic commented Jun 10, 2024

The bad case described in the example of this PR can already be detected by Lint/UselessAccessModifier, so I have concerns about the necessity of providing this new cop.

      #   class Test
      #     public
      #
      #     def test; end
      #   end

https://docs.rubocop.org/rubocop/1.64/cops_lint.html#lintuselessaccessmodifier

@yoshiyoshiharu
Copy link
Author

yoshiyoshiharu commented Jun 13, 2024

@koic
Thank you for having a look!
As mentioned in #11957, using the public access modifier below the private access modifier doesn't be warned.
ClassStructure may detect this; However, if it is disabled (which is default setting), the following example will not be detected.

      #   # bad
      #   class Test
      #     private
      #
      #     def private_method;
      #
      #     public
      #
      #     def public_method; end
      #   end

@yoshiyoshiharu yoshiyoshiharu changed the title [Fix #11957] Add cop Lint/ExplicitPublicAccessModifier [Fix #11957] Add cop Lint/ExplicitPublicAccessModifier Jun 13, 2024
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.

Flag explicit public access modifier usage
2 participants