Skip to content

Commit

Permalink
Ruby: Additional rubocop config (#247)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
luke-hill authored Nov 28, 2023
1 parent 4740e47 commit 7674288
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 282 deletions.
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] Added subsidiary rubocop gems (RSpec/Rake/Performance), and did some initial refactoring ([#247](https://github.com/cucumber/cucumber-expressions/pull/247))

## [17.0.1] - 2023-11-24
### Fixed
Expand Down
16 changes: 13 additions & 3 deletions ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
require:
- rubocop-performance
- rubocop-rake
- rubocop-rspec

inherit_from: .rubocop_todo.yml

inherit_mode:
Expand All @@ -15,13 +20,18 @@ Gemspec/RequireMFA:
Layout/LineLength:
Max: 200

# This is documented in this spec to showcase why it's not working and people shouldn't use it
# cf:
Lint/MixedRegexpCaptureTypes:
Exclude:
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

Style/Documentation:
Enabled: false

Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true

# Once we enable rubocop-rspec
#RSpec/MessageSpies:
# EnforcedStyle: receive
RSpec/MessageSpies:
EnforcedStyle: receive
201 changes: 60 additions & 141 deletions ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-06 11:04:10 UTC using RuboCop version 1.27.0.
# on 2023-11-27 17:52:56 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).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: outdent, indent
Layout/AccessModifierIndentation:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'
# TODO: Nov '23 -> 33 files inspected, 399 offenses detected, 192 offenses auto-correctable

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

# 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'

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
# SupportedHashRocketStyles: key, separator, table
# SupportedColonStyles: key, separator, table
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Layout/HashAlignment:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'

# Offense count: 2
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 252

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
Exclude:
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'

# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression_generator.rb'

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

# Offense count: 57
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'cucumber-cucumber-expressions.gemspec'
- 'lib/cucumber/cucumber_expressions/group_builder.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'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'
EnforcedStyle: consistent

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

# Offense count: 10
# Offense count: 5
# Configuration parameters: AllowComments.
Lint/EmptyClass:
Exclude:
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'

# Offense count: 1
Lint/MixedRegexpCaptureTypes:
Exclude:
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 1
# This cop supports unsafe auto-correction (--auto-correct-all).
Lint/NonDeterministicRequireOrder:
Exclude:
- 'Rakefile'

# Offense count: 1
Lint/NonLocalExitFromIterator:
Exclude:
- 'lib/cucumber/cucumber_expressions/combinatorial_generated_expression_factory.rb'

# Offense count: 7
# Offense count: 5
# Configuration parameters: AllowKeywordBlockArguments.
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'lib/cucumber/cucumber_expressions/ast.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/group.rb'

# Offense count: 14
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'

# Offense count: 10
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Expand Down Expand Up @@ -201,21 +105,6 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Max: 17

# Offense count: 10
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
Naming/BlockParameterName:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'

# Offense count: 2
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'lib/cucumber/cucumber_expressions/errors.rb'

# Offense count: 7
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
Expand All @@ -238,14 +127,59 @@ Naming/PredicateName:
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'

# Offense count: 20
# Configuration parameters: EnforcedStyle, AllowedIdentifiers.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
Performance/RedundantBlockCall:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/parameter_type_matcher.rb'

# Offense count: 2
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'

# Offense count: 29
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_parser_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_transformation_spec.rb'
- 'spec/cucumber/cucumber_expressions/custom_parameter_type_spec.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_registry_spec.rb'
- 'spec/cucumber/cucumber_expressions/parameter_type_spec.rb'
- 'spec/cucumber/cucumber_expressions/regular_expression_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 3
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/cucumber/cucumber_expressions/cucumber_expression_generator_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_spec.rb'

# Offense count: 34
RSpec/MultipleExpectations:
Max: 30

# Offense count: 1
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 6

# Offense count: 2
RSpec/RepeatedDescription:
Exclude:
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 2
RSpec/RepeatedExample:
Exclude:
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
Expand All @@ -254,7 +188,7 @@ Style/AccessModifierDeclarations:
Exclude:
- 'lib/cucumber/cucumber_expressions/tree_regexp.rb'

# Offense count: 5
# Offense count: 4
# 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 @@ -267,7 +201,6 @@ Style/BlockDelimiters:
- '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'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

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

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/PerlBackrefs:
Exclude:
- 'lib/cucumber/cucumber_expressions/parameter_type.rb'

# Offense count: 1
# This cop supports unsafe auto-correction (--auto-correct-all).
# Configuration parameters: EnforcedStyle.
Expand Down Expand Up @@ -473,7 +400,7 @@ Style/SymbolProc:
- 'lib/cucumber/cucumber_expressions/ast.rb'
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'lib/cucumber/cucumber_expressions/errors.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'
- 'spec/cucumber/cucumber_expressions/cucumber_expression_tokenizer_spec.rb'
- 'spec/cucumber/cucumber_expressions/tree_regexp_spec.rb'

Expand All @@ -484,7 +411,7 @@ Style/SymbolProc:
Style/TrailingCommaInArrayLiteral:
Exclude:
- 'lib/cucumber/cucumber_expressions/cucumber_expression_parser.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_test.rb'
- 'spec/cucumber/cucumber_expressions/combinatorial_generated_expression_factory_spec.rb'

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

# Offense count: 9
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, AllowedMethods.
# 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
Style/TrivialAccessors:
Exclude:
- 'lib/cucumber/cucumber_expressions/ast.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/WhileUntilDo:
Expand Down
9 changes: 6 additions & 3 deletions ruby/cucumber-cucumber-expressions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ Gem::Specification.new do |s|

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

s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
s.add_development_dependency 'rspec', '~> 3.11', '>= 3.11.0'
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.files = `git ls-files`.split("\n").reject { |path| path =~ /\.gitignore$/ }
s.rdoc_options = ['--charset=UTF-8']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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
break 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])
Expand Down
Loading

0 comments on commit 7674288

Please sign in to comment.