Add a ruby linter - standardrb (and apply automated fixes)#431
Open
nyourchuck wants to merge 3 commits into
Open
Add a ruby linter - standardrb (and apply automated fixes)#431nyourchuck wants to merge 3 commits into
nyourchuck wants to merge 3 commits into
Conversation
jcoyne
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the
standardrbgem and and applies all safe and unsafe automated fixes. It does not enforce running the linter on CI or other actions.The unsafe changes below are mechanical, behavior-preserving transformations
applied by StandardRB. None alter program logic, control flow, or output.
app/admin/rooms.rb
"#{room.sessions.size}" -> room.sessions.size.to_s
Style/RedundantStringEscapeSequence: String interpolation that wraps a
single expression with no surrounding text is redundant. Calling .to_s
directly is clearer and produces the identical string.
app/controllers/application_controller.rb
current_participant_session && current_participant_session.participant
-> current_participant_session&.participant
Style/SafeNavigation: The safe navigation operator (&.) is a shorthand
for the "call method if receiver is not nil" pattern. When the left side
is nil, &. returns nil - identical to the short-circuit && behavior here.
app/controllers/participants_controller.rb
Moved
redirect_to root_pathafter the if/else block.Style/DuplicateBranch (or similar): Both branches of the if/else ended
with
redirect_to root_path. Extracting the common call after theconditional removes duplication. The redirect happens unconditionally
either way, so behavior is identical.
app/helpers/schedules_helper.rb
sessions[split..-1] -> sessions[split..]
Style/EndlessRange:
split..is an endless range, equivalent tosplit..-1when used as an array slice index. Introduced in Ruby 2.6,it is the preferred modern idiom and produces the same subarray.
app/models/event.rb
slots.sort_by(&:starts_at).first -> slots.min_by(&:starts_at)
Performance/SortReverse (or similar): sort_by(...).first sorts the
entire collection O(n log n) just to pick the minimum. min_by does a
single O(n) pass. Both return the element with the smallest starts_at.
config/environments/production.rb
STDOUT -> $stdout
Style/GlobalStdStream: STDOUT is a constant bound to the original IO
object and cannot be reassigned. $stdout is the global variable that
Ruby's built-in methods (puts, print) actually use, and it can be
redirected (e.g. for testing/capture). Using $stdout ensures the logger
respects any output redirection. Same value under normal operation.
lib/scheduling/context.rb
"..." + "..." -> "..." \ "..."
Style/LineEndConcatenation: When two string literals are separated only
by a line break, Ruby can concatenate them at parse time using a
backslash continuation. This avoids a runtime + method call and is the
standard style for breaking long strings across lines. Produces the
same string.
lib/scheduling/schedule.rb
"..." + "..." -> "..." \ "..."
Same rule as lib/scheduling/context.rb (Style/LineEndConcatenation).
Backslash continuation replaces runtime string concatenation with
compile-time joining. Identical output.
lib/scheduling/session_set.rb
@superset.add(session_id) if @superset -> @superset&.add(session_id)
Style/SafeNavigation: Same transformation as application_controller.rb.
The &. operator calls add only when @superset is not nil, matching the
guard clause behavior exactly.
lib/tasks/app.rake
Multiple changes, all behavior-preserving:
.select { ... }.first -> .find { ... }
Performance/Detect: select builds an entire filtered array, then
.first takes only the first element. find (aka detect) stops
iteration as soon as it finds a match. Same return value, fewer
allocations, and clearer intent.
"..." + "..." -> "..." \ "..."
Style/LineEndConcatenation (multiple occurrences): Backslash line
continuation replaces runtime concatenation. Same resulting string.
puts "#{presenter.name}" -> puts presenter.name
Style/RedundantInterpolation: Interpolating a single expression
with no surrounding text is redundant. puts calls .to_s on its
argument automatically. Identical output.
STDOUT -> $stdout, STDIN -> $stdin (multiple occurrences)
Style/GlobalStdStream: Same reasoning as production.rb. Uses the
reassignable global variable instead of the fixed constant.
Identical behavior under normal operation.
Hash[array.map { ... }] -> array.map { ... }.to_h
Style/HashConversion: Hash[] is the legacy way to convert an array
of [key, value] pairs into a hash. .to_h is the modern equivalent
(Ruby 2.1+). Produces the same hash.
.select { ... }.count -> .count { ... }
Performance/Count: select materializes an intermediate array just
to count it. Passing the block directly to count avoids the
allocation. Same result.
spec/models/settings_spec.rb
"..." + "..." -> "..." \ "..."
Style/LineEndConcatenation: Same transformation as above. Backslash
continuation for multi-line string literals. Identical test string.