Skip to content

Commit e14569f

Browse files
author
Miguel Montalvo
committed
[Ruby] - Upgraded Rubocop gems.
1 parent 74fbf20 commit e14569f

File tree

11 files changed

+45
-42
lines changed

11 files changed

+45
-42
lines changed

ruby/.rubocop.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require:
1+
plugins:
22
- rubocop-performance
33
- rubocop-rake
44
- rubocop-rspec
@@ -10,7 +10,7 @@ inherit_mode:
1010
- Exclude
1111

1212
AllCops:
13-
TargetRubyVersion: 2.5
13+
TargetRubyVersion: 2.7
1414
NewCops: enable
1515

1616
# Disabled on our repo's to enable polyglot-release
@@ -29,6 +29,9 @@ Lint/MixedRegexpCaptureTypes:
2929
Style/Documentation:
3030
Enabled: false
3131

32+
Gemspec/DevelopmentDependencies:
33+
Enabled: false
34+
3235
Style/RegexpLiteral:
3336
EnforcedStyle: slashes
3437
AllowInnerSlashes: true

ruby/cucumber-cucumber-expressions.gemspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ Gem::Specification.new do |s|
2323
'source_code_uri' => 'https://github.com/cucumber/cucumber-expressions/tree/main/ruby',
2424
}
2525

26-
s.add_runtime_dependency 'bigdecimal'
26+
s.add_dependency 'bigdecimal'
2727

2828
s.add_development_dependency 'rake', '~> 13.1'
2929
s.add_development_dependency 'rspec', '~> 3.13'
30-
s.add_development_dependency 'rubocop', '~> 1.27.0'
31-
s.add_development_dependency 'rubocop-performance', '~> 1.7.0'
32-
s.add_development_dependency 'rubocop-rake', '~> 0.5.0'
33-
s.add_development_dependency 'rubocop-rspec', '~> 2.0.0'
30+
s.add_development_dependency 'rubocop', '~> 1.75.7'
31+
s.add_development_dependency 'rubocop-performance', '~> 1.25.0'
32+
s.add_development_dependency 'rubocop-rake', '~> 0.7.1'
33+
s.add_development_dependency 'rubocop-rspec', '~> 3.6.0'
3434

3535
s.files = Dir['lib/**/*', 'CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE', 'README.md']
3636
s.rdoc_options = ['--charset=UTF-8']

ruby/lib/cucumber/cucumber_expressions/argument.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(group, parameter_type)
3333
def value(self_obj = :nil)
3434
raise 'No self_obj' if self_obj == :nil
3535

36-
group_values = @group ? @group.values : nil
36+
group_values = @group&.values
3737
@parameter_type.transform(self_obj, group_values)
3838
end
3939
end

ruby/lib/cucumber/cucumber_expressions/cucumber_expression.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ def rewrite_expression(node)
103103
end
104104

105105
def assert_not_empty(node, &raise_error)
106-
text_nodes = node.nodes.select { |ast_node| NodeType::TEXT == ast_node.type }
106+
text_nodes = node.nodes.select { |ast_node| ast_node.type == NodeType::TEXT }
107107
raise_error.call(node) if text_nodes.length == 0
108108
end
109109

110110
def assert_no_parameters(node, &raise_error)
111-
nodes = node.nodes.select { |ast_node| NodeType::PARAMETER == ast_node.type }
111+
nodes = node.nodes.select { |ast_node| ast_node.type == NodeType::PARAMETER }
112112
raise_error.call(nodes[0]) if nodes.length > 0
113113
end
114114

115115
def assert_no_optionals(node, &raise_error)
116-
nodes = node.nodes.select { |ast_node| NodeType::OPTIONAL == ast_node.type }
116+
nodes = node.nodes.select { |ast_node| ast_node.type == NodeType::OPTIONAL }
117117
raise_error.call(nodes[0]) if nodes.length > 0
118118
end
119119
end

ruby/lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def create_parameter_type_matchers2(parameter_type, text)
8383
end
8484

