Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

Commit b257530

Browse files
committed
Fix RuboCop violations and improve code quality
- Fix all RuboCop violations (Style, Layout, Lint) - Use argument forwarding shorthand (...) for Ruby 3.0+ - Freeze constants for immutability - Remove redundant require statements - Use safe navigation operator where appropriate - Replace string concatenation with interpolation - Use RSpec predicate matchers - Update .rubocop_todo.yml (reduced from 477 to 388 offenses) - Bump Ruby version to 3.2 in .ruby-version
1 parent 57787dc commit b257530

31 files changed

Lines changed: 135 additions & 354 deletions

.rubocop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
inherit_from: .rubocop_todo.yml
22

3-
require:
3+
plugins:
44
- rubocop-rake
55
- rubocop-rspec
66

77
AllCops:
88
NewCops: enable
9+
SuggestExtensions: false

.rubocop_todo.yml

Lines changed: 9 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-03-18 15:28:40 UTC using RuboCop version 1.62.1.
3+
# on 2026-02-19 09:35:40 UTC using RuboCop version 1.84.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

99
# Offense count: 6
10-
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
10+
# Configuration parameters: EnforcedStyle, AllowedGems.
1111
# SupportedStyles: Gemfile, gems.rb, gemspec
12-
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
1312
Gemspec/DevelopmentDependencies:
1413
Exclude:
1514
- 'steno.gemspec'
1615

17-
# Offense count: 1
18-
# This cop supports safe autocorrection (--autocorrect).
19-
# Configuration parameters: Severity, Include.
20-
# Include: **/*.gemspec
21-
Gemspec/RequireMFA:
22-
Exclude:
23-
- 'steno.gemspec'
24-
25-
# Offense count: 1
26-
# Configuration parameters: Severity, Include.
27-
# Include: **/*.gemspec
28-
Gemspec/RequiredRubyVersion:
29-
Exclude:
30-
- 'steno.gemspec'
31-
32-
# Offense count: 2
33-
# This cop supports safe autocorrection (--autocorrect).
34-
# Configuration parameters: EnforcedStyle.
35-
# SupportedStyles: symmetrical, new_line, same_line
36-
Layout/MultilineArrayBraceLayout:
37-
Exclude:
38-
- 'spec/unit/json_prettifier_spec.rb'
39-
4016
# Offense count: 1
4117
Lint/BinaryOperatorWithIdenticalOperands:
4218
Exclude:
@@ -55,34 +31,6 @@ Lint/MissingSuper:
5531
- 'lib/steno/codec/json.rb'
5632
- 'lib/steno/sink/counter.rb'
5733

58-
# Offense count: 1
59-
# This cop supports unsafe autocorrection (--autocorrect-all).
60-
Lint/NonDeterministicRequireOrder:
61-
Exclude:
62-
- 'spec/spec_helper.rb'
63-
64-
# Offense count: 8
65-
# This cop supports unsafe autocorrection (--autocorrect-all).
66-
Lint/RedundantRequireStatement:
67-
Exclude:
68-
- 'lib/steno.rb'
69-
- 'lib/steno/context.rb'
70-
- 'lib/steno/logger.rb'
71-
- 'lib/steno/record.rb'
72-
- 'lib/steno/sink/base.rb'
73-
- 'lib/steno/sink/eventlog.rb'
74-
- 'lib/steno/sink/syslog.rb'
75-
- 'spec/support/barrier.rb'
76-
77-
# Offense count: 4
78-
# This cop supports unsafe autocorrection (--autocorrect-all).
79-
# Configuration parameters: AutoCorrect.
80-
Lint/UselessAssignment:
81-
Exclude:
82-
- 'bin/steno-prettify'
83-
- 'lib/steno/json_prettifier.rb'
84-
- 'spec/unit/sink/fluentd_spec.rb'
85-
8634
# Offense count: 2
8735
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
8836
Metrics/AbcSize:
@@ -103,13 +51,6 @@ Metrics/MethodLength:
10351
Metrics/PerceivedComplexity:
10452
Max: 12
10553

