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

Layout Cops #9203

Merged
Merged

Conversation

mhashizume
Copy link
Contributor

This is the final PR in this series for enabling and resolving Rubocop Layout cops.

This commit enables the Rubocop Layout/SpaceAfterNot cop and addresses
all offenses.
This commit enables the Rubocop Layout/SpaceAfterSemicolon cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceAroundBlockParameters cop
and addresses all offenses.
This commit enables the Rubocop
Layout/SpaceAroundEqualsInParameterDefault cop and addresses all
offenses.
This commit enables the Rubocop Layout/SpaceAroundKeyword cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceAroundMethodCallOperator cop
and addresses all offenses.
The Puppet::Pops::Validation::Diagnostic#== method triggers multiple
Rubocop Layout offenses. Despite that, it's unclear if there is another
way to format the method to improve readability.

This commit disables all Rubocop Layout cops on this method.
This commit enables the Rubocop Layout/SpaceAroundOperators cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceBeforeBlockBraces cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceBeforeBrackets cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceBeforeComma cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceBeforeFirstArg cop.
This commit enables the Rubocop Layout/SpaceBeforeSemicolon cop and
addresses all offenses.
Prior to this commit, the lexer used arrays of sequential characters
(0-9, a-z, A-Z) by explicitly naming each character in the array (e.g.
"['0', '1', '2']").

This commit simplifies those arrays to use ranges (e.g. "('0'..'9')")
instead.
This commit enables the Rubocop Layout/SpaceInsideArrayLiteralBrackets
cop and addresses all offenses.
This commit enables the Rubocop Layout/SpaceInsideBlockBraces cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceInsideHashLiteralBraces cop
and addresses all offenses.
This commit enables the Rubocop Layout/SpaceInsideParens cop and
addresses all offenses.
This commit enables the Rubocop
Layout/SpaceInsidePercentLiteralDelimiters cop and addresses all
offenses.
This commit enables the Rubocop Layout/SpaceInsideRangeLiteral cop and
addresses all offenses.
This commit enables the Rubocop Layout/SpaceInsideReferenceBrackets cop
and addresses all offenses.
This commit enables the Rubocop Layout/SpaceInsideStringInterpolation
cop and addresses all offenses.
This commit enables the Rubocop Layout/TrailingEmptyLines cop and
addresses all offenses.
This commit enables the Rubocop Layout/TrailingWhitespace cop and
addresses all offenses.
@mhashizume mhashizume force-pushed the PUP-11768/main/layout-and-cops-6 branch from e46b5ba to 6cb3b8c Compare January 9, 2024 18:46
@mhashizume mhashizume marked this pull request as ready for review January 9, 2024 18:48
@mhashizume mhashizume requested review from a team as code owners January 9, 2024 18:48
@mhashizume
Copy link
Contributor Author

Note that I've punted on one cop here, Layout/LineLength. I generally think it would be good to have some kind of warning or check for line length since there are some especially egregious offenders (the longest I found was almost 600 characters long), but it would be pretty involved to implement that cop.

@mhashizume mhashizume added the maintenance Maintenance chores are excluded from changelogs label Jan 10, 2024

[ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].each do |c|
('0'..'9').each do |c|
Copy link
Contributor

Choose a reason for hiding this comment

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

More thinking out loud, are there perf implications to this? We generally have to be careful about changes to the lexer, even simple things like referencing an instance variable vs a local variable. It might be worth creating a sample test and running it in benchmark-ips with JRuby 9.4 and see if there's any appreciable difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Running the benchmark here:

it "lexer2", :profile => true do
lexer = Puppet::Pops::Parser::Lexer2.new
m = Benchmark.measure {10000.times {lexer.string = code; lexer.fullscan }}
puts "Lexer2: #{m}"
end

The performance seems comparable between this branch and main, both with MRI and JRuby:

Environment Results
MRI 3.2.2, main Lexer2: 0.245682 0.016103 0.261785 ( 0.264757)
MRI 3.2.2, PUP-11768/main/layout-and-cops-6 Lexer2: 0.242654 0.014749 0.257403 ( 0.261339)
JRuby 9.4.3.0,main Lexer2: 2.540000 0.040000 2.580000 ( 0.799291)
JRuby 9.4.3.0, PUP-11768/main/layout-and-cops-6 Lexer2: 2.380000 0.030000 2.410000 ( 0.766099)

@@ -305,7 +305,7 @@ def self.needs_ensure_retrieved

validate do
if @parameters[:logonpassword] && @parameters[:logonaccount].nil?
raise Puppet::Error.new(_"The 'logonaccount' parameter is mandatory when setting 'logonpassword'.")
raise Puppet::Error.new(_("The 'logonaccount' parameter is mandatory when setting 'logonpassword'."))
Copy link
Contributor

Choose a reason for hiding this comment

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

ah that was a bug!

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.

Tentative approval based on the outcome of the lexer changes

@joshcooper joshcooper merged commit 050c7b4 into puppetlabs:main Jan 17, 2024
10 checks passed
@mhashizume mhashizume deleted the PUP-11768/main/layout-and-cops-6 branch January 19, 2024 22:41
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