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 inline visibility definition on checking visibility #11171

Merged
merged 1 commit into from Nov 10, 2022

Conversation

r7kamura
Copy link
Contributor

@r7kamura r7kamura commented Nov 10, 2022

The following patterns have not been supported by RuboCop::Cop::VisibilityHelp#node_visibility:

class A
  private def x
  end
end
class A
  def x
  end
  private :x
end
node_visibility(def_x_node) #=> :public

I think it would be good to support them as well.

The background leading me to this change is as follows:

I am trying to create a Cop that inspects unrecommended visibility of some method definitions. I tried to use the #node_visibility for this implementation, but realized that this would not work as intended in this case if inline style visibility was used. There seemed to be no obvious reason not to support it, so I decided to create this Pull Request.
(FYI: In fact, I'm trying to create a cop that detects some public methods in Rails controller that actually should be private.)

After making the changes, several tests began to fail, so I decided to improve those as well.


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.

@r7kamura r7kamura changed the title Support inline symbol visibility definition on checking visibility Support inline visibility definition on checking visibility Nov 10, 2022
@r7kamura r7kamura force-pushed the feature/visibility-help-inline branch 2 times, most recently from 373b140 to b4c5c2d Compare November 10, 2022 00:54
@r7kamura r7kamura force-pushed the feature/visibility-help-inline branch from b4c5c2d to e246467 Compare November 10, 2022 02:39
@bbatsov bbatsov merged commit 84c480c into rubocop:master Nov 10, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 10, 2022

Good change! This was indeed just an oversight on our part.

@r7kamura r7kamura deleted the feature/visibility-help-inline branch November 13, 2022 23:26
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