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-11993) Even more Style cops! #9284

Merged
merged 14 commits into from
Mar 9, 2024

Conversation

AriaXLi
Copy link
Contributor

@AriaXLi AriaXLi commented Mar 6, 2024

No description provided.

This commit enables the Style/SelfAssignment cop and fixes 13
autocorrectable fixes.
@AriaXLi AriaXLi requested review from a team as code owners March 6, 2024 23:52
@kenyon
Copy link
Contributor

kenyon commented Mar 7, 2024

typo in PR title

@AriaXLi AriaXLi changed the title (PUP-11993) Even more Syle cops! (PUP-11993) Even more Style cops! Mar 7, 2024
@AriaXLi AriaXLi marked this pull request as draft March 7, 2024 16:57
@AriaXLi AriaXLi force-pushed the PUP-11993/more_style_cops branch 2 times, most recently from e59471b to 21d8383 Compare March 7, 2024 22:40
This commit moves Style/PreferredHashMethods from .rubocop_todo.yml
to .rubocop.yml to indefinitely disable the cop. This is because enabling
this cop causes 11 failures in rb_tree_map_spec.rb that relate to core
functions in trees, like deleting a node and returning nil when a key
can't be found.
acceptance/hosts.yaml Outdated Show resolved Hide resolved
classes.pp Outdated Show resolved Hide resolved
test.patch Outdated Show resolved Hide resolved
testing.pp Outdated Show resolved Hide resolved
Copy link
Contributor

@joshcooper joshcooper left a comment

Choose a reason for hiding this comment

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

I stopped copy/pasting my comment, but it applies to most of these changes. I think rescue ... => e is preferable because it doesn't rely on global state (which isn't thread safe) and it avoids requiring the 'English'.

lib/puppet/file_serving/fileset.rb Outdated Show resolved Hide resolved
lib/puppet/provider/package/ports.rb Outdated Show resolved Hide resolved
lib/puppet/provider/package/portupgrade.rb Outdated Show resolved Hide resolved
lib/puppet/provider/package/rpm.rb Outdated Show resolved Hide resolved
lib/puppet/provider/service/base.rb Outdated Show resolved Hide resolved
lib/puppet/provider/service/daemontools.rb Outdated Show resolved Hide resolved
This commit enables the Style/SpecialGlobalVars cop and fixes
41 (unsafe) autocorrectable offenses. Additionally, this commit
includes => e when rescuing so there is a local reference to the
exception and ERROR_INFO is not needed.
Copy link
Contributor

@joshcooper joshcooper left a comment

Choose a reason for hiding this comment

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

I think these are useful and should be enabled:

  • Style/StringLiteralsInInterpolation - Easy to mix up single and double quotes in interpolated strings. Might be good to enable this
  • Style/StructInheritance - need to update SearchPathElement = Struct.new(:name, :type)
  • Style/SymbolLiteral - hard to remember the rule for when symbols must be quoted
  • Style/SymbolProc - more streamline to say map(&:thing)
  • Style/TrailingCommaInArguments - the presence of trailing commas in arguments gets confusing when there are required keyword arguments
  • Style/TrailingCommaInArrayLiteral - the presence of trailing commas in arrays look like typos
  • Style/UnlessElse - unless [condition] else [condition] is confusing
  • Style/UnpackFirst - more streamline way to get the first array element
  • Style/VariableInterpolation - good to consistently use brackets when interpolating
  • Style/WhileUntilDo - I didn't know do was optional
  • Style/WordArray - using %w[ ] does improve readability

I think we can skip these:

  • Style/StderrPuts - puppet defines a warn method so changing $stderr.puts could break something
  • Style/StringConcatenation - avoiding lots of small string allocations is good, but lots of changes, maybe later
  • Style/StringLiterals - I have a hate/like relationship with single quoted strings. Lots of changes here. Maybe later?
  • Style/SymbolArray - Lots of changes, maybe later?
  • Style/TernaryParentheses - adding parentheses isn't necessarily bad if (a || b) ? c : d)
  • Style/TrailingCommaInHashLiteral - puppet code recommends trailing commas for later diffing
  • Style/TrailingUnderscoreVariable - I think this is a bad cop
  • Style/TrivialAccessors - using attr_reader is good, but I'm not sure how rubocop handles the documentation above the existing method?
  • Style/WhileUntilModifier - seems pedantic
  • Style/WhenThen - I prefer semicolons instead of then
  • Style/YodaCondition - the order doesn't matter in ruby like it does in other languages
  • Style/ZeroLengthPredicate - meh

