Skip to content

Commit f031424

Browse files
authored
Refactor/layout lint fixes (#1750)
* Autofix and then manually tidy up Layout/HashAlignment * AF: Layout/TrailingWhiteSpace * AF: Lint/AmbiguousOperator * Remove the muddy situation where cops are duplicated in TODO and in regular style file. The regular style file is now almost completed * Regenerate TODO * Partial fix for MemoizedInstanceVariableName - we only had one usage for the private method so make a better fetching paradigm and remove the erroneous memoizer * Partial fixes for some variable names used in method / blocks * AF: RSpec/ReturnFromStub * Fixes for described class in rspec * Partial fix to begin removing verbose iVars * Fix remnants of invalid iVar assign * Some limited context wording fixes * Manually fix Naming/VariableNumber * Partial manual fix of Naming/MethodParameterName * Add changelog note
1 parent b126fc8 commit f031424

28 files changed

+201
-288
lines changed

.rubocop.yml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,7 @@ Lint/UselessMethodDefinition:
4141
Exclude:
4242
- lib/cucumber/glue/proto_world.rb
4343

44-
# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
45-
Metrics/ClassLength:
46-
Max: 375
47-
Exclude:
48-
- lib/cucumber/cli/options.rb
49-
# TODO: Manually added! - be careful with regenning the file - this needs a fix
50-
- lib/cucumber/formatter/pretty.rb
51-
52-
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
53-
Metrics/ModuleLength:
54-
Max: 135
55-
Exclude:
56-
- spec/**/*
57-
# TODO: Manually added! - be careful with regenning the file - this needs a fix
58-
- lib/cucumber/formatter/console.rb
59-
60-
# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
61-
Metrics/MethodLength:
62-
Max: 27
63-
# TODO: Manually added! - be careful with regenning the file - this needs a fix
64-
Exclude:
65-
- lib/cucumber/cli/main.rb
66-
- lib/cucumber/cli/options.rb
67-
- lib/cucumber/formatter/publish_banner_printer.rb
68-
- spec/cucumber/formatter/http_io_spec.rb
69-
- lib/cucumber/glue/proto_world.rb
70-
71-
# Rubocop doesn't like method names in other languages but as Cucumber supports multiple languages, this cop needs to be disabled.
44+
# Rubocop doesn't like method names in other languages but as Cucumber supports multiple languages, this cop needs to be disabled
7245
Naming/AsciiIdentifiers:
7346
Enabled: false
7447

@@ -77,8 +50,7 @@ Naming/FileName:
7750
Exclude:
7851
- compatibility/features/**/*
7952

80-
# For the most part, the project is solid on naming. There are though, a few
81-
# cases where the cop doesn't need to catch.
53+
# For the most part, the project is solid on naming. There are though, a few cases where the cop doesn't need to catch
8254
Naming/MethodName:
8355
Exclude:
8456
- examples/i18n/ar/lib/calculator.rb

.rubocop_todo.yml

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,14 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-12-08 14:57:03 UTC using RuboCop version 1.56.4.
3+
# on 2024-01-17 12:23:33 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] -> Sep 6 '23 - 370 files inspected, 983 offenses detected, 368 offenses autocorrectable
10-
# TODO - [LH] -> Sep 11 '23 - 370 files inspected, 825 offenses detected, 387 offenses autocorrectable
11-
# TODO - [LH] -> Sep 19 '23 - 370 files inspected, 640 offenses detected, 202 offenses autocorrectable
129
# TODO - [LH] -> Oct '23 - 355 files inspected, 642 offenses detected, 205 offenses autocorrectable
1310
# TODO - [LH] -> Dec '23 - 350 files inspected, 595 offenses detected, 171 offenses autocorrectable
14-
15-
# Offense count: 10
16-
# This cop supports safe autocorrection (--autocorrect).
17-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
18-
# SupportedHashRocketStyles: key, separator, table
19-
# SupportedColonStyles: key, separator, table
20-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
21-
Layout/HashAlignment:
22-
Exclude:
23-
- 'lib/cucumber/cli/options.rb'
24-
25-
# Offense count: 19
26-
# This cop supports safe autocorrection (--autocorrect).
27-
# Configuration parameters: AllowInHeredoc.
28-
Layout/TrailingWhitespace:
29-
Exclude:
30-
- 'lib/cucumber/multiline_argument/data_table.rb'
31-
32-
# Offense count: 3
33-
# This cop supports safe autocorrection (--autocorrect).
34-
Lint/AmbiguousOperator:
35-
Exclude:
36-
- 'lib/cucumber/multiline_argument/data_table.rb'
37-
- 'lib/cucumber/running_test_case.rb'
38-
- 'spec/cucumber/formatter/spec_helper.rb'
11+
# TODO - [LH] -> Jan '23 (cleaned up most of the config) - 364 files inspected, 713 offenses detected, 132 offenses autocorrectable
3912

4013
# Offense count: 4
4114
Lint/RescueException:
@@ -45,7 +18,7 @@ Lint/RescueException:
4518
- 'lib/cucumber/glue/invoke_in_world.rb'
4619
- 'lib/cucumber/glue/proto_world.rb'
4720

48-
# Offense count: 4
21+
# Offense count: 60
4922
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
5023
Metrics/AbcSize:
5124
Max: 127
@@ -56,11 +29,26 @@ Metrics/AbcSize:
5629
Metrics/BlockLength:
5730
Max: 52
5831

32+
# Offense count: 13
33+
# Configuration parameters: CountComments, CountAsOne.
34+
Metrics/ClassLength:
35+
Max: 523
36+
5937
# Offense count: 8
6038
# Configuration parameters: AllowedMethods, AllowedPatterns.
6139
Metrics/CyclomaticComplexity:
6240
Max: 12
6341

42+
# Offense count: 74
43+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
44+
Metrics/MethodLength:
45+
Max: 72
46+
47+
# Offense count: 17
48+
# Configuration parameters: CountComments, CountAsOne.
49+
Metrics/ModuleLength:
50+
Max: 804
51+
6452
# Offense count: 7
6553
# Configuration parameters: AllowedMethods, AllowedPatterns.
6654
Metrics/PerceivedComplexity:
@@ -131,12 +119,6 @@ RSpec/ContextWording:
131119
- 'spec/cucumber/formatter/publish_banner_printer_spec.rb'
132120
- 'spec/cucumber/glue/step_definition_spec.rb'
133121

134-
# Offense count: 1
135-
# Configuration parameters: IgnoredMetadata.
136-
RSpec/DescribeClass:
137-
Exclude:
138-
- 'spec/cck/cck_spec.rb'
139-
140122
# Offense count: 8
141123
# This cop supports unsafe autocorrection (--autocorrect-all).
142124
# Configuration parameters: SkipBlocks, EnforcedStyle.
@@ -222,7 +204,7 @@ RSpec/MissingExampleGroupArgument:
222204
- 'spec/cucumber/formatter/fail_fast_spec.rb'
223205
- 'spec/cucumber/formatter/rerun_spec.rb'
224206

225-
# Offense count: 59
207+
# Offense count: 58
226208
RSpec/MultipleExpectations:
227209
Max: 3
228210

@@ -317,31 +299,12 @@ RSpec/VerifiedDoubles:
317299
- 'spec/cucumber/runtime/support_code_spec.rb'
318300
- 'spec/cucumber/world/pending_spec.rb'
319301

320-
# Offense count: 1
321-
Security/Open:
322-
Exclude:
323-
- 'lib/autotest/cucumber_mixin.rb'
324-
325302
# Offense count: 1
326303
# This cop supports unsafe autocorrection (--autocorrect-all).
327304
Security/YAMLLoad:
328305
Exclude:
329306
- 'lib/cucumber/cli/profile_loader.rb'
330307

331-
# Offense count: 7
332-
# This cop supports unsafe autocorrection (--autocorrect-all).
333-
# Configuration parameters: EnforcedStyle.
334-
# SupportedStyles: nested, compact
335-
Style/ClassAndModuleChildren:
336-
Exclude:
337-
- 'lib/autotest/cucumber.rb'
338-
- 'lib/autotest/cucumber_mixin.rb'
339-
- 'lib/autotest/cucumber_rails.rb'
340-
- 'lib/autotest/cucumber_rails_rspec.rb'
341-
- 'lib/autotest/cucumber_rails_rspec2.rb'
342-
- 'lib/autotest/cucumber_rspec.rb'
343-
- 'lib/autotest/cucumber_rspec2.rb'
344-
345308
# Offense count: 3
346309
Style/ClassVars:
347310
Exclude:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
1414
### Changed
1515
- Moved all CCK step definition/miscellaneous file logic from CCK gem to this repo.
1616
All logic contained in [compatibility](./compatibility) ([luke-hill](https://github.com/luke-hill))
17+
- Cleared up a few Layout/Linting cop offenses ([#1750](https://github.com/cucumber/cucumber-ruby/pull/1750) [luke-hill](https://github.com/luke-hill))
1718

1819
### Fixed
1920
- Fix a situation whereby the step definition message will omit the parameter-type name when it cannot be inferred

examples/i18n/bg/lib/calculator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ def result
1414
end
1515

1616
def +
17-
number_1 = @stack.pop
18-
number_2 = @stack.pop
17+
number1 = @stack.pop
18+
number2 = @stack.pop
1919

20-
@stack.push number_1 + number_2
20+
@stack.push(number1 + number2)
2121
end
2222

2323
def /
2424
divisor = @stack.pop
2525
dividend = @stack.pop
2626

27-
@stack.push dividend / divisor
27+
@stack.push(dividend / divisor)
2828
end
2929
end

examples/i18n/ru/lib/calculator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def result
1414
end
1515

1616
def +
17-
number_1 = @stack.pop
18-
number_2 = @stack.pop
17+
number1 = @stack.pop
18+
number2 = @stack.pop
1919

20-
@stack.push(number_1 + number_2)
20+
@stack.push(number1 + number2)
2121
end
2222

2323
def /

examples/i18n/uk/lib/calculator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def result
1414
end
1515

1616
def +
17-
number_1 = @stack.pop
18-
number_2 = @stack.pop
17+
number1 = @stack.pop
18+
number2 = @stack.pop
1919

20-
@stack.push(number_1 + number_2)
20+
@stack.push(number1 + number2)
2121
end
2222

2323
def /

examples/i18n/uz/lib/calculator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def result
1414
end
1515

1616
def +
17-
number_1 = @stack.pop
18-
number_2 = @stack.pop
17+
number1 = @stack.pop
18+
number2 = @stack.pop
1919

20-
@stack.push(number_1 + number_2)
20+
@stack.push(number1 + number2)
2121
end
2222

2323
def /

lib/cucumber/cli/options.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ class Options
1212
CUCUMBER_PUBLISH_URL = ENV['CUCUMBER_PUBLISH_URL'] || 'https://messages.cucumber.io/api/reports -X GET'
1313
INDENT = ' ' * 53
1414
BUILTIN_FORMATS = {
15-
'pretty' => ['Cucumber::Formatter::Pretty', 'Prints the feature as is - in colours.'],
16-
'progress' => ['Cucumber::Formatter::Progress', 'Prints one character per scenario.'],
17-
'rerun' => ['Cucumber::Formatter::Rerun', 'Prints failing files with line numbers.'],
18-
'usage' => ['Cucumber::Formatter::Usage', "Prints where step definitions are used.\n" \
19-
"#{INDENT}The slowest step definitions (with duration) are\n" \
20-
"#{INDENT}listed first. If --dry-run is used the duration\n" \
21-
"#{INDENT}is not shown, and step definitions are sorted by\n" \
22-
"#{INDENT}filename instead."],
23-
'stepdefs' => ['Cucumber::Formatter::Stepdefs', "Prints All step definitions with their locations. Same as\n" \
24-
"#{INDENT}the usage formatter, except that steps are not printed."],
25-
'junit' => ['Cucumber::Formatter::Junit', "Generates a report similar to Ant+JUnit. Use\n" \
26-
"#{INDENT}junit,fileattribute=true to include a file attribute."],
27-
'json' => ['Cucumber::Formatter::Json', "Prints the feature as JSON.\n" \
28-
"#{INDENT}The JSON format is in maintenance mode.\n" \
29-
"#{INDENT}Please consider using the message formatter\n"\
30-
"#{INDENT}with the standalone json-formatter\n" \
31-
"#{INDENT}(https://github.com/cucumber/cucumber/tree/master/json-formatter)."],
32-
'message' => ['Cucumber::Formatter::Message', 'Prints each message in NDJSON form, which can then be consumed by other tools.'],
33-
'html' => ['Cucumber::Formatter::HTML', 'Outputs HTML report'],
34-
'summary' => ['Cucumber::Formatter::Summary', 'Summary output of feature and scenarios']
15+
'pretty' => ['Cucumber::Formatter::Pretty', 'Prints the feature as is - in colours.'],
16+
'progress' => ['Cucumber::Formatter::Progress', 'Prints one character per scenario.'],
17+
'rerun' => ['Cucumber::Formatter::Rerun', 'Prints failing files with line numbers.'],
18+
'usage' => ['Cucumber::Formatter::Usage', "Prints where step definitions are used.\n" \
19+
"#{INDENT}The slowest step definitions (with duration) are\n" \
20+
"#{INDENT}listed first. If --dry-run is used the duration\n" \
21+
"#{INDENT}is not shown, and step definitions are sorted by\n" \
22+
"#{INDENT}filename instead."],
23+
'stepdefs' => ['Cucumber::Formatter::Stepdefs', "Prints All step definitions with their locations. Same as\n" \
24+
"#{INDENT}the usage formatter, except that steps are not printed."],
25+
'junit' => ['Cucumber::Formatter::Junit', "Generates a report similar to Ant+JUnit. Use\n" \
26+
"#{INDENT}junit,fileattribute=true to include a file attribute."],
27+
'json' => ['Cucumber::Formatter::Json', "Prints the feature as JSON.\n" \
28+
"#{INDENT}The JSON format is in maintenance mode.\n" \
29+
"#{INDENT}Please consider using the message formatter\n"\
30+
"#{INDENT}with the standalone json-formatter\n" \
31+
"#{INDENT}(https://github.com/cucumber/cucumber/tree/master/json-formatter)."],
32+
'message' => ['Cucumber::Formatter::Message', 'Prints each message in NDJSON form, which can then be consumed by other tools.'],
33+
'html' => ['Cucumber::Formatter::HTML', 'Outputs HTML report'],
34+
'summary' => ['Cucumber::Formatter::Summary', 'Summary output of feature and scenarios']
3535
}.freeze
3636
max = BUILTIN_FORMATS.keys.map(&:length).max
3737
FORMAT_HELP_MSG = [
@@ -295,9 +295,9 @@ def strict_msg
295295
]
296296
end
297297

298-
def parse_formats(v)
299-
formatter, *formatter_options = v.split(',')
300-
options_hash = Hash[formatter_options.map { |s| s.split('=') }]
298+
def parse_formats(value)
299+
formatter, *formatter_options = value.split(',')
300+
options_hash = Hash[formatter_options.map { |string| string.split('=') }]
301301
[formatter, options_hash]
302302
end
303303

@@ -375,12 +375,12 @@ def banner
375375
].join("\n")
376376
end
377377

378-
def require_files(v)
379-
@options[:require] << v
380-
return unless Cucumber::JRUBY && File.directory?(v)
378+
def require_files(filenames)
379+
@options[:require] << filenames
380+
return unless Cucumber::JRUBY && File.directory?(filenames)
381381

382382
require 'java'
383-
$CLASSPATH << v
383+
$CLASSPATH << filenames
384384
end
385385

386386
def require_jars(jars)
@@ -441,8 +441,8 @@ def initialize_project
441441
ProjectInitializer.new.run && Kernel.exit(0)
442442
end
443443

444-
def add_profile(p)
445-
@profiles << p
444+
def add_profile(profile)
445+
@profiles << profile
446446
end
447447

448448
def set_option(option, value = nil)

lib/cucumber/formatter/ansicolor.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ module Formatter
6363
module ANSIColor
6464
include Cucumber::Term::ANSIColor
6565

66-
# :stopdoc:
6766
ALIASES = Hash.new do |h, k|
6867
next unless k.to_s =~ /(.*)_param/
6968

@@ -79,13 +78,8 @@ module ANSIColor
7978
'comment' => 'grey',
8079
'tag' => 'cyan'
8180
)
82-
# :startdoc:
8381

84-
# Apply the custom color scheme
85-
#
86-
# example:
87-
#
88-
# apply_custom_colors('passed=white')
82+
# Apply the custom color scheme -> i.e. apply_custom_colors('passed=white')
8983
def self.apply_custom_colors(colors)
9084
colors.split(':').each do |pair|
9185
a = pair.split('=')
@@ -117,23 +111,21 @@ def self.apply_custom_colors(colors)
117111
end
118112
end
119113

120-
# :stopdoc:
121-
def cukes(n)
122-
('(::) ' * n).strip
114+
def cukes(amount)
115+
('(::) ' * amount).strip
123116
end
124117

125-
def green_cukes(n)
126-
blink(green(cukes(n)))
118+
def green_cukes(amount)
119+
blink(green(cukes(amount)))
127120
end
128121

129-
def red_cukes(n)
130-
blink(red(cukes(n)))
122+
def red_cukes(amount)
123+
blink(red(cukes(amount)))
131124
end
132125

133-
def yellow_cukes(n)
134-
blink(yellow(cukes(n)))
126+
def yellow_cukes(amount)
127+
blink(yellow(cukes(amount)))
135128
end
136-
# :startdoc:
137129

138130
private
139131

0 commit comments

Comments
 (0)