Skip to content

Commit 7674288

Browse files
authored
Ruby: Additional rubocop config (#247)
* Add in new rubocop sub-gems - regenerate todo file * Autofix all remaining Layout cops * AF: Lint/UnusedBlockArgument£ * Fix 2 Lint cops that are very edge case * Fix HeredocDelimiterNames * Fix up Naming/BlockParameterName * AF: RSpec/DescribedClass * Fix Style/PerlBackrefs * Add changelog PR id * Fix erroneous rename of method * Refactor CombinatiorialExpressionFactory spec as it was named as a minitest file * Remove some line complexity from expression factory spec * Regenerate config and get code passable again in CI
1 parent 4740e47 commit 7674288

24 files changed

+210
-282
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
9+
### Changed
10+
- [Ruby] Added subsidiary rubocop gems (RSpec/Rake/Performance), and did some initial refactoring ([#247](https://github.com/cucumber/cucumber-expressions/pull/247))
911

1012
## [17.0.1] - 2023-11-24
1113
### Fixed

ruby/.rubocop.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
require:
2+
- rubocop-performance
3+
- rubocop-rake
4+
- rubocop-rspec
5+
16
inherit_from: .rubocop_todo.yml
27

38
inherit_mode:
@@ -15,13 +20,18 @@ Gemspec/RequireMFA:
1520
Layout/LineLength:
1621
Max: 200
1722

23+
# This is documented in this spec to showcase why it's not working and people shouldn't use it
24+
# cf:
25+
Lint/MixedRegexpCaptureTypes:
26+
Exclude:
27+
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
28+
1829
Style/Documentation:
1930
Enabled: false
2031

2132
Style/RegexpLiteral:
2233
EnforcedStyle: slashes
2334
AllowInnerSlashes: true
2435

25-
# Once we enable rubocop-rspec
26-
#RSpec/MessageSpies:
27-
# EnforcedStyle: receive
36+
RSpec/MessageSpies:
37+
EnforcedStyle: receive

ruby/.rubocop_todo.yml

Lines changed: 60 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,21 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-10-06 11:04:10 UTC using RuboCop version 1.27.0.
3+
# on 2023-11-27 17:52:56 UTC using RuboCop version 1.27.0.
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: Oct '23 -> 33 files inspected, 1004 offenses detected, 859 offenses auto-correctable
1010
# TODO: Oct '23 (later) -> 33 files inspected, 344 offenses detected, 205 offenses auto-correctable
11-
12-
# Offense count: 1
13-
# This cop supports safe auto-correction (--auto-correct).
14-
# Configuration parameters: EnforcedStyle, IndentationWidth.
15-
# SupportedStyles: outdent, indent
16-
Layout/AccessModifierIndentation:
17-
Exclude:
18-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'
11+
# TODO: Nov '23 -> 33 files inspected, 399 offenses detected, 192 offenses auto-correctable
1912

2013
# Offense count: 2
2114
# This cop supports safe auto-correction (--auto-correct).
22-
# Configuration parameters: EnforcedStyle, IndentationWidth.
15+
# Configuration parameters: IndentationWidth.
2316
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
2417
Layout/FirstArrayElementIndentation:
25-
Exclude:
26-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
27-
28-
# Offense count: 2
29-
# This cop supports safe auto-correction (--auto-correct).
30-
# Configuration parameters: EnforcedStyle, IndentationWidth.
31-
# SupportedStyles: special_inside_parentheses, consistent, align_braces
32-
Layout/FirstHashElementIndentation:
33-
Exclude:
34-
- 'cucumber-cucumber-expressions.gemspec'
35-
36-
# Offense count: 4
37-
# This cop supports safe auto-correction (--auto-correct).
38-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
39-
# SupportedHashRocketStyles: key, separator, table
40-
# SupportedColonStyles: key, separator, table
41-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
42-
Layout/HashAlignment:
43-
Exclude:
44-
- 'cucumber-cucumber-expressions.gemspec'
45-
46-
# Offense count: 2
47-
# This cop supports safe auto-correction (--auto-correct).
48-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
49-
# URISchemes: http, https
50-
Layout/LineLength:
51-
Max: 252
52-
53-
# Offense count: 1
54-
# This cop supports safe auto-correction (--auto-correct).
55-
# Configuration parameters: EnforcedStyle.
56-
# SupportedStyles: symmetrical, new_line, same_line
57-
Layout/MultilineMethodCallBraceLayout:
58-
Exclude:
59-
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
60-
61-
# Offense count: 3
62-
# This cop supports safe auto-correction (--auto-correct).
63-
# Configuration parameters: EnforcedStyle, IndentationWidth.
64-
# SupportedStyles: aligned, indented, indented_relative_to_receiver
65-
Layout/MultilineMethodCallIndentation:
66-
Exclude:
67-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'
68-
69-
# Offense count: 4
70-
# This cop supports safe auto-correction (--auto-correct).
71-
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
72-
# SupportedStylesForExponentOperator: space, no_space
73-
Layout/SpaceAroundOperators:
74-
Exclude:
75-
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
76-
77-
# Offense count: 57
78-
# This cop supports safe auto-correction (--auto-correct).
79-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
80-
# SupportedStyles: space, no_space
81-
# SupportedStylesForEmptyBraces: space, no_space
82-
Layout/SpaceInsideBlockBraces:
83-
Exclude:
84-
- 'cucumber-cucumber-expressions.gemspec'
85-
- 'lib/cucumber/cucumber_expressions/group_builder.rb'
86-
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
87-
- 'lib/cucumber/cucumber_expressions/regular_expression.rb'
88-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
89-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
90-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
91-
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
92-
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
93-
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
94-
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
18+
EnforcedStyle: consistent
9519

9620
# Offense count: 1
9721
# This cop supports safe auto-correction (--auto-correct).
@@ -114,47 +38,27 @@ Lint/DuplicateBranch:
11438
- 'lib/cucumber/cucumber_expressions/ast.rb'
11539
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
11640

117-
# Offense count: 10
41+
# Offense count: 5
11842
# Configuration parameters: AllowComments.
11943
Lint/EmptyClass:
12044
Exclude:
121-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
12245
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
12346
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
12447
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
12548

126-
# Offense count: 1
127-
Lint/MixedRegexpCaptureTypes:
128-
Exclude:
129-
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
130-
13149
# Offense count: 1
13250
# This cop supports unsafe auto-correction (--auto-correct-all).
13351
Lint/NonDeterministicRequireOrder:
13452
Exclude:
13553
- 'Rakefile'
13654

137-
# Offense count: 1
138-
Lint/NonLocalExitFromIterator:
139-
Exclude:
140-
- 'lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb'
141-
142-
# Offense count: 7
55+
# Offense count: 5
14356
# Configuration parameters: AllowKeywordBlockArguments.
14457
Lint/UnderscorePrefixedVariableName:
14558
Exclude:
146-
- 'lib/cucumber/cucumber_expressions/ast.rb'
14759
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
14860
- 'lib/cucumber/cucumber_expressions/group.rb'
14961

150-
# Offense count: 14
151-
# This cop supports safe auto-correction (--auto-correct).
152-
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
153-
Lint/UnusedBlockArgument:
154-
Exclude:
155-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
156-
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
157-
15862
# Offense count: 10
15963
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
16064
Metrics/AbcSize:
@@ -201,21 +105,6 @@ Metrics/ParameterLists:
201105
Metrics/PerceivedComplexity:
202106
Max: 17
203107

204-
# Offense count: 10
205-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
206-
Naming/BlockParameterName:
207-
Exclude:
208-
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
209-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
210-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
211-
212-
# Offense count: 2
213-
# Configuration parameters: ForbiddenDelimiters.
214-
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
215-
Naming/HeredocDelimiterNaming:
216-
Exclude:
217-
- 'lib/cucumber/cucumber_expressions/errors.rb'
218-
219108
# Offense count: 7
220109
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
221110
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
@@ -238,14 +127,59 @@ Naming/PredicateName:
238127
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
239128
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
240129

241-
# Offense count: 20
242-
# Configuration parameters: EnforcedStyle, AllowedIdentifiers.
243-
# SupportedStyles: snake_case, camelCase
244-
Naming/VariableName:
130+
# Offense count: 3
131+
# This cop supports safe auto-correction (--auto-correct).
132+
Performance/RedundantBlockCall:
245133
Exclude:
246134
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
247-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
248-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
135+
136+
# Offense count: 2
137+
# Configuration parameters: Prefixes.
138+
# Prefixes: when, with, without
139+
RSpec/ContextWording:
140+
Exclude:
141+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
142+
143+
# Offense count: 29
144+
# Configuration parameters: Max.
145+
RSpec/ExampleLength:
146+
Exclude:
147+
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'
148+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
149+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_parser_spec.rb'
150+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
151+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
152+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb'
153+
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
154+
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
155+
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
156+
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'
157+
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
158+
159+
# Offense count: 3
160+
RSpec/LeakyConstantDeclaration:
161+
Exclude:
162+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
163+
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
164+
165+
# Offense count: 34
166+
RSpec/MultipleExpectations:
167+
Max: 30
168+
169+
# Offense count: 1
170+
# Configuration parameters: AllowSubject.
171+
RSpec/MultipleMemoizedHelpers:
172+
Max: 6
173+
174+
# Offense count: 2
175+
RSpec/RepeatedDescription:
176+
Exclude:
177+
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
178+
179+
# Offense count: 2
180+
RSpec/RepeatedExample:
181+
Exclude:
182+
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
249183

250184
# Offense count: 2
251185
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
@@ -254,7 +188,7 @@ Style/AccessModifierDeclarations:
254188
Exclude:
255189
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
256190

257-
# Offense count: 5
191+
# Offense count: 4
258192
# This cop supports safe auto-correction (--auto-correct).
259193
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
260194
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
@@ -267,7 +201,6 @@ Style/BlockDelimiters:
267201
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
268202
- 'spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb'
269203
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
270-
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
271204

272205
# Offense count: 1
273206
# This cop supports unsafe auto-correction (--auto-correct-all).
@@ -378,12 +311,6 @@ Style/ParallelAssignment:
378311
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
379312
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
380313

381-
# Offense count: 1
382-
# This cop supports safe auto-correction (--auto-correct).
383-
Style/PerlBackrefs:
384-
Exclude:
385-
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
386-
387314
# Offense count: 1
388315
# This cop supports unsafe auto-correction (--auto-correct-all).
389316
# Configuration parameters: EnforcedStyle.
@@ -473,7 +400,7 @@ Style/SymbolProc:
473400
- 'lib/cucumber/cucumber_expressions/ast.rb'
474401
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
475402
- 'lib/cucumber/cucumber_expressions/errors.rb'
476-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
403+
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'
477404
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
478405
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
479406

@@ -484,7 +411,7 @@ Style/SymbolProc:
484411
Style/TrailingCommaInArrayLiteral:
485412
Exclude:
486413
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
487-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
414+
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'
488415

489416
# Offense count: 1
490417
# This cop supports safe auto-correction (--auto-correct).
@@ -494,14 +421,6 @@ Style/TrailingCommaInHashLiteral:
494421
Exclude:
495422
- 'cucumber-cucumber-expressions.gemspec'
496423

497-
# Offense count: 9
498-
# This cop supports safe auto-correction (--auto-correct).
499-
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods.
500-
# AllowedMethods: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym
501-
Style/TrivialAccessors:
502-
Exclude:
503-
- 'lib/cucumber/cucumber_expressions/ast.rb'
504-
505424
# Offense count: 1
506425
# This cop supports safe auto-correction (--auto-correct).
507426
Style/WhileUntilDo:

ruby/cucumber-cucumber-expressions.gemspec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ Gem::Specification.new do |s|
1717

1818
s.metadata = {
1919
'bug_tracker_uri' => 'https://github.com/cucumber/cucumber/issues',
20-
'changelog_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/CHANGELOG.md',
20+
'changelog_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/CHANGELOG.md',
2121
'documentation_uri' => 'https://cucumber.io/docs/cucumber/cucumber-expressions/',
22-
'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/cukes',
23-
'source_code_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/ruby',
22+
'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/cukes',
23+
'source_code_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/ruby',
2424
}
2525

2626
s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
2727
s.add_development_dependency 'rspec', '~> 3.11', '>= 3.11.0'
2828
s.add_development_dependency 'rubocop', '~> 1.27.0'
29+
s.add_development_dependency 'rubocop-performance', '~> 1.7.0'
30+
s.add_development_dependency 'rubocop-rake', '~> 0.5.0'
31+
s.add_development_dependency 'rubocop-rspec', '~> 2.0.0'
2932

3033
s.files = `git ls-files`.split("\n").reject { |path| path =~ /\.gitignore$/ }
3134
s.rdoc_options = ['--charset=UTF-8']

ruby/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def generate_permutations(generated_expressions, depth, current_parameter_types)
3030

3131
(0...@parameter_type_combinations[depth].length).each do |i|
3232
# Avoid recursion if no elements can be added.
33-
return if generated_expressions.length >= MAX_EXPRESSIONS
33+
break if generated_expressions.length >= MAX_EXPRESSIONS
3434

3535
new_current_parameter_types = current_parameter_types.dup # clone
3636
new_current_parameter_types.push(@parameter_type_combinations[depth][i])

0 commit comments

Comments
 (0)