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

(PUP-11771) Rubocop Naming Cops #9183

Merged
merged 16 commits into from
Dec 19, 2023

Conversation

mhashizume
Copy link
Contributor

This PR comprises commits to address Rubocop naming cops and associated issues.

The private method is_module_package? was only ever referenced by code
that was removed in 2014 by 3f05274. Because this method is both private
and not referenced anywhere else in the code base, this commit removes
the is_module_package? method.
Heredoc delimiters do not bring much value and would involve a lot of
work to change existing delimiters. This commit disables the Rubocop
Naming/HeredocDelimiterNaming cop.
The Naming/MethodParameterName Rubocop cop is fairly arbitrary. This
commit disables it.
Disable the Naming/ClassAndModuleCamelCase Rubocop cop on existing
violations, as class names are public by default and updating them could
be a breaking change. Enable this cop for new code to catch any future
violations.
Disable the Naming/ConstantName Rubocop cop on existing violations, as
those constants may be public and updating them could be a breaking
change. Enable this cop for new code to catch any future violations.
@mhashizume mhashizume force-pushed the PUP-11771/main/rubocop-naming branch 2 times, most recently from 89b793a to 8ef4974 Compare December 12, 2023 00:29
Because renaming memoized instance variables can be potentially
dangerous, to address the Rubocop Naming/MemoizedInstanceVariableName
cop, this commit excludes existing violations while enabling the cop for
new code.
Pops implements the visitor pattern and that relies on the convention of
methods being namedoperation_Class. This commit excludes
puppet/functions, puppet/pops, and puppet/util/windows from the Rubocop
Naming/MethodName cop.

Additionally, this commit updates the rpm_compareEVR methods in both
Puppet::Util::Package::Version::Rpm and Puppet::Util::RpmCompare to
instead be called rpm_compare_evr to adhere to snake case.
This commit disables the Rubocop Naming/RescuedExceptionsVariableName
cop, as the cost of updating all of the existing violations outweighs
the benefits of those changes.
This commit enables the Rubocop Naming/VariableName cop while excluding
files that had been previously excluded (some Windows code that
intentionally follows Microsoft's Hungarian notation).

New code will be subject to this cop.
This commit disables the Rubocop Naming/VariableNumber cop. This check
affects too much of our existing codebase and the cost of correcting
potential violations outweighs the benefits of enabling this cop.
This commit disables the Rubocop Naming/BinaryOperatorParameterName
cop, as its violations are too far-reaching in our codebase to safely
and easily fix.
This commit enables the Rubocop Naming/BlockParameterName cop.
This commit moves the Rubocop Naming/AccessorMethodName cop from the
todo file to the .rubocop configuration file. This does not change any
behavior but indicates that this behavior is known and intentional.
The is_constant_defined? method was added in 3d43d86 to account for
behavior differences between Ruby 1.8 and 1.9. It was simplified in
84a9cb8 as part of removal Ruby 1.8 support and the method exists now as
a fairly transparent wrapper of Ruby's built-in Module#const_defined?
method.

is_constant_defined? has been marked as private since 79889af in 2013.

This method removes the is_constant_defined? method and substitutes it
with Module#const_defined? instead.
@mhashizume mhashizume force-pushed the PUP-11771/main/rubocop-naming branch 2 times, most recently from 550bd2e to 60e143d Compare December 12, 2023 00:51
@mhashizume mhashizume marked this pull request as ready for review December 12, 2023 00:52
@mhashizume mhashizume requested review from a team as code owners December 12, 2023 00:52
@mhashizume mhashizume closed this Dec 12, 2023
@mhashizume mhashizume reopened this Dec 12, 2023
@mhashizume
Copy link
Contributor Author

@joshcooper Thanks for the review, I've reverted the issues you've flagged

@joshcooper
Copy link
Contributor

joshcooper commented Dec 14, 2023

Ah sorry, the Naming/PredicateName cop is confusing... I was hoping to keep the is_XXX? and has_XXX? methods as is. But if there's a private is_XXX/has_XXX method, then renaming/appending ? sounds good. And if the method is public, then skip the cop like you're doing. I think what I'm looking for can be done with this config and then taking into account whether the method is private:

Naming/PredicateName:
  ForbiddenPrefixes: []

@mhashizume
Copy link
Contributor Author

@joshcooper Gotcha, I think I understand now. I've updated my commit with your suggestions. Let me know if I can make any other changes.

This commit addresses the Rubocop Naming/PredicateName cop by either
exempting public methods with predicate names or renaming private
methods.
@mhashizume mhashizume added the maintenance Maintenance chores are excluded from changelogs label Dec 18, 2023
@joshcooper joshcooper merged commit 554eb96 into puppetlabs:main Dec 19, 2023
10 checks passed
@mhashizume mhashizume deleted the PUP-11771/main/rubocop-naming branch December 19, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance chores are excluded from changelogs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants