Skip to content

[Ruby] - Upgraded Rubocop gems. #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- [Ruby] Updated rubocop and rubocop gems (RSpec/Rake/Performance), also updated project files affected by the updated rules ([#342](https://github.com/cucumber/cucumber-expressions/pull/342))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary. Notable in this context means "notable to the user" and "notable for the purposes of semver".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, ideally here you'd maybe write a quick changelog that you autofixed some styles or something. As some of the changes could break, but this would go into a patch release if it was released

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but not completely sure if I should keep the changelog entry or remove it 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what Rien is saying is technical things about ruby don't belong in a polyglot changelog (This is a library with 6 flavours).

So maybe just say somethinig similar to what has been written prior


## [18.0.1] - 2024-10-28
### Fixed
Expand Down
7 changes: 5 additions & 2 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require:
plugins:
- rubocop-performance
- rubocop-rake
- rubocop-rspec
Expand All @@ -10,7 +10,7 @@ inherit_mode:
- Exclude

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
NewCops: enable

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

Gemspec/DevelopmentDependencies:
Enabled: false

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true
Expand Down
10 changes: 5 additions & 5 deletions ruby/cucumber-cucumber-expressions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ Gem::Specification.new do |s|
'source_code_uri' => 'https://github.com/cucumber/cucumber-expressions/tree/main/ruby',
}

s.add_runtime_dependency 'bigdecimal'
s.add_dependency 'bigdecimal'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luke-hill this looks breaking. Is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah this is just minor naming. Although I wasn't aware this was a new recommendation 🤷‍♂️


s.add_development_dependency 'rake', '~> 13.1'
s.add_development_dependency 'rspec', '~> 3.13'
s.add_development_dependency 'rubocop', '~> 1.27.0'
s.add_development_dependency 'rubocop-performance', '~> 1.7.0'
s.add_development_dependency 'rubocop-rake', '~> 0.5.0'
s.add_development_dependency 'rubocop-rspec', '~> 2.0.0'
s.add_development_dependency 'rubocop', '~> 1.75.7'
s.add_development_dependency 'rubocop-performance', '~> 1.25.0'
s.add_development_dependency 'rubocop-rake', '~> 0.7.1'
s.add_development_dependency 'rubocop-rspec', '~> 3.6.0'

s.files = Dir['lib/**/*', 'CHANGELOG.md', 'CONTRIBUTING.md', 'LICENSE', 'README.md']
s.rdoc_options = ['--charset=UTF-8']
Expand Down
3 changes: 1 addition & 2 deletions ruby/lib/cucumber/cucumber_expressions/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def initialize(group, parameter_type)
def value(self_obj = :nil)
raise 'No self_obj' if self_obj == :nil

group_values = @group ? @group.values : nil
@parameter_type.transform(self_obj, group_values)
@parameter_type.transform(self_obj, @group&.values)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions ruby/lib/cucumber/cucumber_expressions/cucumber_expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ def rewrite_expression(node)
end

def assert_not_empty(node, &raise_error)
text_nodes = node.nodes.select { |ast_node| NodeType::TEXT == ast_node.type }
text_nodes = node.nodes.select { |ast_node| ast_node.type == NodeType::TEXT }
raise_error.call(node) if text_nodes.length == 0
end

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

def assert_no_optionals(node, &raise_error)
nodes = node.nodes.select { |ast_node| NodeType::OPTIONAL == ast_node.type }
nodes = node.nodes.select { |ast_node| ast_node.type == NodeType::OPTIONAL }
raise_error.call(nodes[0]) if nodes.length > 0
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def create_parameter_type_matchers2(parameter_type, text)
end

