Skip to content

Commit

Permalink
Refactor/layout lint fixes (#1750)
Browse files Browse the repository at this point in the history
* Autofix and then manually tidy up Layout/HashAlignment

* AF: Layout/TrailingWhiteSpace

* AF: Lint/AmbiguousOperator

* Remove the muddy situation where cops are duplicated in TODO and in regular style file. The regular style file is now almost completed

* Regenerate TODO

* Partial fix for MemoizedInstanceVariableName - we only had one usage for the private method so make a better fetching paradigm and remove the erroneous memoizer

* Partial fixes for some variable names used in method / blocks

* AF: RSpec/ReturnFromStub

* Fixes for described class in rspec

* Partial fix to begin removing verbose iVars

* Fix remnants of invalid iVar assign

* Some limited context wording fixes

* Manually fix Naming/VariableNumber

* Partial manual fix of Naming/MethodParameterName

* Add changelog note
  • Loading branch information
luke-hill authored Jan 23, 2024
1 parent b126fc8 commit f031424
Show file tree
Hide file tree
Showing 28 changed files with 201 additions and 288 deletions.
32 changes: 2 additions & 30 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,7 @@ Lint/UselessMethodDefinition:
Exclude:
- 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
Exclude:
- lib/cucumber/cli/options.rb
# TODO: Manually added! - be careful with regenning the file - this needs a fix
- lib/cucumber/formatter/pretty.rb

# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
Metrics/ModuleLength:
Max: 135
Exclude:
- spec/**/*
# TODO: Manually added! - be careful with regenning the file - this needs a fix
- lib/cucumber/formatter/console.rb

# TODO: [LH] - Initial 10% reduction done Aug '23 - Further reductions should happen as/when we fix a bunch of the todo
Metrics/MethodLength:
Max: 27
# TODO: Manually added! - be careful with regenning the file - this needs a fix
Exclude:
- lib/cucumber/cli/main.rb
- lib/cucumber/cli/options.rb
- lib/cucumber/formatter/publish_banner_printer.rb
- spec/cucumber/formatter/http_io_spec.rb
- lib/cucumber/glue/proto_world.rb

# Rubocop doesn't like method names in other languages but as Cucumber supports multiple languages, this cop needs to be disabled.
# Rubocop doesn't like method names in other languages but as Cucumber supports multiple languages, this cop needs to be disabled
Naming/AsciiIdentifiers:
Enabled: false

Expand All @@ -77,8 +50,7 @@ Naming/FileName:
Exclude:
- compatibility/features/**/*

# For the most part, the project is solid on naming. There are though, a few
# cases where the cop doesn't need to catch.
# For the most part, the project is solid on naming. There are though, a few cases where the cop doesn't need to catch
Naming/MethodName:
Exclude:
- examples/i18n/ar/lib/calculator.rb
Expand Down
75 changes: 19 additions & 56 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-08 14:57:03 UTC using RuboCop version 1.56.4.
# on 2024-01-17 12:23:33 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] -> 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: 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:
- 'lib/cucumber/cli/options.rb'

# Offense count: 19
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Exclude:
- 'lib/cucumber/multiline_argument/data_table.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
Lint/AmbiguousOperator:
Exclude:
- 'lib/cucumber/multiline_argument/data_table.rb'
- 'lib/cucumber/running_test_case.rb'
- 'spec/cucumber/formatter/spec_helper.rb'
# TODO - [LH] -> Jan '23 (cleaned up most of the config) - 364 files inspected, 713 offenses detected, 132 offenses autocorrectable

# Offense count: 4
Lint/RescueException:
Expand All @@ -45,7 +18,7 @@ Lint/RescueException:
- 'lib/cucumber/glue/invoke_in_world.rb'
- 'lib/cucumber/glue/proto_world.rb'

# Offense count: 4
# Offense count: 60
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 127
Expand All @@ -56,11 +29,26 @@ Metrics/AbcSize:
Metrics/BlockLength:
Max: 52

# Offense count: 13
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 523

# Offense count: 8
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 12

# Offense count: 74
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 72

# Offense count: 17
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 804

# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Expand Down Expand Up @@ -131,12 +119,6 @@ RSpec/ContextWording:
- 'spec/cucumber/formatter/publish_banner_printer_spec.rb'
- 'spec/cucumber/glue/step_definition_spec.rb'

# Offense count: 1
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- 'spec/cck/cck_spec.rb'

# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
Expand Down Expand Up @@ -222,7 +204,7 @@ RSpec/MissingExampleGroupArgument:
- 'spec/cucumber/formatter/fail_fast_spec.rb'
- 'spec/cucumber/formatter/rerun_spec.rb'

# Offense count: 59
# Offense count: 58
RSpec/MultipleExpectations:
Max: 3

Expand Down Expand Up @@ -317,31 +299,12 @@ 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.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/autotest/cucumber.rb'
- 'lib/autotest/cucumber_mixin.rb'
- 'lib/autotest/cucumber_rails.rb'
- 'lib/autotest/cucumber_rails_rspec.rb'
- 'lib/autotest/cucumber_rails_rspec2.rb'
- 'lib/autotest/cucumber_rspec.rb'
- 'lib/autotest/cucumber_rspec2.rb'

# Offense count: 3
Style/ClassVars:
Exclude:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
### Changed
- Moved all CCK step definition/miscellaneous file logic from CCK gem to this repo.
All logic contained in [compatibility](./compatibility) ([luke-hill](https://github.com/luke-hill))
- Cleared up a few Layout/Linting cop offenses ([#1750](https://github.com/cucumber/cucumber-ruby/pull/1750) [luke-hill](https://github.com/luke-hill))

### Fixed
- Fix a situation whereby the step definition message will omit the parameter-type name when it cannot be inferred
Expand Down
8 changes: 4 additions & 4 deletions examples/i18n/bg/lib/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def result
end

def +
number_1 = @stack.pop
number_2 = @stack.pop
number1 = @stack.pop
number2 = @stack.pop

@stack.push number_1 + number_2
@stack.push(number1 + number2)
end

def /
divisor = @stack.pop
dividend = @stack.pop

@stack.push dividend / divisor
@stack.push(dividend / divisor)
end
end
6 changes: 3 additions & 3 deletions examples/i18n/ru/lib/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def result
end

def +
number_1 = @stack.pop
number_2 = @stack.pop
number1 = @stack.pop
number2 = @stack.pop

@stack.push(number_1 + number_2)
@stack.push(number1 + number2)
end

def /
Expand Down
6 changes: 3 additions & 3 deletions examples/i18n/uk/lib/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def result
end

def +
number_1 = @stack.pop
number_2 = @stack.pop
number1 = @stack.pop
number2 = @stack.pop

@stack.push(number_1 + number_2)
@stack.push(number1 + number2)
end

def /
Expand Down
6 changes: 3 additions & 3 deletions examples/i18n/uz/lib/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def result
end

def +
number_1 = @stack.pop
number_2 = @stack.pop
number1 = @stack.pop
number2 = @stack.pop

@stack.push(number_1 + number_2)
@stack.push(number1 + number2)
end

def /
Expand Down
58 changes: 29 additions & 29 deletions lib/cucumber/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class Options
CUCUMBER_PUBLISH_URL = ENV['CUCUMBER_PUBLISH_URL'] || 'https://messages.cucumber.io/api/reports -X GET'
INDENT = ' ' * 53
BUILTIN_FORMATS = {
'pretty' => ['Cucumber::Formatter::Pretty', 'Prints the feature as is - in colours.'],
'progress' => ['Cucumber::Formatter::Progress', 'Prints one character per scenario.'],
'rerun' => ['Cucumber::Formatter::Rerun', 'Prints failing files with line numbers.'],
'usage' => ['Cucumber::Formatter::Usage', "Prints where step definitions are used.\n" \
"#{INDENT}The slowest step definitions (with duration) are\n" \
"#{INDENT}listed first. If --dry-run is used the duration\n" \
"#{INDENT}is not shown, and step definitions are sorted by\n" \
"#{INDENT}filename instead."],
'stepdefs' => ['Cucumber::Formatter::Stepdefs', "Prints All step definitions with their locations. Same as\n" \
"#{INDENT}the usage formatter, except that steps are not printed."],
'junit' => ['Cucumber::Formatter::Junit', "Generates a report similar to Ant+JUnit. Use\n" \
"#{INDENT}junit,fileattribute=true to include a file attribute."],
'json' => ['Cucumber::Formatter::Json', "Prints the feature as JSON.\n" \
"#{INDENT}The JSON format is in maintenance mode.\n" \
"#{INDENT}Please consider using the message formatter\n"\
"#{INDENT}with the standalone json-formatter\n" \
"#{INDENT}(https://github.com/cucumber/cucumber/tree/master/json-formatter)."],
'message' => ['Cucumber::Formatter::Message', 'Prints each message in NDJSON form, which can then be consumed by other tools.'],
'html' => ['Cucumber::Formatter::HTML', 'Outputs HTML report'],
'summary' => ['Cucumber::Formatter::Summary', 'Summary output of feature and scenarios']
'pretty' => ['Cucumber::Formatter::Pretty', 'Prints the feature as is - in colours.'],
'progress' => ['Cucumber::Formatter::Progress', 'Prints one character per scenario.'],
'rerun' => ['Cucumber::Formatter::Rerun', 'Prints failing files with line numbers.'],
'usage' => ['Cucumber::Formatter::Usage', "Prints where step definitions are used.\n" \
"#{INDENT}The slowest step definitions (with duration) are\n" \
"#{INDENT}listed first. If --dry-run is used the duration\n" \
"#{INDENT}is not shown, and step definitions are sorted by\n" \
"#{INDENT}filename instead."],
'stepdefs' => ['Cucumber::Formatter::Stepdefs', "Prints All step definitions with their locations. Same as\n" \
"#{INDENT}the usage formatter, except that steps are not printed."],
'junit' => ['Cucumber::Formatter::Junit', "Generates a report similar to Ant+JUnit. Use\n" \
"#{INDENT}junit,fileattribute=true to include a file attribute."],
'json' => ['Cucumber::Formatter::Json', "Prints the feature as JSON.\n" \
"#{INDENT}The JSON format is in maintenance mode.\n" \
"#{INDENT}Please consider using the message formatter\n"\
"#{INDENT}with the standalone json-formatter\n" \
"#{INDENT}(https://github.com/cucumber/cucumber/tree/master/json-formatter)."],
'message' => ['Cucumber::Formatter::Message', 'Prints each message in NDJSON form, which can then be consumed by other tools.'],
'html' => ['Cucumber::Formatter::HTML', 'Outputs HTML report'],
'summary' => ['Cucumber::Formatter::Summary', 'Summary output of feature and scenarios']
}.freeze
max = BUILTIN_FORMATS.keys.map(&:length).max
FORMAT_HELP_MSG = [
Expand Down Expand Up @@ -295,9 +295,9 @@ def strict_msg
]
end

def parse_formats(v)
formatter, *formatter_options = v.split(',')
options_hash = Hash[formatter_options.map { |s| s.split('=') }]
def parse_formats(value)
formatter, *formatter_options = value.split(',')
options_hash = Hash[formatter_options.map { |string| string.split('=') }]
[formatter, options_hash]
end

Expand Down Expand Up @@ -375,12 +375,12 @@ def banner
].join("\n")
end

def require_files(v)
@options[:require] << v
return unless Cucumber::JRUBY && File.directory?(v)
def require_files(filenames)
@options[:require] << filenames
return unless Cucumber::JRUBY && File.directory?(filenames)

require 'java'
$CLASSPATH << v
$CLASSPATH << filenames
end

def require_jars(jars)
Expand Down Expand Up @@ -441,8 +441,8 @@ def initialize_project
ProjectInitializer.new.run && Kernel.exit(0)
end

def add_profile(p)
@profiles << p
def add_profile(profile)
@profiles << profile
end

def set_option(option, value = nil)
Expand Down
26 changes: 9 additions & 17 deletions lib/cucumber/formatter/ansicolor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ module Formatter
module ANSIColor
include Cucumber::Term::ANSIColor

# :stopdoc:
ALIASES = Hash.new do |h, k|
next unless k.to_s =~ /(.*)_param/

Expand All @@ -79,13 +78,8 @@ module ANSIColor
'comment' => 'grey',
'tag' => 'cyan'
)
# :startdoc:

# Apply the custom color scheme
#
# example:
#
# apply_custom_colors('passed=white')
# Apply the custom color scheme -> i.e. apply_custom_colors('passed=white')
def self.apply_custom_colors(colors)
colors.split(':').each do |pair|
a = pair.split('=')
Expand Down Expand Up @@ -117,23 +111,21 @@ def self.apply_custom_colors(colors)
end
end

# :stopdoc:
def cukes(n)
('(::) ' * n).strip
def cukes(amount)
('(::) ' * amount).strip
end

def green_cukes(n)
blink(green(cukes(n)))
def green_cukes(amount)
blink(green(cukes(amount)))
end

def red_cukes(n)
blink(red(cukes(n)))
def red_cukes(amount)
blink(red(cukes(amount)))
end

def yellow_cukes(n)
blink(yellow(cukes(n)))
def yellow_cukes(amount)
blink(yellow(cukes(amount)))
end
# :startdoc:

private

Expand Down
Loading

0 comments on commit f031424

Please sign in to comment.