Skip to content

Commit 65a43c3

Browse files
authored
Refactor/autofix cops (#70)
* AF: Layout/DotPosition * AF: If/Else/End alignments * Fix other alignments in exception class * AF Layout Space cops * AF: Lint/AmbiguousRegexpLiteral * AF: Lint/UnusedArg * AF: RSpec/DescribedClass * AF: RSpec/HookArgument * AF: Style/Alias * AF: Style/EmptyMethod * AF: Style/GuardClause and IfUnlessModifier * AF: Style/FrozenStringLiteral * AF: Style/NumericLiterals * AF: Style/PercentDelims * AF: All redundant style cops * AF: Symbol/Word Arrays * Regen the TODO file after 50%+ fixes * Update changelog
1 parent 4897952 commit 65a43c3

26 files changed

+115
-232
lines changed

.rubocop_todo.yml

+2-162
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-11-15 15:51:35 UTC using RuboCop version 1.44.1.
3+
# on 2023-12-21 16:12:21 UTC using RuboCop version 1.44.1.
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
# TODO: Nov '23 -> 25 files inspected, 132 offenses detected, 102 offenses autocorrectable
10-
11-
# Offense count: 1
12-
# This cop supports safe autocorrection (--autocorrect).
13-
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
14-
# Include: **/*.gemspec
15-
Gemspec/OrderedDependencies:
16-
Exclude:
17-
- 'cucumber-wire.gemspec'
18-
19-
# Offense count: 6
20-
# This cop supports safe autocorrection (--autocorrect).
21-
# Configuration parameters: EnforcedStyle.
22-
# SupportedStyles: leading, trailing
23-
Layout/DotPosition:
24-
Exclude:
25-
- 'lib/cucumber/wire/add_hooks_filter.rb'
26-
- 'lib/cucumber/wire/request_handler.rb'
27-
28-
# Offense count: 1
29-
# This cop supports safe autocorrection (--autocorrect).
30-
Layout/ElseAlignment:
31-
Exclude:
32-
- 'lib/cucumber/wire/exception.rb'
33-
34-
# Offense count: 1
35-
# This cop supports safe autocorrection (--autocorrect).
36-
# Configuration parameters: EnforcedStyleAlignWith, Severity.
37-
# SupportedStylesAlignWith: keyword, variable, start_of_line
38-
Layout/EndAlignment:
39-
Exclude:
40-
- 'lib/cucumber/wire/exception.rb'
41-
42-
# Offense count: 1
43-
# This cop supports safe autocorrection (--autocorrect).
44-
# Configuration parameters: Width, AllowedPatterns, IgnoredPatterns.
45-
Layout/IndentationWidth:
46-
Exclude:
47-
- 'lib/cucumber/wire/exception.rb'
10+
# TODO: Nov '23 -> 25 files inspected, 53 offenses detected, 28 offenses autocorrectable
4811

4912
# Offense count: 4
5013
# This cop supports safe autocorrection (--autocorrect).
@@ -54,27 +17,6 @@ Layout/MultilineMethodCallIndentation:
5417
Exclude:
5518
- 'lib/cucumber/wire/request_handler.rb'
5619

57-
# Offense count: 2
58-
# This cop supports safe autocorrection (--autocorrect).
59-
Layout/SpaceAfterComma:
60-
Exclude:
61-
- 'lib/cucumber/wire/request_handler.rb'
62-
63-
# Offense count: 2
64-
# This cop supports safe autocorrection (--autocorrect).
65-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
66-
# SupportedStyles: space, no_space, compact
67-
# SupportedStylesForEmptyBrackets: space, no_space
68-
Layout/SpaceInsideArrayLiteralBrackets:
69-
Exclude:
70-
- 'features/support/fake_wire_server.rb'
71-
72-
# Offense count: 3
73-
# This cop supports safe autocorrection (--autocorrect).
74-
Lint/AmbiguousRegexpLiteral:
75-
Exclude:
76-
- 'features/step_definitions/wire_steps.rb'
77-
7820
# Offense count: 3
7921
# This cop supports safe autocorrection (--autocorrect).
8022
# Configuration parameters: AllowSafeAssignment.
@@ -101,13 +43,6 @@ Lint/ToJSON:
10143
Exclude:
10244
- 'lib/cucumber/wire/data_packet.rb'
10345

104-
# Offense count: 1
105-
# This cop supports safe autocorrection (--autocorrect).
106-
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
107-
Lint/UnusedMethodArgument:
108-
Exclude:
109-
- 'lib/cucumber/wire/snippet.rb'
110-
11146
# Offense count: 1
11247
Lint/UselessAssignment:
11348
Exclude:
@@ -141,16 +76,6 @@ Performance/RegexpMatch:
14176
Exclude:
14277
- 'lib/cucumber/wire/configuration.rb'
14378

144-
# Offense count: 8
145-
# This cop supports unsafe autocorrection (--autocorrect-all).
146-
# Configuration parameters: SkipBlocks, EnforcedStyle.
147-
# SupportedStyles: described_class, explicit
148-
RSpec/DescribedClass:
149-
Exclude:
150-
- 'spec/cucumber/wire/configuration_spec.rb'
151-
- 'spec/cucumber/wire/connections_spec.rb'
152-
- 'spec/cucumber/wire/data_packet_spec.rb'
153-
15479
# Offense count: 3
15580
# Configuration parameters: CountAsOne.
15681
RSpec/ExampleLength:
@@ -190,14 +115,6 @@ Security/YAMLLoad:
190115
Exclude:
191116
- 'lib/cucumber/wire/configuration.rb'
192117

193-
# Offense count: 5
194-
# This cop supports safe autocorrection (--autocorrect).
195-
# Configuration parameters: EnforcedStyle.
196-
# SupportedStyles: prefer_alias, prefer_alias_method
197-
Style/Alias:
198-
Exclude:
199-
- 'lib/cucumber/wire/protocol/requests.rb'
200-
201118
# Offense count: 1
202119
# This cop supports safe autocorrection (--autocorrect).
203120
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
@@ -222,34 +139,6 @@ Style/ConditionalAssignment:
222139
Exclude:
223140
- 'lib/cucumber/wire/connection.rb'
224141

225-
# Offense count: 1
226-
# This cop supports safe autocorrection (--autocorrect).
227-
# Configuration parameters: EnforcedStyle.
228-
# SupportedStyles: compact, expanded
229-
Style/EmptyMethod:
230-
Exclude:
231-
- 'lib/cucumber/wire/request_handler.rb'
232-
233-
# Offense count: 24
234-
# This cop supports unsafe autocorrection (--autocorrect-all).
235-
# Configuration parameters: EnforcedStyle.
236-
# SupportedStyles: always, always_true, never
237-
Style/FrozenStringLiteralComment:
238-
Enabled: false
239-
240-
# Offense count: 1
241-
# This cop supports safe autocorrection (--autocorrect).
242-
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
243-
Style/GuardClause:
244-
Exclude:
245-
- 'lib/cucumber/wire/exception.rb'
246-
247-
# Offense count: 2
248-
# This cop supports safe autocorrection (--autocorrect).
249-
Style/IfUnlessModifier:
250-
Exclude:
251-
- 'Gemfile'
252-
253142
# Offense count: 1
254143
# This cop supports safe autocorrection (--autocorrect).
255144
# Configuration parameters: EnforcedStyle.
@@ -266,12 +155,6 @@ Style/MutableConstant:
266155
Exclude:
267156
- 'lib/cucumber/wire/configuration.rb'
268157

269-
# Offense count: 2
270-
# This cop supports safe autocorrection (--autocorrect).
271-
# Configuration parameters: Strict, AllowedNumbers, AllowedPatterns.
272-
Style/NumericLiterals:
273-
MinDigits: 6
274-
275158
# Offense count: 3
276159
# This cop supports safe autocorrection (--autocorrect).
277160
Style/ParallelAssignment:
@@ -280,34 +163,6 @@ Style/ParallelAssignment:
280163
- 'lib/cucumber/wire/data_packet.rb'
281164
- 'lib/cucumber/wire/step_argument.rb'
282165

283-
# Offense count: 6
284-
# This cop supports safe autocorrection (--autocorrect).
285-
# Configuration parameters: PreferredDelimiters.
286-
Style/PercentLiteralDelimiters:
287-
Exclude:
288-
- 'spec/cucumber/wire/configuration_spec.rb'
289-
- 'spec/cucumber/wire/connection_spec.rb'
290-
291-
# Offense count: 1
292-
# This cop supports safe autocorrection (--autocorrect).
293-
Style/RedundantBegin:
294-
Exclude:
295-
- 'features/support/fake_wire_server.rb'
296-
297-
# Offense count: 5
298-
# This cop supports safe autocorrection (--autocorrect).
299-
Style/RedundantPercentQ:
300-
Exclude:
301-
- 'spec/cucumber/wire/configuration_spec.rb'
302-
- 'spec/cucumber/wire/connection_spec.rb'
303-
304-
# Offense count: 1
305-
# This cop supports safe autocorrection (--autocorrect).
306-
# Configuration parameters: AllowMultipleReturnValues.
307-
Style/RedundantReturn:
308-
Exclude:
309-
- 'lib/cucumber/wire/configuration.rb'
310-
311166
# Offense count: 1
312167
# This cop supports safe autocorrection (--autocorrect).
313168
Style/RescueModifier:
@@ -335,18 +190,3 @@ Style/Semicolon:
335190
Style/StringConcatenation:
336191
Exclude:
337192
- 'features/support/fake_wire_server.rb'
338-
339-
# Offense count: 3
340-
# This cop supports safe autocorrection (--autocorrect).
341-
# Configuration parameters: MinSize.
342-
# SupportedStyles: percent, brackets
343-
Style/SymbolArray:
344-
EnforcedStyle: brackets
345-
346-
# Offense count: 2
347-
# This cop supports safe autocorrection (--autocorrect).
348-
# Configuration parameters: WordRegex.
349-
# SupportedStyles: percent, brackets
350-
Style/WordArray:
351-
EnforcedStyle: percent
352-
MinSize: 4

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1010

1111
## [Unreleased]
1212
### Added
13-
- Added some basic rubocop compliance to suite (More fixes to come) ([#69](https://github.com/cucumber/cucumber-ruby-wire/pull/69))
13+
- Added some basic rubocop compliance to suite (More fixes to come) ([#69](https://github.com/cucumber/cucumber-ruby-wire/pull/69) [#70](https://github.com/cucumber/cucumber-ruby-wire/pull/70))
1414

1515
### Changed
1616

Gemfile

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec
46

5-
if ENV['CUCUMBER_RUBY_CORE']
6-
gem 'cucumber-core', path: ENV['CUCUMBER_RUBY_CORE']
7-
end
7+
gem 'cucumber-core', path: ENV['CUCUMBER_RUBY_CORE'] if ENV['CUCUMBER_RUBY_CORE']
88

9-
if ENV['CUCUMBER_RUBY']
10-
gem 'cucumber', path: ENV['CUCUMBER_RUBY']
11-
end
9+
gem 'cucumber', path: ENV['CUCUMBER_RUBY'] if ENV['CUCUMBER_RUBY']

Rakefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require 'rubygems'
24
require 'bundler'
35
Bundler::GemHelper.install_tasks
46

5-
task default: [:unit_tests, :acceptance_tests]
7+
task default: %i[unit_tests acceptance_tests]
68

79
task :unit_tests do
810
sh 'bundle exec rspec'

cucumber-wire.gemspec

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
24

35
Gem::Specification.new do |s|
+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
require 'aruba/cucumber'

features/step_definitions/wire_steps.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Given /^there is a wire server (running |)on port (\d+) which understands the following protocol:$/ do |running, port, table|
1+
# frozen_string_literal: true
2+
3+
Given(/^there is a wire server (running |)on port (\d+) which understands the following protocol:$/) do |running, port, table|
24
protocol = table.hashes.map do |table_hash|
35
table_hash['response'] = table_hash['response'].gsub(/\n/, '\n')
46
table_hash
@@ -8,12 +10,12 @@
810
start_wire_server if running.strip == 'running'
911
end
1012

11-
Given /^the wire server takes (.*) seconds to respond to the invoke message$/ do |timeout|
13+
Given(/^the wire server takes (.*) seconds to respond to the invoke message$/) do |timeout|
1214
@server.delay_response(:invoke, timeout.to_f)
1315
start_wire_server
1416
end
1517

16-
Given /^I have environment variable (\w+) set to "([^"]*)"$/ do |variable, value|
18+
Given(/^I have environment variable (\w+) set to "([^"]*)"$/) do |variable, value|
1719
set_environment_variable(variable, value)
1820
end
1921

features/support/fake_wire_server.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'json'
24
require 'socket'
35

@@ -23,14 +25,12 @@ def handle_connections(io)
2325
end
2426

2527
def open_session_on(socket, io)
26-
begin
27-
on_message = lambda { |message| io.puts message }
28-
SocketSession.new(socket, @protocol_table, @delays, on_message).start
29-
rescue Exception => e
30-
raise e
31-
ensure
32-
socket.close
33-
end
28+
on_message = lambda { |message| io.puts message }
29+
SocketSession.new(socket, @protocol_table, @delays, on_message).start
30+
rescue Exception => e
31+
raise e
32+
ensure
33+
socket.close
3434
end
3535

3636
class SocketSession
@@ -56,10 +56,10 @@ def handle(data)
5656
send_response(protocol_entry['response'])
5757
else
5858
serialized_exception = { message: "Not understood: #{data}", backtrace: [] }
59-
send_response(['fail', serialized_exception ].to_json)
59+
send_response(['fail', serialized_exception].to_json)
6060
end
6161
rescue => e
62-
send_response(['fail', { message: e.message, backtrace: e.backtrace, exception: e.class } ].to_json)
62+
send_response(['fail', { message: e.message, backtrace: e.backtrace, exception: e.class }].to_json)
6363
end
6464

6565
def response_to(data)

lib/cucumber/wire.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'cucumber/wire/plugin'
24

35
return unless respond_to?(:InstallPlugin)

lib/cucumber/wire/add_hooks_filter.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
module Cucumber
24
module Wire
35
class AddHooksFilter < Core::Filter.new(:connections)
46
def test_case(test_case)
5-
test_case.
6-
with_steps([before_hook(test_case)] + test_case.test_steps + [after_hook(test_case)]).
7-
describe_to receiver
7+
test_case
8+
.with_steps([before_hook(test_case)] + test_case.test_steps + [after_hook(test_case)])
9+
.describe_to receiver
810
end
911

1012
def before_hook(test_case)

lib/cucumber/wire/configuration.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'yaml'
24
require 'erb'
35

@@ -19,7 +21,7 @@ def initialize(args)
1921
end
2022

2123
def timeout(message = nil)
22-
return @timeouts[message.to_s] || 3
24+
@timeouts[message.to_s] || 3
2325
end
2426

2527
def to_s

lib/cucumber/wire/connection.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'timeout'
24
require 'cucumber/wire/protocol'
35
require 'cucumber/wire/exception'

lib/cucumber/wire/connections.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'json'
24
require 'socket'
35
require 'cucumber/wire/connection'

lib/cucumber/wire/data_packet.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'json'
24

35
module Cucumber

0 commit comments

Comments
 (0)