106-
# Offense count: 1
107-
# Configuration parameters: ForbiddenDelimiters.
108-
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
109-
Naming/HeredocDelimiterNaming:
110-
Exclude:
111-
- 'bin/steno-prettify'
112-
11354
# Offense count: 2
11455
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
11556
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
@@ -118,58 +59,16 @@ Naming/MethodParameterName:
11859
- 'lib/steno/logger.rb'
11960
- 'lib/steno/tagged_logger.rb'
12061

121-
# Offense count: 4
122-
# This cop supports unsafe autocorrection (--autocorrect-all).
123-
RSpec/BeEq:
124-
Exclude:
125-
- 'spec/unit/config_spec.rb'
126-
- 'spec/unit/json_codec_spec.rb'
127-
128-
# Offense count: 58
129-
# This cop supports unsafe autocorrection (--autocorrect-all).
130-
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
131-
# SupportedStyles: described_class, explicit
132-
RSpec/DescribedClass:
133-
Exclude:
134-
- 'spec/unit/config_spec.rb'
135-
- 'spec/unit/context_spec.rb'
136-
- 'spec/unit/json_codec_spec.rb'
137-
- 'spec/unit/json_prettifier_spec.rb'
138-
- 'spec/unit/log_level_spec.rb'
139-
- 'spec/unit/logger_spec.rb'
140-
- 'spec/unit/record_spec.rb'
141-
- 'spec/unit/sink/eventlog_spec.rb'
142-
- 'spec/unit/sink/io_spec.rb'
143-
- 'spec/unit/sink/syslog_spec.rb'
144-
- 'spec/unit/steno_spec.rb'
145-
- 'spec/unit/tagged_logger_spec.rb'
146-
14762
# Offense count: 28
14863
# Configuration parameters: CountAsOne.
14964
RSpec/ExampleLength:
150-
Max: 29
65+
Max: 28
15166

15267
# Offense count: 19
15368
RSpec/ExpectInHook:
15469
Exclude:
15570
- 'spec/unit/config_spec.rb'
15671

157-
# Offense count: 10
158-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
159-
# Include: **/*_spec*rb*, **/spec/**/*
160-
RSpec/FilePath:
161-
Exclude:
162-
- 'spec/unit/config_spec.rb'
163-
- 'spec/unit/json_codec_spec.rb'
164-
- 'spec/unit/json_prettifier_spec.rb'
165-
- 'spec/unit/log_level_spec.rb'
166-
- 'spec/unit/logger_spec.rb'
167-
- 'spec/unit/record_spec.rb'
168-
- 'spec/unit/sink/counter_spec.rb'
169-
- 'spec/unit/sink/fluentd_spec.rb'
170-
- 'spec/unit/sink/io_spec.rb'
171-
- 'spec/unit/tagged_logger_spec.rb'
172-
17372
# Offense count: 57
17473
# Configuration parameters: AssignmentOnly.
17574
RSpec/InstanceVariable:
@@ -214,17 +113,8 @@ RSpec/NoExpectationExample:
214113
- 'spec/unit/sink/syslog_spec.rb'
215114

216115
# Offense count: 10
217-
# This cop supports unsafe autocorrection (--autocorrect-all).
218-
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
219-
# SupportedStyles: inflected, explicit
220-
RSpec/PredicateMatcher:
221-
Exclude:
222-
- 'spec/unit/logger_spec.rb'
223-
- 'spec/unit/tagged_logger_spec.rb'
224-
225-
# Offense count: 10
226-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
227-
# Include: **/*_spec.rb
116+
# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector.
117+
# SupportedInflectors: default, active_support
228118
RSpec/SpecFilePathFormat:
229119
Exclude:
230120
- '**/spec/routing/**/*'
@@ -260,8 +150,10 @@ RSpec/VerifiedDoubles:
260150