def escape(s)
s.gsub(/%/, '%%')
.gsub(/\(/, '\\(')
s.gsub('%', '%%')
.gsub('(', '\\(')
.gsub(/{/, '\\{')
.gsub(/\//, '\\/')
.gsub('/', '\\/')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ def parse(expression)
return [0, nil]
end
# If configured correctly this will never happen
return [0, nil]
[0, nil]
end

# name := whitespace | .
parse_name = lambda do |_, tokens, current|
token = tokens[current]
case token.type
when TokenType::WHITE_SPACE, TokenType::TEXT
return [1, [Node.new(NodeType::TEXT, nil, token.text, token.start, token.end)]]
[1, [Node.new(NodeType::TEXT, nil, token.text, token.start, token.end)]]
when TokenType::BEGIN_PARAMETER, TokenType::END_PARAMETER, TokenType::BEGIN_OPTIONAL, TokenType::END_OPTIONAL, TokenType::ALTERNATION
raise InvalidParameterTypeNameInNode.new(expression, token)
when TokenType::START_OF_LINE, TokenType::END_OF_LINE
# If configured correctly this will never happen
return [0, nil]
[0, nil]
else
# If configured correctly this will never happen
return [0, nil]
[0, nil]
end
end

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

token = tokens[current]
return [1, [Node.new(NodeType::ALTERNATIVE, nil, token.text, token.start, token.end)]]
[1, [Node.new(NodeType::ALTERNATIVE, nil, token.text, token.start, token.end)]]
end

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

#
Expand Down Expand Up @@ -118,7 +118,7 @@ def parse_between(type, begin_token, end_token, parsers)
_end = tokens[sub_current].end
consumed = sub_current + 1 - current
ast = [Node.new(type, ast, nil, start, _end)]
return [consumed, ast]
[consumed, ast]
end
end

Expand Down Expand Up @@ -171,7 +171,7 @@ def split_alternatives(start, _end, alternation)
alternatives = []
alternative = []
alternation.each do |n|
if NodeType::ALTERNATIVE == n.type
if n.type == NodeType::ALTERNATIVE
separators.push(n)
alternatives.push(alternative)
alternative = []
Expand Down
2 changes: 1 addition & 1 deletion ruby/lib/cucumber/cucumber_expressions/tree_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def match(s)
return true
end

if source[i + 3] == '=' || source[i + 3] == '!'
if ['=', '!'].include?(source[i + 3])
# (?<=X)
# (?<!X)
return true
Expand Down
32 changes: 16 additions & 16 deletions ruby/spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module CucumberExpressions
else
cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
matches = cucumber_expression.match(expectation['text'])
values = matches.nil? ? nil : matches.map do |arg|
values = matches&.map do |arg|
value = arg.value(nil)
case value
when BigDecimal
Expand Down Expand Up @@ -51,32 +51,32 @@ module CucumberExpressions
end

it 'matches float' do
expect(match('{float}', '')).to eq(nil)
expect(match('{float}', '.')).to eq(nil)
expect(match('{float}', ',')).to eq(nil)
expect(match('{float}', '-')).to eq(nil)
expect(match('{float}', 'E')).to eq(nil)
expect(match('{float}', '1,')).to eq(nil)
expect(match('{float}', ',1')).to eq(nil)
expect(match('{float}', '1.')).to eq(nil)
expect(match('{float}', '')).to be_nil
expect(match('{float}', '.')).to be_nil
expect(match('{float}', ',')).to be_nil
expect(match('{float}', '-')).to be_nil
expect(match('{float}', 'E')).to be_nil
expect(match('{float}', '1,')).to be_nil
expect(match('{float}', ',1')).to be_nil
expect(match('{float}', '1.')).to be_nil

expect(match('{float}', '1')).to eq([1])
expect(match('{float}', '-1')).to eq([-1])
expect(match('{float}', '1.1')).to eq([1.1])
expect(match('{float}', '1,000')).to eq(nil)
expect(match('{float}', '1,000,0')).to eq(nil)
expect(match('{float}', '1,000.1')).to eq(nil)
expect(match('{float}', '1,000,10')).to eq(nil)
expect(match('{float}', '1,0.1')).to eq(nil)
expect(match('{float}', '1,000,000.1')).to eq(nil)
expect(match('{float}', '1,000')).to be_nil
expect(match('{float}', '1,000,0')).to be_nil
expect(match('{float}', '1,000.1')).to be_nil
expect(match('{float}', '1,000,10')).to be_nil
expect(match('{float}', '1,0.1')).to be_nil
expect(match('{float}', '1,000,000.1')).to be_nil
expect(match('{float}', '-1.1')).to eq([-1.1])

expect(match('{float}', '.1')).to eq([0.1])
expect(match('{float}', '-.1')).to eq([-0.1])
expect(match('{float}', '-.1000001')).to eq([-0.1000001])
expect(match('{float}', '1E1')).to eq([10.0])
expect(match('{float}', '.1E1')).to eq([1])
expect(match('{float}', 'E1')).to eq(nil)
expect(match('{float}', 'E1')).to be_nil
expect(match('{float}', '-.1E-1')).to eq([-0.01])
expect(match('{float}', '-.1E-2')).to eq([-0.001])
expect(match('{float}', '-.1E+1')).to eq([-1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module CucumberExpressions
else
cucumber_expression = described_class.new(expectation['expression'], parameter_registry)
matches = cucumber_expression.match(expectation['text'])
values = matches.nil? ? nil : matches.map { |arg| arg.value(nil) }
values = matches&.map { |arg| arg.value(nil) }
expect(values).to eq(expectation['expected_args'])
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def ==(other)
}.to raise_error('There is already a parameter with name color')
end

it 'is not detected for type' do
it 'is not detected for type', skip: 'missing expectation' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just flagging this for me here, this should be checked across languages. It "could" be similar issue

@parameter_type_registry.define_parameter_type(
ParameterType.new(
'whatever',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module CucumberExpressions
tr = described_class.new(/the stdout(?: from "(.*?)")?/)
group = tr.match('the stdout')
expect(group.value).to eq('the stdout')
expect(group.children[0].value).to eq(nil)
expect(group.children[0].value).to be_nil
expect(group.children.length).to eq(1)
end

Expand Down