Skip to content

Ruby: Layout rubocop fixes #235

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

Merged
merged 16 commits into from
Oct 6, 2023
Merged
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
146 changes: 9 additions & 137 deletions ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-03 17:06:00 UTC using RuboCop version 1.27.0.
# on 2023-10-06 11:04:10 UTC using RuboCop version 1.27.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# TODO: Oct '23 -> 33 files inspected, 1004 offenses detected, 859 offenses auto-correctable
# TODO: Oct '23 (later) -> 33 files inspected, 344 offenses detected, 205 offenses auto-correctable

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

# Offense count: 23
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterGuardClause:
Exclude:
- 'lib/cucumber/cucumber_expressions/argument.rb'
- 'lib/cucumber/cucumber_expressions/ast.rb'
- 'lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLineAfterMagicComment:
Exclude:
- 'Gemfile'
- 'Rakefile'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'lib/cucumber/cucumber_expressions/ast.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLines:
Exclude:
- 'lib/cucumber/cucumber_expressions/ast.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
- 'lib/cucumber/cucumber_expressions/errors.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
- 'lib/cucumber/cucumber_expressions/regular_expression.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Layout/FirstArrayElementIndentation:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'

# Offense count: 3
# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Layout/FirstHashElementIndentation:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'
- 'lib/cucumber/cucumber_expressions/ast.rb'

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

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
Layout/HeredocIndentation:
Exclude:
- 'lib/cucumber/cucumber_expressions/errors.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
Expand All @@ -146,43 +66,15 @@ Layout/MultilineMethodCallIndentation:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'lib/cucumber/cucumber_expressions/argument.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'

# Offense count: 5
# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
Exclude:
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: require_no_space, require_space
Layout/SpaceInLambdaLiteral:
Exclude:
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'

# Offense count: 58
# Offense count: 57
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
Expand All @@ -191,7 +83,6 @@ Layout/SpaceInsideBlockBraces:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'
- 'lib/cucumber/cucumber_expressions/group_builder.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_registry.rb'
- 'lib/cucumber/cucumber_expressions/regular_expression.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
Expand All @@ -202,22 +93,6 @@ Layout/SpaceInsideBlockBraces:
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 24
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Exclude:
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Lint/AmbiguousOperatorPrecedence:
Expand Down Expand Up @@ -299,7 +174,7 @@ Metrics/BlockNesting:
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 151
Max: 141

# Offense count: 7
# Configuration parameters: IgnoredMethods.
Expand All @@ -309,7 +184,7 @@ Metrics/CyclomaticComplexity:
# Offense count: 20
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
Metrics/MethodLength:
Max: 71
Max: 61

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne.
Expand Down Expand Up @@ -379,7 +254,7 @@ Style/AccessModifierDeclarations:
Exclude:
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'

# Offense count: 7
# Offense count: 5
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
Expand All @@ -389,8 +264,6 @@ Style/AccessModifierDeclarations:
Style/BlockDelimiters:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb'
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
Expand All @@ -414,11 +287,10 @@ Style/EmptyLiteral:
Exclude:
- 'lib/cucumber/cucumber_expressions/ast.rb'

# Offense count: 2
# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/Encoding:
Exclude:
- 'Rakefile'
- 'cucumber-cucumber-expressions.gemspec'

# Offense count: 1
Expand Down
1 change: 1 addition & 0 deletions ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gemspec
4 changes: 0 additions & 4 deletions ruby/Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# encoding: utf-8
# frozen_string_literal: true
require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks

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

Expand Down
2 changes: 1 addition & 1 deletion ruby/cucumber-cucumber-expressions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.license = 'MIT'
s.required_ruby_version = '>= 2.5'

s.metadata = {
s.metadata = {
'bug_tracker_uri' => 'https://github.com/cucumber/cucumber/issues',
'changelog_uri' => 'https://github.com/cucumber/common/blob/main/cucumber-expressions/CHANGELOG.md',
'documentation_uri' => 'https://cucumber.io/docs/cucumber/cucumber-expressions/',
Expand Down
3 changes: 2 additions & 1 deletion ruby/lib/cucumber/cucumber_expressions/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def initialize(group, parameter_type)
@group, @parameter_type = group, parameter_type
end

def value(self_obj=:nil)
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)
end
Expand Down
51 changes: 11 additions & 40 deletions ruby/lib/cucumber/cucumber_expressions/ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,21 @@ module CucumberExpressions
END_OPTIONAL_CHARACTER = ')'

class Node
def initialize(type, nodes, token, start, _end)
attr_reader :type, :nodes, :token, :start, :end

def initialize(type, nodes, token, start, ending)
raise 'Either nodes or token must be defined' if nodes.nil? && token.nil?

@type = type
@nodes = nodes
@token = token
@start = start
@end = _end
end

def type
@type
end

def nodes
@nodes
end

def token
@token
end

def start
@start
end

def end
@end
@end = ending
end

def text
return @nodes.map { |value| value.text }.join('') if @token.nil?

@token
end

Expand All @@ -64,26 +48,11 @@ module NodeType
EXPRESSION = 'EXPRESSION_NODE'
end


class Token
def initialize(type, text, start, _end)
@type, @text, @start, @end = type, text, start, _end
end

def type
@type
end

def text
@text
end

def start
@start
end
attr_reader :type, :text, :start, :end

def end
@end
def initialize(type, text, start, ending)
@type, @text, @start, @end = type, text, start, ending
end

def self.is_escape_character(codepoint)
Expand All @@ -96,6 +65,7 @@ def self.can_escape(codepoint)
# TODO: Unicode whitespace?
return true
end

case c
when ESCAPE_CHARACTER
true
Expand All @@ -120,6 +90,7 @@ def self.type_of(codepoint)
# TODO: Unicode whitespace?
return TokenType::WHITE_SPACE
end

case c
when ALTERNATION_CHARACTER
TokenType::ALTERNATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def generate_permutations(generated_expressions, depth, current_parameter_types)
(0...@parameter_type_combinations[depth].length).each do |i|
# Avoid recursion if no elements can be added.
return if generated_expressions.length >= MAX_EXPRESSIONS

new_current_parameter_types = current_parameter_types.dup # clone
new_current_parameter_types.push(@parameter_type_combinations[depth][i])
generate_permutations(generated_expressions, depth + 1, new_current_parameter_types)
Expand Down
Loading