Skip to content

Add a ruby linter - standardrb (and apply automated fixes)#431

Open
nyourchuck wants to merge 3 commits into
minnestar:mainfrom
nyourchuck:add_standard_rb
Open

Add a ruby linter - standardrb (and apply automated fixes)#431
nyourchuck wants to merge 3 commits into
minnestar:mainfrom
nyourchuck:add_standard_rb

Conversation

@nyourchuck

Copy link
Copy Markdown

This PR adds the standardrb gem 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_path after 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 the
conditional 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 to
split..-1 when 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:

  1. .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.

  2. "..." + "..." -> "..." \ "..."
    Style/LineEndConcatenation (multiple occurrences): Backslash line
    continuation replaces runtime concatenation. Same resulting string.

  3. 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.

  4. 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.

  5. 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.

  6. .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.

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.

2 participants