8585
def escape(s)
86-
s.gsub(/%/, '%%')
87-
.gsub(/\(/, '\\(')
86+
s.gsub('%', '%%')
87+
.gsub('(', '\\(')
8888
.gsub(/{/, '\\{')
89-
.gsub(/\//, '\\/')
89+
.gsub('/', '\\/')
9090
end
9191
end
9292
end

ruby/lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ def parse(expression)
2222
return [0, nil]
2323
end
2424
# If configured correctly this will never happen
25-
return [0, nil]
25+
[0, nil]
2626
end
2727

2828
# name := whitespace | .
2929
parse_name = lambda do |_, tokens, current|
3030
token = tokens[current]
3131
case token.type
3232
when TokenType::WHITE_SPACE, TokenType::TEXT
33-
return [1, [Node.new(NodeType::TEXT, nil, token.text, token.start, token.end)]]
33+
[1, [Node.new(NodeType::TEXT, nil, token.text, token.start, token.end)]]
3434
when TokenType::BEGIN_PARAMETER, TokenType::END_PARAMETER, TokenType::BEGIN_OPTIONAL, TokenType::END_OPTIONAL, TokenType::ALTERNATION
3535
raise InvalidParameterTypeNameInNode.new(expression, token)
3636
when TokenType::START_OF_LINE, TokenType::END_OF_LINE
3737
# If configured correctly this will never happen
38-
return [0, nil]
38+
[0, nil]
3939
else
4040
# If configured correctly this will never happen
41-
return [0, nil]
41+
[0, nil]
4242
end
4343
end
4444

@@ -56,7 +56,7 @@ def parse(expression)
5656
return [0, nil] unless looking_at(tokens, current, TokenType::ALTERNATION)
5757

5858
token = tokens[current]
59-
return [1, [Node.new(NodeType::ALTERNATIVE, nil, token.text, token.start, token.end)]]
59+
[1, [Node.new(NodeType::ALTERNATIVE, nil, token.text, token.start, token.end)]]
6060
end
6161

6262
alternative_parsers = [
@@ -81,7 +81,7 @@ def parse(expression)
8181
start = tokens[current].start
8282
_end = tokens[sub_current].start
8383
# Does not consume right hand boundary token
84-
return [consumed, [Node.new(NodeType::ALTERNATION, split_alternatives(start, _end, ast), nil, start, _end)]]
84+
[consumed, [Node.new(NodeType::ALTERNATION, split_alternatives(start, _end, ast), nil, start, _end)]]
8585
end
8686

8787
#
@@ -118,7 +118,7 @@ def parse_between(type, begin_token, end_token, parsers)
118118
_end = tokens[sub_current].end
119119
consumed = sub_current + 1 - current
120120
ast = [Node.new(type, ast, nil, start, _end)]
121-
return [consumed, ast]
121+
[consumed, ast]
122122
end
123123
end
124124

@@ -171,7 +171,7 @@ def split_alternatives(start, _end, alternation)
171171
alternatives = []
172172
alternative = []
173173
alternation.each do |n|
174-
if NodeType::ALTERNATIVE == n.type
174+
if n.type == NodeType::ALTERNATIVE
175175
separators.push(n)
176176
alternatives.push(alternative)
177177
alternative = []

ruby/lib/cucumber/cucumber_expressions/tree_regexp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def match(s)
3838
return true
3939
end
4040

41-
if source[i + 3] == '=' || source[i + 3] == '!'
41+
if ['=', '!'].include?(source[i + 3])
4242
# (?<=X)
4343
# (?<!X)
4444
return true

ruby/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module CucumberExpressions
2020
else
2121
cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
2222
matches = cucumber_expression.match(expectation['text'])
23-
values = matches.nil? ? nil : matches.map do |arg|
23+
values = matches&.map do |arg|
2424
value = arg.value(nil)
2525
case value
2626
when BigDecimal
@@ -51,32 +51,32 @@ module CucumberExpressions
5151
end
5252

5353
it 'matches float' do
54-
expect(match('{float}', '')).to eq(nil)
55-
expect(match('{float}', '.')).to eq(nil)
56-
expect(match('{float}', ',')).to eq(nil)
57-
expect(match('{float}', '-')).to eq(nil)
58-
expect(match('{float}', 'E')).to eq(nil)
59-
expect(match('{float}', '1,')).to eq(nil)
60-
expect(match('{float}', ',1')).to eq(nil)
61-
expect(match('{float}', '1.')).to eq(nil)
54+
expect(match('{float}', '')).to be_nil
55+
expect(match('{float}', '.')).to be_nil
56+
expect(match('{float}', ',')).to be_nil
57+
expect(match('{float}', '-')).to be_nil
58+
expect(match('{float}', 'E')).to be_nil
59+
expect(match('{float}', '1,')).to be_nil
60+
expect(match('{float}', ',1')).to be_nil
61+
expect(match('{float}', '1.')).to be_nil
6262

6363
expect(match('{float}', '1')).to eq([1])
6464
expect(match('{float}', '-1')).to eq([-1])
6565
expect(match('{float}', '1.1')).to eq([1.1])
66-
expect(match('{float}', '1,000')).to eq(nil)
67-
expect(match('{float}', '1,000,0')).to eq(nil)
68-
expect(match('{float}', '1,000.1')).to eq(nil)
69-
expect(match('{float}', '1,000,10')).to eq(nil)
70-
expect(match('{float}', '1,0.1')).to eq(nil)
71-
expect(match('{float}', '1,000,000.1')).to eq(nil)
66+
expect(match('{float}', '1,000')).to be_nil
67+
expect(match('{float}', '1,000,0')).to be_nil
68+
expect(match('{float}', '1,000.1')).to be_nil
69+
expect(match('{float}', '1,000,10')).to be_nil
70+
expect(match('{float}', '1,0.1')).to be_nil
71+
expect(match('{float}', '1,000,000.1')).to be_nil
7272
expect(match('{float}', '-1.1')).to eq([-1.1])
7373

7474
expect(match('{float}', '.1')).to eq([0.1])
7575
expect(match('{float}', '-.1')).to eq([-0.1])
7676
expect(match('{float}', '-.1000001')).to eq([-0.1000001])
7777
expect(match('{float}', '1E1')).to eq([10.0])
7878
expect(match('{float}', '.1E1')).to eq([1])
79-
expect(match('{float}', 'E1')).to eq(nil)
79+
expect(match('{float}', 'E1')).to be_nil
8080
expect(match('{float}', '-.1E-1')).to eq([-0.01])
8181
expect(match('{float}', '-.1E-2')).to eq([-0.001])
8282
expect(match('{float}', '-.1E+1')).to eq([-1])

ruby/spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module CucumberExpressions
1919
else
2020
cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
2121
matches = cucumber_expression.match(expectation['text'])
22-
values = matches.nil? ? nil : matches.map { |arg| arg.value(nil) }
22+
values = matches&.map { |arg| arg.value(nil) }
2323
expect(values).to eq(expectation['expected_args'])
2424
end
2525
end

ruby/spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def ==(other)
155155
}.to raise_error('There is already a parameter with name color')
156156
end
157157

158-
it 'is not detected for type' do
158+
it 'is not detected for type', skip: 'missing expectation' do
159159
@parameter_type_registry.define_parameter_type(
160160
ParameterType.new(
161161
'whatever',

0 commit comments

Comments
 (0)