Skip to content

Commit 67d4d5a

Browse files
authored
Refactor/initial rubocop rework (#1733)
* Remove poor cop config for this setting. It should be fixed up * Complexity metrics should definitely be fixed up in the codebase * Remove redundant enabling of cops now we use them by default in latest rubocop * These two cops are purely style related and relatively simple to tag and fix up * Reduce some metric offenses by 10% * Run rubocop on ruby 2.7 as that's our lowest supported version and target for cop offenses * Remove a bunch of hidden rubocop metric overrides * Re-generate the auto-gen-config * Add changelog * Re-generate config with new rule settings * Add new manual hacked settings * Make run green again * Add todo note * Fix changelog PR number
1 parent 6e2551b commit 67d4d5a

File tree

9 files changed

+111
-76
lines changed

9 files changed

+111
-76
lines changed

.github/workflows/rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- uses: ruby/setup-ruby@v1
1717
with:
18-
ruby-version: 3.2
18+
ruby-version: 2.7
1919
bundler-cache: true
20-
- run: bundle exec rake rubocop
20+
- run: bundle exec rubocop

.rubocop.yml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ AllCops:
2525
Layout/EndOfLine:
2626
EnforcedStyle: lf
2727

28-
# TODO: [LH] - This needs removing - legacy code. Initially move to auto-gen-config and then fix
29-
# Disabling this cop until the minimum Ruby version is >= 2.3 as squiggly
30-
# heredocs '<<~' were introduced then. The files below are the current ones
31-
# with offenses
32-
Layout/HeredocIndentation:
33-
Exclude:
34-
- 'features/lib/support/feature_factory.rb'
35-
- 'lib/cucumber/cli/options.rb'
36-
- 'lib/cucumber/cli/profile_loader.rb'
37-
- 'spec/cucumber/cli/configuration_spec.rb'
38-
- 'spec/cucumber/cli/profile_loader_spec.rb'
39-
- 'spec/cucumber/formatter/pretty_spec.rb'
40-
4128
# Reviewed: Formatters put trailing spaces after things like 'Feature: '
4229
# In pretty_spec.rb & progress_spec.rb offences look false as the trailing spaces are in fact multiline string literals
4330
Layout/TrailingWhitespace:
@@ -59,10 +46,14 @@ Lint/UselessMethodDefinition:
5946
Exclude:
6047
- 'lib/cucumber/glue/proto_world.rb'
6148

62-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
49+
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
6350
# to the auto-gen-config
6451
Metrics/AbcSize:
65-
Max: 45
52+
Max: 41
53+
# TODO: Manually added! - be careful with regenning the file - this needs a fix
54+
Exclude:
55+
- lib/cucumber/formatter/junit.rb
56+
- spec/cucumber/formatter/http_io_spec.rb
6657

6758
# TODO: [LH] - This needs a re-review. I think we can pretty much delete / phase this out with incremental updates
6859
Metrics/BlockLength:
@@ -77,29 +68,31 @@ Metrics/ClassLength:
7768
Max: 375
7869
Exclude:
7970
- 'lib/cucumber/cli/options.rb'
80-
81-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
82-
Metrics/CyclomaticComplexity:
83-
Max: 12
71+
# TODO: Manually added! - be careful with regenning the file - this needs a fix
72+
- lib/cucumber/formatter/pretty.rb
8473

8574
# A line length of 200 covers most violations in the repo while still being a more up to date length given today's screen sizes
8675
Layout/LineLength:
8776
Max: 200
8877

89-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
78+
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
9079
Metrics/ModuleLength:
91-
Max: 150
80+
Max: 135
9281
Exclude:
9382
- './spec/**/*'
9483
- 'cck/spec/**/*'
84+
# TODO: Manually added! - be careful with regenning the file - this needs a fix
85+
- lib/cucumber/formatter/console.rb
9586

96-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
87+
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
9788
Metrics/MethodLength:
98-
Max: 30
99-
100-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
101-
Metrics/PerceivedComplexity:
102-
Max: 13
89+
Max: 27
90+
# TODO: Manually added! - be careful with regenning the file - this needs a fix
91+
Exclude:
92+
- lib/cucumber/cli/main.rb
93+
- lib/cucumber/cli/options.rb
94+
- lib/cucumber/formatter/publish_banner_printer.rb
95+
- spec/cucumber/formatter/http_io_spec.rb
10396

10497
# Rubocop doesn't like method names in other languages but as Cucumber supports
10598
# languages, this cop needs to be disabled.
@@ -139,29 +132,17 @@ Naming/VariableNumber:
139132
# This cop throws errors when parsing a lot of the repo's code, possibly due
140133
# to splat issues?
141134
Style/AccessModifierDeclarations:
142-
Enabled: false
143-
144-
Style/ClassAndModuleChildren:
145135
Enabled: false
146136

147-
Style/ClassEqualityComparison:
148-
Enabled: true
149-
150137
Style/Documentation:
151138
Enabled: false
152139

153140
Style/FormatStringToken:
154141
EnforcedStyle: annotated
155142

156-
Style/FloatDivision:
157-
Enabled: false
158-
159143
Style/StderrPuts:
160144
Enabled: false
161145

162146
Style/RegexpLiteral:
163147
EnforcedStyle: slashes
164148
AllowInnerSlashes: true
165-
166-
Style/YodaCondition:
167-
Enabled: true

.rubocop_todo.yml

Lines changed: 85 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-09-01 11:47:49 UTC using RuboCop version 1.43.0.
3+
# on 2023-09-02 09:39:29 UTC using RuboCop version 1.56.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

9+
# TODO - [LH] -> Aug '23 - 370 files inspected, 1110 offenses detected, 482 offenses autocorrectable
10+
911
# Offense count: 38
1012
# This cop supports safe autocorrection (--autocorrect).
1113
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
@@ -19,12 +21,46 @@ Layout/HashAlignment:
1921
- 'lib/cucumber/formatter/ansicolor.rb'
2022
- 'lib/cucumber/gherkin/formatter/ansi_escapes.rb'
2123

24+
# Offense count: 13
25+
# This cop supports safe autocorrection (--autocorrect).
26+
Layout/HeredocIndentation:
27+
Exclude:
28+
- 'features/lib/support/feature_factory.rb'
29+
- 'lib/cucumber/cli/options.rb'
30+
- 'lib/cucumber/cli/profile_loader.rb'
31+
- 'spec/cucumber/cli/configuration_spec.rb'
32+
- 'spec/cucumber/cli/profile_loader_spec.rb'
33+
- 'spec/cucumber/formatter/pretty_spec.rb'
34+
35+
# Offense count: 1
36+
# This cop supports safe autocorrection (--autocorrect).
37+
# Configuration parameters: AllowedMethods, AllowedPatterns.
38+
Lint/AmbiguousBlockAssociation:
39+
Exclude:
40+
- 'spec/cucumber/glue/step_definition_spec.rb'
41+
42+
# Offense count: 1
43+
# This cop supports safe autocorrection (--autocorrect).
44+
Lint/RedundantCopDisableDirective:
45+
Exclude:
46+
- 'lib/cucumber/cli/options.rb'
47+
2248
# Offense count: 1
2349
# Configuration parameters: AllowComments, AllowNil.
2450
Lint/SuppressedException:
2551
Exclude:
2652
- 'lib/cucumber/rake/task.rb'
2753

54+
# Offense count: 9
55+
# Configuration parameters: AllowedMethods, AllowedPatterns.
56+
Metrics/CyclomaticComplexity:
57+
Max: 12
58+
59+
# Offense count: 9
60+
# Configuration parameters: AllowedMethods, AllowedPatterns.
61+
Metrics/PerceivedComplexity:
62+
Max: 13
63+
2864
# Offense count: 1
2965
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
3066
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
@@ -39,7 +75,7 @@ RSpec/AnyInstance:
3975
- 'spec/cucumber/cli/main_spec.rb'
4076

4177
# Offense count: 5
42-
# This cop supports safe autocorrection (--autocorrect).
78+
# This cop supports unsafe autocorrection (--autocorrect-all).
4379
RSpec/BeEql:
4480
Exclude:
4581
- 'spec/cucumber/cli/configuration_spec.rb'
@@ -69,7 +105,7 @@ RSpec/ContextMethod:
69105
- 'spec/cucumber/term/banner_spec.rb'
70106

71107
# Offense count: 98
72-
# Configuration parameters: Prefixes.
108+
# Configuration parameters: Prefixes, AllowedPatterns.
73109
# Prefixes: when, with, without
74110
RSpec/ContextWording:
75111
Enabled: false
@@ -78,6 +114,11 @@ RSpec/ContextWording:
78114
# Configuration parameters: IgnoredMetadata.
79115
RSpec/DescribeClass:
80116
Exclude:
117+
- '**/spec/features/**/*'
118+
- '**/spec/requests/**/*'
119+
- '**/spec/routing/**/*'
120+
- '**/spec/system/**/*'
121+
- '**/spec/views/**/*'
81122
- 'spec/cck/cck_spec.rb'
82123

83124
# Offense count: 167
@@ -88,6 +129,7 @@ RSpec/DescribedClass:
88129
Enabled: false
89130

90131
# Offense count: 2
132+
# This cop supports unsafe autocorrection (--autocorrect-all).
91133
RSpec/EmptyExampleGroup:
92134
Exclude:
93135
- 'spec/cucumber/filters/activate_steps_spec.rb'
@@ -122,28 +164,27 @@ RSpec/EmptyLineAfterFinalLet:
122164

123165
# Offense count: 3
124166
# This cop supports safe autocorrection (--autocorrect).
167+
# Configuration parameters: AllowConsecutiveOneLiners.
125168
RSpec/EmptyLineAfterHook:
126169
Exclude:
127170
- 'spec/cucumber/formatter/junit_spec.rb'
128171

129-
# Offense count: 6
172+
# Offense count: 2
130173
# This cop supports safe autocorrection (--autocorrect).
131174
RSpec/EmptyLineAfterSubject:
132175
Exclude:
133176
- 'spec/cucumber/filters/tag_limits/verifier_spec.rb'
134-
- 'spec/cucumber/hooks_spec.rb'
135177
- 'spec/cucumber/runtime/meta_message_builder_spec.rb'
136-
- 'spec/cucumber/runtime/support_code_spec.rb'
137-
- 'spec/cucumber/runtime_spec.rb'
138178

139179
# Offense count: 150
140-
# Configuration parameters: Max.
180+
# Configuration parameters: CountAsOne.
141181
RSpec/ExampleLength:
142-
Enabled: false
182+
Max: 58
143183

144184
# Offense count: 51
145185
# This cop supports safe autocorrection (--autocorrect).
146-
# Configuration parameters: CustomTransform, IgnoredWords.
186+
# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples.
187+
# DisallowedExamples: works
147188
RSpec/ExampleWording:
148189
Exclude:
149190
- 'spec/cucumber/cli/configuration_spec.rb'
@@ -155,7 +196,7 @@ RSpec/ExampleWording:
155196
# This cop supports safe autocorrection (--autocorrect).
156197
RSpec/ExpectActual:
157198
Exclude:
158-
- 'spec/routing/**/*'
199+
- '**/spec/routing/**/*'
159200
- 'spec/cucumber/cli/configuration_spec.rb'
160201
- 'spec/cucumber/step_match_spec.rb'
161202

@@ -195,16 +236,6 @@ RSpec/IteratedExpectation:
195236
Exclude:
196237
- 'spec/cucumber/filters/gated_receiver_spec.rb'
197238

198-
# Offense count: 6
199-
# This cop supports safe autocorrection (--autocorrect).
200-
RSpec/LeadingSubject:
201-
Exclude:
202-
- 'spec/cucumber/cli/main_spec.rb'
203-
- 'spec/cucumber/configuration_spec.rb'
204-
- 'spec/cucumber/formatter/url_reporter_spec.rb'
205-
- 'spec/cucumber/rake/forked_spec.rb'
206-
- 'spec/cucumber/runtime/support_code_spec.rb'
207-
208239
# Offense count: 59
209240
# Configuration parameters: EnforcedStyle.
210241
# SupportedStyles: have_received, receive
@@ -242,7 +273,8 @@ RSpec/MultipleMemoizedHelpers:
242273
Max: 15
243274

244275
# Offense count: 46
245-
# Configuration parameters: IgnoreSharedExamples.
276+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
277+
# SupportedStyles: always, named_only
246278
RSpec/NamedSubject:
247279
Exclude:
248280
- 'spec/cucumber/cli/main_spec.rb'
@@ -255,6 +287,7 @@ RSpec/NamedSubject:
255287
- 'spec/cucumber/runtime_spec.rb'
256288

257289
# Offense count: 6
290+
# Configuration parameters: AllowedGroups.
258291
RSpec/NestedGroups:
259292
Max: 6
260293

@@ -354,6 +387,36 @@ Rake/Desc:
354387
- 'gem_tasks/contributors.rake'
355388
- 'gem_tasks/environment.rake'
356389

390+
# Offense count: 11
391+
# This cop supports unsafe autocorrection (--autocorrect-all).
392+
# Configuration parameters: EnforcedStyle.
393+
# SupportedStyles: nested, compact
394+
Style/ClassAndModuleChildren:
395+
Exclude:
396+
- 'lib/autotest/cucumber.rb'
397+
- 'lib/autotest/cucumber_mixin.rb'
398+
- 'lib/autotest/cucumber_rails.rb'
399+
- 'lib/autotest/cucumber_rails_rspec.rb'
400+
- 'lib/autotest/cucumber_rails_rspec2.rb'
401+
- 'lib/autotest/cucumber_rspec.rb'
402+
- 'lib/autotest/cucumber_rspec2.rb'
403+
- 'spec/cucumber/deprecate_spec.rb'
404+
- 'spec/cucumber/formatter/fail_fast_spec.rb'
405+
- 'spec/cucumber/formatter/interceptor_spec.rb'
406+
- 'spec/cucumber/hooks_spec.rb'
407+
408+
# Offense count: 3
409+
Style/ClassVars:
410+
Exclude:
411+
- 'spec/cucumber/glue/step_definition_spec.rb'
412+
413+
# Offense count: 22
414+
# This cop supports unsafe autocorrection (--autocorrect-all).
415+
# Configuration parameters: EnforcedStyle.
416+
# SupportedStyles: left_coerce, right_coerce, single_coerce, fdiv
417+
Style/FloatDivision:
418+
Enabled: false
419+
357420
# Offense count: 5
358421
# This cop supports unsafe autocorrection (--autocorrect-all).
359422
# Configuration parameters: EnforcedStyle.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1414

1515
- Gem update. Update rubocop gems to latest and increase minimum version of some cucumber sub-gems ([#1732](https://github.com/cucumber/cucumber-ruby/pull/1732) [luke-hill](https://github.com/luke-hill))
1616

17+
- Rubocop update. Massively overhauled the cucumber style / rubocop expectations and began to tackle some long-standing tech-debt ([#1733](https://github.com/cucumber/cucumber-ruby/pull/1733) [luke-hill](https://github.com/luke-hill))
18+
1719
## [9.0.1] - 2023-09-01
1820
### Changed
1921
- Update dependency of a few associated cucumber sub-gems ([#1715](https://github.com/cucumber/cucumber-ruby/pull/1715) [luke-hill](https://github.com/luke-hill))

lib/cucumber/formatter/console.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
# rubocop:disable Metrics/ModuleLength
4-
53
require 'cucumber/formatter/ansicolor'
64
require 'cucumber/formatter/duration'
75
require 'cucumber/gherkin/i18n'
@@ -262,4 +260,3 @@ def initialize(actual_keyword, step)
262260
end
263261
end
264262
end
265-
# rubocop:enable Metrics/ModuleLength

lib/cucumber/formatter/pretty.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Formatter
1919
#
2020
# If the output is STDOUT (and not a file), there are bright colours to watch too.
2121
#
22-
class Pretty # rubocop:disable Metrics/ClassLength
22+
class Pretty
2323
include FileUtils
2424
include Console
2525
include Io

lib/cucumber/formatter/publish_banner_printer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def initialize(configuration)
1515
end
1616
end
1717

18-
# rubocop:disable Metrics/MethodLength
1918
def display_publish_ad(io)
2019
display_banner(
2120
[
@@ -59,7 +58,6 @@ def display_publish_ad(io)
5958
io
6059
)
6160
end
62-
# rubocop:enable Metrics/MethodLength
6361

6462
def highlight(text)
6563
[text, :cyan]

0 commit comments

Comments
 (0)