261151
# Offense count: 15
262152
# This cop supports unsafe autocorrection (--autocorrect-all).
263-
# Configuration parameters: EnforcedStyle.
153+
# Configuration parameters: EnforcedStyle, EnforcedStyleForClasses, EnforcedStyleForModules.
264154
# SupportedStyles: nested, compact
155+
# SupportedStylesForClasses: ~, nested, compact
156+
# SupportedStylesForModules: ~, nested, compact
265157
Style/ClassAndModuleChildren:
266158
Exclude:
267159
- 'lib/steno/codec/base.rb'
@@ -304,7 +196,7 @@ Style/Documentation:
304196

305197
# Offense count: 3
306198
# This cop supports safe autocorrection (--autocorrect).
307-
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
199+
# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, Mode, AllowedMethods, AllowedPatterns.
308200
# SupportedStyles: annotated, template, unannotated
309201
Style/FormatStringToken:
310202
EnforcedStyle: unannotated
@@ -316,111 +208,9 @@ Style/FormatStringToken:
316208
Style/FrozenStringLiteralComment:
317209
Enabled: false
318210

319-
# Offense count: 4
320-
# This cop supports unsafe autocorrection (--autocorrect-all).
321-
Style/GlobalStdStream:
322-
Exclude:
323-
- 'bin/steno-prettify'
324-
- 'lib/steno/config.rb'
325-
- 'spec/unit/config_spec.rb'
326-
327-
# Offense count: 1
328-
# This cop supports unsafe autocorrection (--autocorrect-all).
329-
# Configuration parameters: AllowSplatArgument.
330-
Style/HashConversion:
331-
Exclude:
332-
- 'lib/steno/config.rb'
333-
334-
# Offense count: 4
335-
# This cop supports unsafe autocorrection (--autocorrect-all).
336-
# Configuration parameters: AllowedReceivers.
337-
# AllowedReceivers: Thread.current
338-
Style/HashEachMethods:
339-
Exclude:
340-
- 'lib/steno/logger.rb'
341-
- 'lib/steno/sink/counter.rb'
342-
- 'lib/steno/tagged_logger.rb'
343-
- 'spec/unit/logger_spec.rb'
344-
345-
# Offense count: 1
346-
# This cop supports unsafe autocorrection (--autocorrect-all).
347-
Style/HashTransformKeys:
348-
Exclude:
349-
- 'lib/steno/config.rb'
350-
351-
# Offense count: 1
352-
Style/MissingRespondToMissing:
353-
Exclude:
354-
- 'lib/steno/tagged_logger.rb'
355-
356-
# Offense count: 7
357-
# This cop supports unsafe autocorrection (--autocorrect-all).
358-
# Configuration parameters: EnforcedStyle.
359-
# SupportedStyles: literals, strict
360-
Style/MutableConstant:
361-
Exclude:
362-
- 'lib/steno/context.rb'
363-
- 'lib/steno/json_prettifier.rb'
364-
- 'lib/steno/logger.rb'
365-
- 'lib/steno/sink/eventlog.rb'
366-
- 'lib/steno/sink/syslog.rb'
367-
- 'lib/steno/version.rb'
368-
369211
# Offense count: 2
370212
# Configuration parameters: AllowedMethods.
371213
# AllowedMethods: respond_to_missing?
372214
Style/OptionalBooleanParameter:
373215
Exclude:
374216
- 'bin/steno-prettify'
375-
376-
# Offense count: 2
377-
# This cop supports unsafe autocorrection (--autocorrect-all).
378-
# Configuration parameters: EnforcedStyle.
379-
# SupportedStyles: short, verbose
380-
Style/PreferredHashMethods:
381-
Exclude:
382-
- 'lib/steno/json_prettifier.rb'
383-
384-
# Offense count: 1
385-
# This cop supports unsafe autocorrection (--autocorrect-all).
386-
# Configuration parameters: EnforcedStyle, AllowedCompactTypes.
387-
# SupportedStyles: compact, exploded
388-
Style/RaiseArgs:
389-
Exclude:
390-
- 'lib/steno/logger.rb'
391-
392-
# Offense count: 1
393-
# This cop supports unsafe autocorrection (--autocorrect-all).
394-
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
395-
# AllowedMethods: present?, blank?, presence, try, try!
396-
Style/SafeNavigation:
397-
Exclude:
398-
- 'bin/steno-prettify'
399-
400-
# Offense count: 10
401-
# This cop supports unsafe autocorrection (--autocorrect-all).
402-
# Configuration parameters: Mode.
403-
Style/StringConcatenation:
404-
Exclude:
405-
- 'lib/steno/codec/json.rb'
406-
- 'lib/steno/json_prettifier.rb'
407-
- 'lib/steno/logger.rb'
408-
- 'lib/steno/tagged_logger.rb'
409-
- 'spec/unit/json_prettifier_spec.rb'
410-
- 'spec/unit/logger_spec.rb'
411-
- 'steno.gemspec'
412-
413-
# Offense count: 1
414-
# This cop supports unsafe autocorrection (--autocorrect-all).
415-
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
416-
# AllowedMethods: define_method
417-
Style/SymbolProc:
418-
Exclude:
419-
- 'steno.gemspec'
420-
421-
# Offense count: 2
422-
# This cop supports safe autocorrection (--autocorrect).
423-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
424-
# URISchemes: http, https
425-
Layout/LineLength:
426-
Max: 128

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7.8
1+
3.2.10

