Skip to content

Commit f23e603

Browse files
authored
Refactor/Layout Autofixes (#1745)
* AF: Layout/ClosingHeredocIndentation and alter heredocs to squigglies * A partial AF of Layout/HashAlignment * AF: Layout/HeredocIndentation from using Squigglies * AF: Layout/IndentationConsistency * AF: Layout/SpaceInsideHashLiteralBraces * AF: Layout/EmptyLines * AF: Layout/BlockAlignment * Remove lots of in-line disabling in favour of a centralized todo file * Regenerate todo file and tidy up previous iterations * Add changelog * Remove ABCSize override in regular rubocop file - now regenning should fix it
1 parent 0e094a6 commit f23e603

File tree

21 files changed

+188
-231
lines changed

21 files changed

+188
-231
lines changed

.rubocop.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ Lint/UselessMethodDefinition:
4242
Exclude:
4343
- 'lib/cucumber/glue/proto_world.rb'
4444

45-
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
46-
# to the auto-gen-config
47-
Metrics/AbcSize:
48-
Max: 41
49-
# TODO: Manually added! - be careful with regenning the file - this needs a fix
50-
Exclude:
51-
- lib/cucumber/formatter/junit.rb
52-
- spec/cucumber/formatter/http_io_spec.rb
53-
- lib/cucumber/glue/proto_world.rb
54-
5545
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
5646
Metrics/ClassLength:
5747
Max: 375

.rubocop_todo.yml

Lines changed: 47 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,33 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-10-03 13:56:41 UTC using RuboCop version 1.56.4.
3+
# on 2023-12-08 14:57:03 UTC using RuboCop version 1.56.4.
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

9-
# TODO - [LH] -> Aug '23 - 370 files inspected, 1110 offenses detected, 482 offenses autocorrectable
109
# TODO - [LH] -> Sep 6 '23 - 370 files inspected, 983 offenses detected, 368 offenses autocorrectable
1110
# TODO - [LH] -> Sep 11 '23 - 370 files inspected, 825 offenses detected, 387 offenses autocorrectable
1211
# TODO - [LH] -> Sep 19 '23 - 370 files inspected, 640 offenses detected, 202 offenses autocorrectable
1312
# TODO - [LH] -> Oct '23 - 355 files inspected, 642 offenses detected, 205 offenses autocorrectable
13+
# TODO - [LH] -> Dec '23 - 350 files inspected, 595 offenses detected, 171 offenses autocorrectable
1414

15-
# Offense count: 1
16-
# This cop supports safe autocorrection (--autocorrect).
17-
# Configuration parameters: EnforcedStyleAlignWith.
18-
# SupportedStylesAlignWith: either, start_of_block, start_of_line
19-
Layout/BlockAlignment:
20-
Exclude:
21-
- 'spec/cucumber/formatter/fail_fast_spec.rb'
22-
23-
# Offense count: 17
24-
# This cop supports safe autocorrection (--autocorrect).
25-
Layout/ClosingHeredocIndentation:
26-
Exclude:
27-
- 'spec/cucumber/cli/profile_loader_spec.rb'
28-
- 'spec/cucumber/formatter/json_spec.rb'
29-
30-
# Offense count: 1
31-
# This cop supports safe autocorrection (--autocorrect).
32-
Layout/EmptyLines:
33-
Exclude:
34-
- 'spec/cucumber/formatter/fail_fast_spec.rb'
35-
36-
# Offense count: 38
15+
# Offense count: 10
3716
# This cop supports safe autocorrection (--autocorrect).
3817
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
3918
# SupportedHashRocketStyles: key, separator, table
4019
# SupportedColonStyles: key, separator, table
4120
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
4221
Layout/HashAlignment:
4322
Exclude:
44-
- 'cucumber.gemspec'
4523
- 'lib/cucumber/cli/options.rb'
46-
- 'lib/cucumber/formatter/ansicolor.rb'
47-
- 'lib/cucumber/gherkin/formatter/ansi_escapes.rb'
4824

49-
# Offense count: 4
25+
# Offense count: 19
5026
# This cop supports safe autocorrection (--autocorrect).
51-
Layout/HeredocIndentation:
27+
# Configuration parameters: AllowInHeredoc.
28+
Layout/TrailingWhitespace:
5229
Exclude:
53-
- 'lib/cucumber/cli/options.rb'
54-
- 'lib/cucumber/cli/profile_loader.rb'
55-
- 'spec/cucumber/cli/profile_loader_spec.rb'
56-
57-
# Offense count: 3
58-
# This cop supports safe autocorrection (--autocorrect).
59-
# Configuration parameters: EnforcedStyle.
60-
# SupportedStyles: normal, indented_internal_methods
61-
Layout/IndentationConsistency:
62-
Exclude:
63-
- 'spec/cucumber/formatter/fail_fast_spec.rb'
64-
65-
# Offense count: 1
66-
# This cop supports safe autocorrection (--autocorrect).
67-
# Configuration parameters: Width, AllowedPatterns.
68-
Layout/IndentationWidth:
69-
Exclude:
70-
- 'spec/cucumber/formatter/fail_fast_spec.rb'
71-
72-
# Offense count: 4
73-
# This cop supports safe autocorrection (--autocorrect).
74-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
75-
# SupportedStyles: space, no_space, compact
76-
# SupportedStylesForEmptyBraces: space, no_space
77-
Layout/SpaceInsideHashLiteralBraces:
78-
Exclude:
79-
- 'spec/cucumber/cli/options_spec.rb'
30+
- 'lib/cucumber/multiline_argument/data_table.rb'
8031

8132
# Offense count: 3
8233
# This cop supports safe autocorrection (--autocorrect).
@@ -86,17 +37,25 @@ Lint/AmbiguousOperator:
8637
- 'lib/cucumber/running_test_case.rb'
8738
- 'spec/cucumber/formatter/spec_helper.rb'
8839

89-
# Offense count: 1
90-
# This cop supports safe autocorrection (--autocorrect).
91-
Lint/RedundantCopDisableDirective:
92-
Exclude:
93-
- 'lib/cucumber/cli/options.rb'
94-
95-
# Offense count: 1
40+
# Offense count: 4
9641
Lint/RescueException:
9742
Exclude:
43+
- 'lib/cucumber/cli/main.rb'
44+
- 'lib/cucumber/configuration.rb'
45+
- 'lib/cucumber/glue/invoke_in_world.rb'
9846
- 'lib/cucumber/glue/proto_world.rb'
9947

48+
# Offense count: 4
49+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
50+
Metrics/AbcSize:
51+
Max: 127
52+
53+
# Offense count: 1
54+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
55+
# AllowedMethods: refine
56+
Metrics/BlockLength:
57+
Max: 52
58+
10059
# Offense count: 8
10160
# Configuration parameters: AllowedMethods, AllowedPatterns.
10261
Metrics/CyclomaticComplexity:
@@ -115,6 +74,15 @@ Naming/FileName:
11574
Exclude:
11675
- 'features/lib/step_definitions/iso-8859-1_steps.rb'
11776

77+
# Offense count: 2
78+
# This cop supports unsafe autocorrection (--autocorrect-all).
79+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
80+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
81+
Naming/MemoizedInstanceVariableName:
82+
Exclude:
83+
- 'lib/cucumber/formatter/json.rb'
84+
- 'lib/cucumber/multiline_argument/data_table.rb'
85+
11886
# Offense count: 14
11987
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
12088
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
@@ -214,7 +182,7 @@ RSpec/ExpectActual:
214182
- 'spec/cucumber/cli/configuration_spec.rb'
215183
- 'spec/cucumber/step_match_spec.rb'
216184

217-
# Offense count: 2
185+
# Offense count: 4
218186
RSpec/ExpectInHook:
219187
Exclude:
220188
- 'spec/cucumber/multiline_argument/data_table_spec.rb'
@@ -261,7 +229,7 @@ RSpec/MultipleExpectations:
261229
# Offense count: 38
262230
# Configuration parameters: AllowSubject.
263231
RSpec/MultipleMemoizedHelpers:
264-
Max: 15
232+
Max: 10
265233

266234
# Offense count: 1
267235
# This cop supports safe autocorrection (--autocorrect).
@@ -283,22 +251,11 @@ RSpec/NamedSubject:
283251
- 'spec/cucumber/runtime/support_code_spec.rb'
284252
- 'spec/cucumber/runtime_spec.rb'
285253

286-
# Offense count: 6
287-
# Configuration parameters: AllowedGroups.
288-
RSpec/NestedGroups:
289-
Max: 6
290-
291254
# Offense count: 1
292255
RSpec/OverwritingSetup:
293256
Exclude:
294257
- 'spec/cucumber/runtime/support_code_spec.rb'
295258

296-
# Offense count: 2
297-
# This cop supports safe autocorrection (--autocorrect).
298-
RSpec/ReceiveCounts:
299-
Exclude:
300-
- 'spec/cucumber/filters/retry_spec.rb'
301-
302259
# Offense count: 8
303260
RSpec/RepeatedExample:
304261
Exclude:
@@ -334,7 +291,7 @@ RSpec/ScatteredLet:
334291
Exclude:
335292
- 'spec/cucumber/runtime/support_code_spec.rb'
336293

337-
# Offense count: 5
294+
# Offense count: 7
338295
RSpec/StubbedMock:
339296
Exclude:
340297
- 'spec/cucumber/cli/configuration_spec.rb'
@@ -360,6 +317,17 @@ RSpec/VerifiedDoubles:
360317
- 'spec/cucumber/runtime/support_code_spec.rb'
361318
- 'spec/cucumber/world/pending_spec.rb'
362319

320+
# Offense count: 1
321+
Security/Open:
322+
Exclude:
323+
- 'lib/autotest/cucumber_mixin.rb'
324+
325+
# Offense count: 1
326+
# This cop supports unsafe autocorrection (--autocorrect-all).
327+
Security/YAMLLoad:
328+
Exclude:
329+
- 'lib/cucumber/cli/profile_loader.rb'
330+
363331
# Offense count: 7
364332
# This cop supports unsafe autocorrection (--autocorrect-all).
365333
# Configuration parameters: EnforcedStyle.
@@ -379,10 +347,11 @@ Style/ClassVars:
379347
Exclude:
380348
- 'spec/cucumber/glue/step_definition_spec.rb'
381349

382-
# Offense count: 4
350+
# Offense count: 7
383351
# Configuration parameters: AllowedVariables.
384352
Style/GlobalVars:
385353
Exclude:
354+
- 'features/lib/support/env.rb'
386355
- 'spec/cucumber/cli/options_spec.rb'
387356

388357
# Offense count: 6

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1313

1414
### Changed
1515
- Updated dependencies to slightly more permissive / up to date versions ([luke-hill](https://github.com/luke-hill))
16+
- Fixed most of the `Layout` cop offenses ([luke-hill](https://github.com/luke-hill))
1617

1718
### Fixed
1819

cucumber.gemspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Gem::Specification.new do |s|
1212
s.platform = Gem::Platform::RUBY
1313

1414
s.metadata = {
15-
'bug_tracker_uri' => 'https://github.com/cucumber/cucumber-ruby/issues',
16-
'changelog_uri' => 'https://github.com/cucumber/cucumber-ruby/blob/main/CHANGELOG.md',
15+
'bug_tracker_uri' => 'https://github.com/cucumber/cucumber-ruby/issues',
16+
'changelog_uri' => 'https://github.com/cucumber/cucumber-ruby/blob/main/CHANGELOG.md',
1717
'documentation_uri' => 'https://www.rubydoc.info/github/cucumber/cucumber-ruby/',
18-
'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/cukes',
19-
'source_code_uri' => 'https://github.com/cucumber/cucumber-ruby'
18+
'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/cukes',
19+
'source_code_uri' => 'https://github.com/cucumber/cucumber-ruby'
2020
}
2121

2222
s.required_ruby_version = '>= 2.7'

features/docs/events/step_activated_event.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Feature: Step Activated Event
99
Given a file named "features/step_definitions/steps.rb" with:
1010
"""
1111
Given /a step/ do
12-
# automation goes here
12+
# automation goes here
1313
end
1414
"""
1515
And a file named "features/test.feature" with:

features/lib/support/env.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@
4949
# (the ones ran by Cucumber itself).
5050
# This should reset data hopefully (and make clear why we do that)
5151

52-
# rubocop:disable Style/GlobalVars
5352
$global_state = nil
5453
$global_cukes = 0
5554
$scenario_runs = 0
56-
# rubocop:enable Style/GlobalVars
5755
end
5856

5957
After('@disable_fail_fast') do

lib/cucumber/cli/main.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def execute!(existing_runtime = nil)
4949
rescue Errno::EACCES, Errno::ENOENT => e
5050
@err.puts("#{e.message} (#{e.class})")
5151
exit_unable_to_finish
52-
rescue Exception => e # rubocop:disable Lint/RescueException
52+
rescue Exception => e
5353
@err.puts("#{e.message} (#{e.class})")
5454
@err.puts(e.backtrace.join("\n"))
5555
exit_unable_to_finish

lib/cucumber/cli/options.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ def []=(key, value)
9292
@options[key] = value
9393
end
9494

95-
def parse!(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
95+
def parse!(args)
9696
@args = args
9797
@expanded_args = @args.dup
9898

9999
@args.extend(::OptionParser::Arguable)
100100

101-
@args.options do |opts| # rubocop:disable Metrics/BlockLength
101+
@args.options do |opts|
102102
opts.banner = banner
103103
opts.on('--publish', 'Publish a report to https://reports.cucumber.io') do
104104
set_option :publish_enabled, true
@@ -143,11 +143,11 @@ def parse!(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
143143
opts.on('-x', '--expand', 'Expand Scenario Outline Tables in output.') { set_option :expand }
144144

145145
opts.on('--order TYPE[:SEED]', 'Run examples in the specified order. Available types:',
146-
*<<-TEXT.split("\n")) do |order|
147-
[defined] Run scenarios in the order they were defined (default).
148-
[random] Shuffle scenarios before running.
149-
Specify SEED to reproduce the shuffling from a previous run.
150-
e.g. --order random:5738
146+
*<<~TEXT.split("\n")) do |order|
147+
[defined] Run scenarios in the order they were defined (default).
148+
[random] Shuffle scenarios before running.
149+
Specify SEED to reproduce the shuffling from a previous run.
150+
e.g. --order random:5738
151151
TEXT
152152
@options[:order], @options[:seed] = *order.split(':')
153153
raise "'#{@options[:order]}' is not a recognised order type. Please use one of #{ORDER_TYPES.join(', ')}." unless ORDER_TYPES.include?(@options[:order])
@@ -522,7 +522,7 @@ def profile_loader
522522
@profile_loader ||= ProfileLoader.new
523523
end
524524

525-
def reverse_merge(other_options) # rubocop:disable Metrics/AbcSize
525+
def reverse_merge(other_options)
526526
@options = other_options.options.merge(@options)
527527
@options[:require] += other_options[:require]
528528
@options[:excludes] += other_options[:excludes]

lib/cucumber/cli/profile_loader.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ def initialize
1111

1212
def args_from(profile)
1313
unless cucumber_yml.key?(profile)
14-
raise(ProfileNotFound, <<-END_OF_ERROR)
15-
Could not find profile: '#{profile}'
14+
raise(ProfileNotFound, <<~END_OF_ERROR)
15+
Could not find profile: '#{profile}'
1616
17-
Defined profiles in cucumber.yml:
18-
* #{cucumber_yml.keys.sort.join("\n * ")}
17+
Defined profiles in cucumber.yml:
18+
* #{cucumber_yml.keys.sort.join("\n * ")}
1919
END_OF_ERROR
2020
end
2121

@@ -84,7 +84,7 @@ def process_configuration_file_with_erb
8484
def load_configuration
8585
require 'yaml'
8686
begin
87-
@cucumber_yml = YAML.load(@cucumber_erb) # rubocop:disable Security/YAMLLoad
87+
@cucumber_yml = YAML.load(@cucumber_erb)
8888
rescue StandardError
8989
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.\n")
9090
end

lib/cucumber/configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def formatter_factories
213213
yield factory,
214214
formatter_options,
215215
path_or_io
216-
rescue Exception => e # rubocop:disable Lint/RescueException
216+
rescue Exception => e
217217
raise e, "#{e.message}\nError creating formatter: #{format}", e.backtrace
218218
end
219219
end

0 commit comments

Comments
 (0)