Skip to content

Commit 82b3869

Browse files
authored
Ruby: Layout rubocop fixes (#235)
* Remove redundant crud from rakefile * AF: Layout/EmptyLineAfterGuardClause * AF: Layout/EmptyLineAfterMagicComment * AF: Layout/EmptyLineBetweenDefs * AF: Layout/EmptyLinesAroundBlockBody * AF: Layout/EmptyLinesAroundClassBody * AF: Layout/ExtraSpacing * AF: Layout/EmptyLinesAroundModuleBody * AF: Layout/HeredocIndentation * AF: Layout/SpaceAroundEqualsInParameterDefault * AF: Layout/SpaceBeforeBlockBraces * AF: Layout/SpaceInsideParens * AF: Layout/TrailingEmptyLines * AF: Layout/SpaceInLambdaLiteral * Re-generated auto-gen-config file * Use attr readers for performance gain
1 parent 66964f5 commit 82b3869

21 files changed

+73
-221
lines changed

ruby/.rubocop_todo.yml

Lines changed: 9 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-10-03 17:06:00 UTC using RuboCop version 1.27.0.
3+
# on 2023-10-06 11:04:10 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
10+
# TODO: Oct '23 (later) -> 33 files inspected, 344 offenses detected, 205 offenses auto-correctable
1011

1112
# Offense count: 1
1213
# This cop supports safe auto-correction (--auto-correct).
@@ -16,96 +17,21 @@ Layout/AccessModifierIndentation:
1617
Exclude:
1718
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'
1819

19-
# Offense count: 23
20-
# This cop supports safe auto-correction (--auto-correct).
21-
Layout/EmptyLineAfterGuardClause:
22-
Exclude:
23-
- 'lib/cucumber/cucumber_expressions/argument.rb'
24-
- 'lib/cucumber/cucumber_expressions/ast.rb'
25-
- 'lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb'
26-
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
27-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
28-
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
29-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
30-
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
31-
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
32-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
33-
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'
34-
35-
# Offense count: 2
36-
# This cop supports safe auto-correction (--auto-correct).
37-
Layout/EmptyLineAfterMagicComment:
38-
Exclude:
39-
- 'Gemfile'
40-
- 'Rakefile'
41-
42-
# Offense count: 1
43-
# This cop supports safe auto-correction (--auto-correct).
44-
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
45-
Layout/EmptyLineBetweenDefs:
46-
Exclude:
47-
- 'lib/cucumber/cucumber_expressions/ast.rb'
48-
4920
# Offense count: 2
5021
# This cop supports safe auto-correction (--auto-correct).
51-
Layout/EmptyLines:
52-
Exclude:
53-
- 'lib/cucumber/cucumber_expressions/ast.rb'
54-
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
55-
56-
# Offense count: 2
57-
# This cop supports safe auto-correction (--auto-correct).
58-
# Configuration parameters: EnforcedStyle.
59-
# SupportedStyles: empty_lines, no_empty_lines
60-
Layout/EmptyLinesAroundBlockBody:
61-
Exclude:
62-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
63-
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
64-
65-
# Offense count: 4
66-
# This cop supports safe auto-correction (--auto-correct).
67-
# Configuration parameters: EnforcedStyle.
68-
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
69-
Layout/EmptyLinesAroundClassBody:
70-
Exclude:
71-
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
72-
- 'lib/cucumber/cucumber_expressions/errors.rb'
73-
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
74-
- 'lib/cucumber/cucumber_expressions/regular_expression.rb'
75-
76-
# Offense count: 1
77-
# This cop supports safe auto-correction (--auto-correct).
78-
# Configuration parameters: EnforcedStyle.
79-
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
80-
Layout/EmptyLinesAroundModuleBody:
81-
Exclude:
82-
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
83-
84-
# Offense count: 1
85-
# This cop supports safe auto-correction (--auto-correct).
86-
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
87-
Layout/ExtraSpacing:
88-
Exclude:
89-
- 'cucumber-cucumber-expressions.gemspec'
90-
91-
# Offense count: 4
92-
# This cop supports safe auto-correction (--auto-correct).
9322
# Configuration parameters: EnforcedStyle, IndentationWidth.
9423
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
9524
Layout/FirstArrayElementIndentation:
9625
Exclude:
97-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
98-
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
9926
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
10027

101-
# Offense count: 3
28+
# Offense count: 2
10229
# This cop supports safe auto-correction (--auto-correct).
10330
# Configuration parameters: EnforcedStyle, IndentationWidth.
10431
# SupportedStyles: special_inside_parentheses, consistent, align_braces
10532
Layout/FirstHashElementIndentation:
10633
Exclude:
10734
- 'cucumber-cucumber-expressions.gemspec'
108-
- 'lib/cucumber/cucumber_expressions/ast.rb'
10935

11036
# Offense count: 4
11137
# This cop supports safe auto-correction (--auto-correct).
@@ -117,12 +43,6 @@ Layout/HashAlignment:
11743
Exclude:
11844
- 'cucumber-cucumber-expressions.gemspec'
11945

120-
# Offense count: 2
121-
# This cop supports safe auto-correction (--auto-correct).
122-
Layout/HeredocIndentation:
123-
Exclude:
124-
- 'lib/cucumber/cucumber_expressions/errors.rb'
125-
12646
# Offense count: 2
12747
# This cop supports safe auto-correction (--auto-correct).
12848
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
@@ -146,43 +66,15 @@ Layout/MultilineMethodCallIndentation:
14666
Exclude:
14767
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'
14868

149-
# Offense count: 2
150-
# This cop supports safe auto-correction (--auto-correct).
151-
# Configuration parameters: EnforcedStyle.
152-
# SupportedStyles: space, no_space
153-
Layout/SpaceAroundEqualsInParameterDefault:
154-
Exclude:
155-
- 'lib/cucumber/cucumber_expressions/argument.rb'
156-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
157-
158-
# Offense count: 5
69+
# Offense count: 4
15970
# This cop supports safe auto-correction (--auto-correct).
16071
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
16172
# SupportedStylesForExponentOperator: space, no_space
16273
Layout/SpaceAroundOperators:
16374
Exclude:
164-
- 'cucumber-cucumber-expressions.gemspec'
16575
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
16676

167-
# Offense count: 2
168-
# This cop supports safe auto-correction (--auto-correct).
169-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
170-
# SupportedStyles: space, no_space
171-
# SupportedStylesForEmptyBraces: space, no_space
172-
Layout/SpaceBeforeBlockBraces:
173-
Exclude:
174-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
175-
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
176-
177-
# Offense count: 2
178-
# This cop supports safe auto-correction (--auto-correct).
179-
# Configuration parameters: EnforcedStyle.
180-
# SupportedStyles: require_no_space, require_space
181-
Layout/SpaceInLambdaLiteral:
182-
Exclude:
183-
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
184-
185-
# Offense count: 58
77+
# Offense count: 57
18678
# This cop supports safe auto-correction (--auto-correct).
18779
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
18880
# SupportedStyles: space, no_space
@@ -191,7 +83,6 @@ Layout/SpaceInsideBlockBraces:
19183
Exclude:
19284
- 'cucumber-cucumber-expressions.gemspec'
19385
- 'lib/cucumber/cucumber_expressions/group_builder.rb'
194-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
19586
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
19687
- 'lib/cucumber/cucumber_expressions/regular_expression.rb'
19788
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
@@ -202,22 +93,6 @@ Layout/SpaceInsideBlockBraces:
20293
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
20394
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
20495

205-
# Offense count: 24
206-
# This cop supports safe auto-correction (--auto-correct).
207-
# Configuration parameters: EnforcedStyle.
208-
# SupportedStyles: space, compact, no_space
209-
Layout/SpaceInsideParens:
210-
Exclude:
211-
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'
212-
213-
# Offense count: 1
214-
# This cop supports safe auto-correction (--auto-correct).
215-
# Configuration parameters: EnforcedStyle.
216-
# SupportedStyles: final_newline, final_blank_line
217-
Layout/TrailingEmptyLines:
218-
Exclude:
219-
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
220-
22196
# Offense count: 1
22297
# This cop supports safe auto-correction (--auto-correct).
22398
Lint/AmbiguousOperatorPrecedence:
@@ -299,7 +174,7 @@ Metrics/BlockNesting:
299174
# Offense count: 1
300175
# Configuration parameters: CountComments, CountAsOne.
301176
Metrics/ClassLength:
302-
Max: 151
177+
Max: 141
303178

304179
# Offense count: 7
305180
# Configuration parameters: IgnoredMethods.
@@ -309,7 +184,7 @@ Metrics/CyclomaticComplexity:
309184
# Offense count: 20
310185
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
311186
Metrics/MethodLength:
312-
Max: 71
187+
Max: 61
313188

314189
# Offense count: 4
315190
# Configuration parameters: CountComments, CountAsOne.
@@ -379,7 +254,7 @@ Style/AccessModifierDeclarations:
379254
Exclude:
380255
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
381256

382-
# Offense count: 7
257+
# Offense count: 5
383258
# This cop supports safe auto-correction (--auto-correct).
384259
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
385260
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
@@ -389,8 +264,6 @@ Style/AccessModifierDeclarations:
389264
Style/BlockDelimiters:
390265
Exclude:
391266
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
392-
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
393-
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
394267
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
395268
- 'spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb'
396269
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
@@ -414,11 +287,10 @@ Style/EmptyLiteral:
414287
Exclude:
415288
- 'lib/cucumber/cucumber_expressions/ast.rb'
416289

417-
# Offense count: 2
290+
# Offense count: 1
418291
# This cop supports safe auto-correction (--auto-correct).
419292
Style/Encoding:
420293
Exclude:
421-
- 'Rakefile'
422294
- 'cucumber-cucumber-expressions.gemspec'
423295

424296
# Offense count: 1

ruby/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# frozen_string_literal: true
2+
23
source 'https://rubygems.org'
34
gemspec

ruby/Rakefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# encoding: utf-8
21
# frozen_string_literal: true
3-
require 'rubygems'
4-
require 'bundler'
5-
Bundler::GemHelper.install_tasks
62

73
$:.unshift File.expand_path('../lib', __FILE__)
84

ruby/cucumber-cucumber-expressions.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.license = 'MIT'
1616
s.required_ruby_version = '>= 2.5'
1717

18-
s.metadata = {
18+
s.metadata = {
1919
'bug_tracker_uri' => 'https://github.com/cucumber/cucumber/issues',
2020
'changelog_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/CHANGELOG.md',
2121
'documentation_uri' => 'https://cucumber.io/docs/cucumber/cucumber-expressions/',

ruby/lib/cucumber/cucumber_expressions/argument.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def initialize(group, parameter_type)
2929
@group, @parameter_type = group, parameter_type
3030
end
3131

32-
def value(self_obj=:nil)
32+
def value(self_obj = :nil)
3333
raise 'No self_obj' if self_obj == :nil
34+
3435
group_values = @group ? @group.values : nil
3536
@parameter_type.transform(self_obj, group_values)
3637
end

ruby/lib/cucumber/cucumber_expressions/ast.rb

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,21 @@ module CucumberExpressions
1010
END_OPTIONAL_CHARACTER = ')'
1111

1212
class Node
13-
def initialize(type, nodes, token, start, _end)
13+
attr_reader :type, :nodes, :token, :start, :end
14+
15+
def initialize(type, nodes, token, start, ending)
1416
raise 'Either nodes or token must be defined' if nodes.nil? && token.nil?
17+
1518
@type = type
1619
@nodes = nodes
1720
@token = token
1821
@start = start
19-
@end = _end
20-
end
21-
22-
def type
23-
@type
24-
end
25-
26-
def nodes
27-
@nodes
28-
end
29-
30-
def token
31-
@token
32-
end
33-
34-
def start
35-
@start
36-
end
37-
38-
def end
39-
@end
22+
@end = ending
4023
end
4124

4225
def text
4326
return @nodes.map { |value| value.text }.join('') if @token.nil?
27+
4428
@token
4529
end
4630

@@ -64,26 +48,11 @@ module NodeType
6448
EXPRESSION = 'EXPRESSION_NODE'
6549
end
6650

67-
6851
class Token
69-
def initialize(type, text, start, _end)
70-
@type, @text, @start, @end = type, text, start, _end
71-
end
72-
73-
def type
74-
@type
75-
end
76-
77-
def text
78-
@text
79-
end
80-
81-
def start
82-
@start
83-
end
52+
attr_reader :type, :text, :start, :end
8453

85-
def end
86-
@end
54+
def initialize(type, text, start, ending)
55+
@type, @text, @start, @end = type, text, start, ending
8756
end
8857

8958
def self.is_escape_character(codepoint)
@@ -96,6 +65,7 @@ def self.can_escape(codepoint)
9665
# TODO: Unicode whitespace?
9766
return true
9867
end
68+
9969
case c
10070
when ESCAPE_CHARACTER
10171
true
@@ -120,6 +90,7 @@ def self.type_of(codepoint)
12090
# TODO: Unicode whitespace?
12191
return TokenType::WHITE_SPACE
12292
end
93+
12394
case c
12495
when ALTERNATION_CHARACTER
12596
TokenType::ALTERNATION

ruby/lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def generate_permutations(generated_expressions, depth, current_parameter_types)
3131
(0...@parameter_type_combinations[depth].length).each do |i|
3232
# Avoid recursion if no elements can be added.
3333
return if generated_expressions.length >= MAX_EXPRESSIONS
34+
3435
new_current_parameter_types = current_parameter_types.dup # clone
3536
new_current_parameter_types.push(@parameter_type_combinations[depth][i])
3637
generate_permutations(generated_expressions, depth + 1, new_current_parameter_types)

0 commit comments

Comments
 (0)