This commit enables the Style/StructInheritance cop and fixes 5
autocorrectable offenses.
This commit enables the Style/StringLiteralsInInterpolation cop and
fixes 23 autocorrectable offenses.
@AriaXLi
Copy link
Contributor Author

AriaXLi commented Mar 8, 2024

I think these are useful and should be enabled:

* Style/StringLiteralsInInterpolation - Easy to mix up single and double quotes in interpolated strings. Might be good to enable this

* Style/StructInheritance - need to update `SearchPathElement = Struct.new(:name, :type)`

* Style/SymbolLiteral - hard to remember the rule for when symbols must be quoted

* Style/SymbolProc - more streamline to say `map(&:thing)`

* Style/TrailingCommaInArguments - the presence of trailing commas in arguments gets confusing when there are required keyword arguments

* Style/TrailingCommaInArrayLiteral - the presence of trailing commas in arrays look like typos

* Style/UnlessElse - `unless [condition] else [condition]` is confusing

* Style/UnpackFirst - more streamline way to get the first array element

* Style/VariableInterpolation - good to consistently use brackets when interpolating

* Style/WhileUntilDo - I didn't know `do` was optional

* Style/WordArray - using `%w[ ]` does improve readability

I think we can skip these:

* Style/StderrPuts - puppet defines a `warn` method so changing $stderr.puts could break something

* Style/StringConcatenation - avoiding lots of small string allocations is good, but lots of changes, maybe later

* Style/StringLiterals - I have a hate/like relationship with single quoted strings. Lots of changes here. Maybe later?

* Style/SymbolArray - Lots of changes, maybe later?

* Style/TernaryParentheses - adding parentheses isn't necessarily bad `if (a || b) ? c : d`)

* Style/TrailingCommaInHashLiteral - puppet code recommends trailing commas for later diffing

* Style/TrailingUnderscoreVariable - I think this is a bad cop

* Style/TrivialAccessors - using `attr_reader` is good, but I'm not sure how rubocop handles the documentation above the existing method?

* Style/WhileUntilModifier - seems pedantic

* Style/WhenThen - I prefer semicolons instead of `then`

* Style/YodaCondition - the order doesn't matter in ruby like it does in other languages

* Style/ZeroLengthPredicate - meh

Thank you, this is incredibly helpful! The comments help a lot on how you determine what's a helpful cop and what isnt.

This commit enables the Style/SymbolLiteral cop and fixes 1
autocorrectable offense.
This commit enables the Style/SymbolProc cop and fixes 125
(unsafe) autocorrectable offenses.
This commit enables the Style/TrailingCommaInArguments cop and fixes
17 autocorrectable offenses.
This commit enables the Style/TrailingCommaInArrayLiteral cop and
fixes 16 autocorrectable offenses.
This commit enables the Style/UnlessElse cop and fixes 13
autocorrectable offenses.
This commit enables the Style/UnpackFirst cop and fixes 5
autocorrectable offenses.
This commit enables the Style/VariableInterpolation cop and fixes
1 autocorrectable offense.
This commit enables the Style/WhileUntilDo cop and fixes 24
autocorrectable offenses.
This commit enables the Style/WordArray cop and fixes 41
autocorrectable offenses.
@AriaXLi AriaXLi marked this pull request as ready for review March 8, 2024 21:43
@AriaXLi AriaXLi requested a review from a team as a code owner March 8, 2024 21:43
@joshcooper
Copy link
Contributor

jenkins please test this

@joshcooper joshcooper merged commit 500c601 into puppetlabs:main Mar 9, 2024
15 checks passed
@AriaXLi AriaXLi deleted the PUP-11993/more_style_cops branch March 11, 2024 15:53
@joshcooper joshcooper added the maintenance Maintenance chores are excluded from changelogs label Apr 5, 2024
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.

3 participants