Skip to content

Commit

Permalink
Refactor/Layout Autofixes (#1745)
Browse files Browse the repository at this point in the history
* AF: Layout/ClosingHeredocIndentation and alter heredocs to squigglies

* A partial AF of Layout/HashAlignment

* AF: Layout/HeredocIndentation from using Squigglies

* AF: Layout/IndentationConsistency

* AF: Layout/SpaceInsideHashLiteralBraces

* AF: Layout/EmptyLines

* AF: Layout/BlockAlignment

* Remove lots of in-line disabling in favour of a centralized todo file

* Regenerate todo file and tidy up previous iterations

* Add changelog

* Remove ABCSize override in regular rubocop file - now regenning should fix it
  • Loading branch information
luke-hill authored Dec 22, 2023
1 parent 0e094a6 commit f23e603
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 231 deletions.
10 changes: 0 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ Lint/UselessMethodDefinition:
Exclude:
- 'lib/cucumber/glue/proto_world.rb'

# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
# to the auto-gen-config
Metrics/AbcSize:
Max: 41
# TODO: Manually added! - be careful with regenning the file - this needs a fix
Exclude:
- lib/cucumber/formatter/junit.rb
- spec/cucumber/formatter/http_io_spec.rb
- lib/cucumber/glue/proto_world.rb

# TODO: [LH] - This definitely needs a partial fix / reduction. Even if only an interim one that pushes some stuff
Metrics/ClassLength:
Max: 375
Expand Down
125 changes: 47 additions & 78 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,33 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-10-03 13:56:41 UTC using RuboCop version 1.56.4.
# on 2023-12-08 14:57:03 UTC using RuboCop version 1.56.4.
# 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 - [LH] -> Aug '23 - 370 files inspected, 1110 offenses detected, 482 offenses autocorrectable
# TODO - [LH] -> Sep 6 '23 - 370 files inspected, 983 offenses detected, 368 offenses autocorrectable
# TODO - [LH] -> Sep 11 '23 - 370 files inspected, 825 offenses detected, 387 offenses autocorrectable
# TODO - [LH] -> Sep 19 '23 - 370 files inspected, 640 offenses detected, 202 offenses autocorrectable
# TODO - [LH] -> Oct '23 - 355 files inspected, 642 offenses detected, 205 offenses autocorrectable
# TODO - [LH] -> Dec '23 - 350 files inspected, 595 offenses detected, 171 offenses autocorrectable

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyleAlignWith.
# SupportedStylesAlignWith: either, start_of_block, start_of_line
Layout/BlockAlignment:
Exclude:
- 'spec/cucumber/formatter/fail_fast_spec.rb'

# Offense count: 17
# This cop supports safe autocorrection (--autocorrect).
Layout/ClosingHeredocIndentation:
Exclude:
- 'spec/cucumber/cli/profile_loader_spec.rb'
- 'spec/cucumber/formatter/json_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/EmptyLines:
Exclude:
- 'spec/cucumber/formatter/fail_fast_spec.rb'

# Offense count: 38
# Offense count: 10
# This cop supports safe autocorrection (--autocorrect).
# 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.gemspec'
- 'lib/cucumber/cli/options.rb'
- 'lib/cucumber/formatter/ansicolor.rb'
- 'lib/cucumber/gherkin/formatter/ansi_escapes.rb'

# Offense count: 4
# Offense count: 19
# This cop supports safe autocorrection (--autocorrect).
Layout/HeredocIndentation:
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'lib/cucumber/cli/options.rb'
- 'lib/cucumber/cli/profile_loader.rb'
- 'spec/cucumber/cli/profile_loader_spec.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: normal, indented_internal_methods
Layout/IndentationConsistency:
Exclude:
- 'spec/cucumber/formatter/fail_fast_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Width, AllowedPatterns.
Layout/IndentationWidth:
Exclude:
- 'spec/cucumber/formatter/fail_fast_spec.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Exclude:
- 'spec/cucumber/cli/options_spec.rb'
- 'lib/cucumber/multiline_argument/data_table.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -86,17 +37,25 @@ Lint/AmbiguousOperator:
- 'lib/cucumber/running_test_case.rb'
- 'spec/cucumber/formatter/spec_helper.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Lint/RedundantCopDisableDirective:
Exclude:
- 'lib/cucumber/cli/options.rb'

# Offense count: 1
# Offense count: 4
Lint/RescueException:
Exclude:
- 'lib/cucumber/cli/main.rb'
- 'lib/cucumber/configuration.rb'
- 'lib/cucumber/glue/invoke_in_world.rb'
- 'lib/cucumber/glue/proto_world.rb'

# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 127

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 52

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Expand All @@ -115,6 +74,15 @@ Naming/FileName:
Exclude:
- 'features/lib/step_definitions/iso-8859-1_steps.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/cucumber/formatter/json.rb'
- 'lib/cucumber/multiline_argument/data_table.rb'

# Offense count: 14
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Expand Down Expand Up @@ -214,7 +182,7 @@ RSpec/ExpectActual:
- 'spec/cucumber/cli/configuration_spec.rb'
- 'spec/cucumber/step_match_spec.rb'

# Offense count: 2
# Offense count: 4
RSpec/ExpectInHook:
Exclude:
- 'spec/cucumber/multiline_argument/data_table_spec.rb'
Expand Down Expand Up @@ -261,7 +229,7 @@ RSpec/MultipleExpectations:
# Offense count: 38
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 15
Max: 10

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand All @@ -283,22 +251,11 @@ RSpec/NamedSubject:
- 'spec/cucumber/runtime/support_code_spec.rb'
- 'spec/cucumber/runtime_spec.rb'

# Offense count: 6
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 6

# Offense count: 1
RSpec/OverwritingSetup:
Exclude:
- 'spec/cucumber/runtime/support_code_spec.rb'

# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
RSpec/ReceiveCounts:
Exclude:
- 'spec/cucumber/filters/retry_spec.rb'

# Offense count: 8
RSpec/RepeatedExample:
Exclude:
Expand Down Expand Up @@ -334,7 +291,7 @@ RSpec/ScatteredLet:
Exclude:
- 'spec/cucumber/runtime/support_code_spec.rb'

# Offense count: 5
# Offense count: 7
RSpec/StubbedMock:
Exclude:
- 'spec/cucumber/cli/configuration_spec.rb'
Expand All @@ -360,6 +317,17 @@ RSpec/VerifiedDoubles:
- 'spec/cucumber/runtime/support_code_spec.rb'
- 'spec/cucumber/world/pending_spec.rb'

# Offense count: 1
Security/Open:
Exclude:
- 'lib/autotest/cucumber_mixin.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Security/YAMLLoad:
Exclude:
- 'lib/cucumber/cli/profile_loader.rb'

# Offense count: 7
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
Expand All @@ -379,10 +347,11 @@ Style/ClassVars:
Exclude:
- 'spec/cucumber/glue/step_definition_spec.rb'

# Offense count: 4
# Offense count: 7
# Configuration parameters: AllowedVariables.
Style/GlobalVars:
Exclude:
- 'features/lib/support/env.rb'
- 'spec/cucumber/cli/options_spec.rb'

# Offense count: 6
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo

### Changed
- Updated dependencies to slightly more permissive / up to date versions ([luke-hill](https://github.com/luke-hill))
- Fixed most of the `Layout` cop offenses ([luke-hill](https://github.com/luke-hill))

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY

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

s.required_ruby_version = '>= 2.7'
Expand Down
2 changes: 1 addition & 1 deletion features/docs/events/step_activated_event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Step Activated Event
Given a file named "features/step_definitions/steps.rb" with:
"""
Given /a step/ do
# automation goes here
# automation goes here
end
"""
And a file named "features/test.feature" with:
Expand Down
2 changes: 0 additions & 2 deletions features/lib/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
# (the ones ran by Cucumber itself).
# This should reset data hopefully (and make clear why we do that)

# rubocop:disable Style/GlobalVars
$global_state = nil
$global_cukes = 0
$scenario_runs = 0
# rubocop:enable Style/GlobalVars
end

After('@disable_fail_fast') do
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def execute!(existing_runtime = nil)
rescue Errno::EACCES, Errno::ENOENT => e
@err.puts("#{e.message} (#{e.class})")
exit_unable_to_finish
rescue Exception => e # rubocop:disable Lint/RescueException
rescue Exception => e
@err.puts("#{e.message} (#{e.class})")
@err.puts(e.backtrace.join("\n"))
exit_unable_to_finish
Expand Down
16 changes: 8 additions & 8 deletions lib/cucumber/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ def []=(key, value)
@options[key] = value
end

def parse!(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def parse!(args)
@args = args
@expanded_args = @args.dup

@args.extend(::OptionParser::Arguable)

@args.options do |opts| # rubocop:disable Metrics/BlockLength
@args.options do |opts|
opts.banner = banner
opts.on('--publish', 'Publish a report to https://reports.cucumber.io') do
set_option :publish_enabled, true
Expand Down Expand Up @@ -143,11 +143,11 @@ def parse!(args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
opts.on('-x', '--expand', 'Expand Scenario Outline Tables in output.') { set_option :expand }

opts.on('--order TYPE[:SEED]', 'Run examples in the specified order. Available types:',
*<<-TEXT.split("\n")) do |order|
[defined] Run scenarios in the order they were defined (default).
[random] Shuffle scenarios before running.
Specify SEED to reproduce the shuffling from a previous run.
e.g. --order random:5738
*<<~TEXT.split("\n")) do |order|
[defined] Run scenarios in the order they were defined (default).
[random] Shuffle scenarios before running.
Specify SEED to reproduce the shuffling from a previous run.
e.g. --order random:5738
TEXT
@options[:order], @options[:seed] = *order.split(':')
raise "'#{@options[:order]}' is not a recognised order type. Please use one of #{ORDER_TYPES.join(', ')}." unless ORDER_TYPES.include?(@options[:order])
Expand Down Expand Up @@ -522,7 +522,7 @@ def profile_loader
@profile_loader ||= ProfileLoader.new
end

def reverse_merge(other_options) # rubocop:disable Metrics/AbcSize
def reverse_merge(other_options)
@options = other_options.options.merge(@options)
@options[:require] += other_options[:require]
@options[:excludes] += other_options[:excludes]
Expand Down
10 changes: 5 additions & 5 deletions lib/cucumber/cli/profile_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def initialize

def args_from(profile)
unless cucumber_yml.key?(profile)
raise(ProfileNotFound, <<-END_OF_ERROR)
Could not find profile: '#{profile}'
raise(ProfileNotFound, <<~END_OF_ERROR)
Could not find profile: '#{profile}'
Defined profiles in cucumber.yml:
* #{cucumber_yml.keys.sort.join("\n * ")}
Defined profiles in cucumber.yml:
* #{cucumber_yml.keys.sort.join("\n * ")}
END_OF_ERROR
end

Expand Down Expand Up @@ -84,7 +84,7 @@ def process_configuration_file_with_erb
def load_configuration
require 'yaml'
begin
@cucumber_yml = YAML.load(@cucumber_erb) # rubocop:disable Security/YAMLLoad
@cucumber_yml = YAML.load(@cucumber_erb)
rescue StandardError
raise(YmlLoadError, "cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.\n")
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def formatter_factories
yield factory,
formatter_options,
path_or_io
rescue Exception => e # rubocop:disable Lint/RescueException
rescue Exception => e
raise e, "#{e.message}\nError creating formatter: #{format}", e.backtrace
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/cucumber/formatter/ansicolor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ module ANSIColor
"#{h[Regexp.last_match(1)]},bold"
end.merge(
'undefined' => 'yellow',
'pending' => 'yellow',
'flaky' => 'yellow',
'failed' => 'red',
'passed' => 'green',
'outline' => 'cyan',
'skipped' => 'cyan',
'comment' => 'grey',
'tag' => 'cyan'
'pending' => 'yellow',
'flaky' => 'yellow',
'failed' => 'red',
'passed' => 'green',
'outline' => 'cyan',
'skipped' => 'cyan',
'comment' => 'grey',
'tag' => 'cyan'
)
# :startdoc:

Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/formatter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def internal_hook?(test_step)
end

def current_feature
@feature_hash ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName
@feature_hash ||= {}
end

def feature_elements
Expand Down
Loading

0 comments on commit f23e603

Please sign in to comment.