bin/steno-prettify

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def prettify_io(io, prettifier, ignore_parse_error = false)
2121

2222
prettified = prettifier.prettify_line(json)
2323
print prefix + prettified
24-
rescue Steno::JsonPrettifier::ParseError => e
24+
rescue Steno::JsonPrettifier::ParseError
2525
if ignore_parse_error
2626
print line
2727
else
@@ -43,14 +43,14 @@ def prettify_file(path, prettifier, ignore_parse_error = false)
4343

4444
prettify_io(f, prettifier, ignore_parse_error)
4545
ensure
46-
f.close if f
46+
f&.close
4747
end
4848

4949
excluded_fields = []
5050
ignore_parse_error = false
5151

5252
option_parser = OptionParser.new do |op|
53-
op.banner = <<~EOT
53+
op.banner = <<~USAGE
5454
Usage: steno-prettify [OPTS] [FILE...]
5555
5656
Parses json formatted log lines from FILE(s), or stdin,
@@ -65,7 +65,7 @@ option_parser = OptionParser.new do |op|
6565
Prettify contents of stdin.
6666
6767
Options:
68-
EOT
68+
USAGE
6969

7070
op.on('-h', '--help', 'Display help') do
7171
puts op
@@ -83,15 +83,15 @@ end
8383

8484
option_parser.parse!(ARGV)
8585

86-
STDOUT.sync = true
86+
$stdout.sync = true
8787
prettifier = Steno::JsonPrettifier.new(excluded_fields)
8888

8989
inputs = ARGV.dup
9090
inputs << '-' if inputs.empty?
9191

9292
inputs.each do |path|
9393
if path == '-'
94-
prettify_io(STDIN, prettifier, ignore_parse_error)
94+
prettify_io($stdin, prettifier, ignore_parse_error)
9595
else
9696
prettify_file(path, prettifier, ignore_parse_error)
9797
end

lib/steno.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'thread'
2-
31
require 'steno/codec'
42
require 'steno/config'
53
require 'steno/context'

lib/steno/codec/json.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def encode_record(record)
3737

3838
h['timestamp'] = Time.at(record.timestamp).utc.iso8601(6) if iso8601_timestamps?
3939

40-
Yajl::Encoder.encode(h) + "\n"
40+
"#{Yajl::Encoder.encode(h)}\n"
4141
end
4242

4343
def iso8601_timestamps?

0 commit comments

Comments
 (0)