Skip to content

Commit

Permalink
Refactor/rubocop autofix part2 (#258)
Browse files Browse the repository at this point in the history
* AF: Style/StringLiterals

* AF: Layout/SpaceInsideParens

* AF: RSpec/DescribedClass

* AF: RSpec/PredicateMatcher

* AF: Style/FrozenStringLiteralComment

* AF: Style/PercentLiteralDelimeters

* AF: Layout/EmptyLinesAroundBlockBody

* Regenned config
  • Loading branch information
luke-hill authored Sep 8, 2023
1 parent e9d61db commit c279d45
Show file tree
Hide file tree
Showing 38 changed files with 844 additions and 948 deletions.
98 changes: 4 additions & 94 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-07 17:19:02 UTC using RuboCop version 1.27.0.
# on 2023-09-07 17:25:54 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
Expand Down Expand Up @@ -37,35 +37,13 @@ Layout/EmptyLineAfterGuardClause:
- 'lib/cucumber/core/test/result.rb'
- 'lib/cucumber/core/test/step.rb'

# Offense count: 30
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'lib/cucumber/core/filter.rb'
- 'spec/cucumber/core/event_bus_spec.rb'
- 'spec/cucumber/core/event_spec.rb'
- 'spec/cucumber/core/filter_spec.rb'
- 'spec/cucumber/core/gherkin/writer_spec.rb'
- 'spec/cucumber/core/test/action_spec.rb'
- 'spec/cucumber/core/test/data_table_spec.rb'
- 'spec/cucumber/core/test/empty_multiline_argument_spec.rb'
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'
- 'spec/cucumber/core/test/location_spec.rb'
- 'spec/cucumber/core/test/result_spec.rb'
- 'spec/cucumber/core/test/runner_spec.rb'
- 'spec/cucumber/core/test/step_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 5
# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'cucumber-core.gemspec'
- 'spec/cucumber/core/test/runner_spec.rb'
- 'spec/cucumber/core/test/step_spec.rb'

# Offense count: 7
# This cop supports safe auto-correction (--auto-correct).
Expand Down Expand Up @@ -106,26 +84,6 @@ Layout/SpaceAroundOperators:
Exclude:
- 'cucumber-core.gemspec'

# Offense count: 735
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'spec/cucumber/core/compiler_spec.rb'
- 'spec/cucumber/core/gherkin/parser_spec.rb'
- 'spec/cucumber/core/gherkin/writer_spec.rb'
- 'spec/cucumber/core/report/summary_spec.rb'
- 'spec/cucumber/core/test/action_spec.rb'
- 'spec/cucumber/core/test/data_table_spec.rb'
- 'spec/cucumber/core/test/doc_string_spec.rb'
- 'spec/cucumber/core/test/location_spec.rb'
- 'spec/cucumber/core/test/result_spec.rb'
- 'spec/cucumber/core/test/runner_spec.rb'
- 'spec/cucumber/core/test/step_spec.rb'
- 'spec/cucumber/core/test/timer_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 7
# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Expand Down Expand Up @@ -232,13 +190,6 @@ RSpec/ContextWording:
- 'spec/cucumber/core/test/result_spec.rb'
- 'spec/cucumber/core/test/runner_spec.rb'

# Offense count: 121
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Enabled: false

# Offense count: 60
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Expand Down Expand Up @@ -324,26 +275,18 @@ RSpec/NotToNot:
Exclude:
- 'spec/cucumber/core/test/result_spec.rb'

# Offense count: 36
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
# SupportedStyles: inflected, explicit
RSpec/PredicateMatcher:
Exclude:
- 'spec/cucumber/core/test/case_spec.rb'
- 'spec/cucumber/core/test/result_spec.rb'

# Offense count: 2
RSpec/RepeatedDescription:
Exclude:
- 'spec/cucumber/core/gherkin/parser_spec.rb'

# Offense count: 10
# Offense count: 18
RSpec/RepeatedExample:
Exclude:
- 'spec/cucumber/core/filter_spec.rb'
- 'spec/cucumber/core/gherkin/parser_spec.rb'
- 'spec/cucumber/core/test/filters/locations_filter_spec.rb'
- 'spec/cucumber/core/test/result_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 1
Expand Down Expand Up @@ -433,23 +376,6 @@ Style/ExpandPathArguments:
Exclude:
- 'Rakefile'

# Offense count: 10
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'cucumber-core.gemspec'
- 'lib/cucumber/core/event.rb'
- 'lib/cucumber/core/event_bus.rb'
- 'lib/cucumber/core/events.rb'
- 'lib/cucumber/core/test/filters/activate_steps_for_self_test.rb'
- 'spec/cucumber/core/event_bus_spec.rb'
- 'spec/cucumber/core/event_spec.rb'
- 'spec/cucumber/core/report/summary_spec.rb'

# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
Style/IfUnlessModifier:
Expand Down Expand Up @@ -500,15 +426,6 @@ Style/ParallelAssignment:
- 'lib/cucumber/core/gherkin/writer.rb'
- 'lib/cucumber/core/test/result.rb'

# Offense count: 15
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'lib/cucumber/core/gherkin/writer.rb'
- 'lib/cucumber/core/test/doc_string.rb'
- 'spec/cucumber/core/test/data_table_spec.rb'

# Offense count: 1
# This cop supports safe auto-correction (--auto-correct).
Style/PerlBackrefs:
Expand Down Expand Up @@ -557,13 +474,6 @@ Style/SoleNestedConditional:
- 'lib/cucumber/core/test/doc_string.rb'
- 'lib/cucumber/core/test/result.rb'

# Offense count: 386
# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 3
# This cop supports safe auto-correction (--auto-correct).
Style/StructInheritance:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand Down
7 changes: 4 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# encoding: utf-8
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
Bundler::GemHelper.install_tasks

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

require 'rubocop/rake_task'
RuboCop::RakeTask.new

require "rspec/core/rake_task"
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new

namespace :spec do
desc "run (slow) performance tests"
desc 'run (slow) performance tests'
RSpec::Core::RakeTask.new(:slow) do |t|
t.rspec_opts = %w[--tag slow]
end
Expand Down
11 changes: 6 additions & 5 deletions cucumber-core.gemspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

version = File.read(File.expand_path('VERSION', __dir__)).strip

Gem::Specification.new do |s|
s.name = 'cucumber-core'
s.version = version
s.authors = ["Aslak Hellesøy", "Matt Wynne", "Steve Tooke", "Oleg Sukhodolsky", "Tom Brand"]
s.authors = ['Aslak Hellesøy', 'Matt Wynne', 'Steve Tooke', 'Oleg Sukhodolsky', 'Tom Brand']
s.description = 'Core library for the Cucumber BDD app'
s.summary = "cucumber-core-#{s.version}"
s.email = '[email protected]'
s.homepage = "https://cucumber.io"
s.homepage = 'https://cucumber.io'
s.platform = Gem::Platform::RUBY
s.license = "MIT"
s.license = 'MIT'
s.required_ruby_version = '>= 2.5'

s.metadata = {
Expand Down Expand Up @@ -41,6 +42,6 @@ Gem::Specification.new do |s|
'LICENSE',
'lib/**/*'
]
s.rdoc_options = ["--charset=UTF-8"]
s.require_path = "lib"
s.rdoc_options = ['--charset=UTF-8']
s.require_path = 'lib'
end
6 changes: 4 additions & 2 deletions lib/cucumber/core/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Cucumber
module Core
class Event
Expand Down Expand Up @@ -38,7 +40,7 @@ class << self
# @return [Symbol] the underscored name of the class to be used
#  as the key in an event registry.
def event_id
underscore(name.split("::").last).to_sym
underscore(name.split('::').last).to_sym
end

private
Expand All @@ -47,7 +49,7 @@ def underscore(string)
string.to_s.gsub('::', '/').
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z\d])([A-Z])/, '\1_\2').
tr("-", "_").
tr('-', '_').
downcase
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/cucumber/core/event_bus.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'cucumber/core/events'

module Cucumber
Expand Down Expand Up @@ -62,8 +64,8 @@ def is_registered_type?(event_type)
end

def validate_handler_and_event_id!(handler, event_id)
raise ArgumentError, "Please pass either an object or a handler block" unless handler
raise ArgumentError, "Please use a symbol for the event_id" unless event_id.is_a?(Symbol)
raise ArgumentError, 'Please pass either an object or a handler block' unless handler
raise ArgumentError, 'Please use a symbol for the event_id' unless event_id.is_a?(Symbol)
raise ArgumentError, "Event ID #{event_id} is not recognised. Try one of these:\n#{event_types.keys.join("\n")}" unless is_registered_id?(event_id)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/core/events.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# coding: utf-8
# frozen_string_literal: true

require 'cucumber/core/event'

Expand Down
1 change: 0 additions & 1 deletion lib/cucumber/core/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def done
args[-1] = new_receiver
self.class.new(*args)
end

end

if block
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/gherkin/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def statements

def doc_string_statement
[
%["""#{content_type}],
%("""#{content_type}),
strings,
'"""'
]
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/gherkin/writer/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def elements(*names)

def element(name)
define_method name do |*args, &source|
factory_name = String(name).split("_").map(&:capitalize).join
factory_name = String(name).split('_').map(&:capitalize).join
factory = Writer.const_get(factory_name)
factory.new(slurp_comments, *args).tap do |builder|
builder.instance_exec(&source) if source
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Cucumber
unless defined?(Cucumber::VERSION)
JRUBY = defined?(JRUBY_VERSION)
IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
IRONRUBY = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ironruby'
WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
OS_X = RbConfig::CONFIG['host_os'] =~ /darwin/
WINDOWS_MRI = WINDOWS && !JRUBY && !IRONRUBY
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/test/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Core
module Test
class Action
def initialize(location = nil, &block)
raise ArgumentError, "Passing a block to execute the action is mandatory." unless block
raise ArgumentError, 'Passing a block to execute the action is mandatory.' unless block
@location = location || Test::Location.new(*block.source_location)
@block = block
@timer = Timer.new
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/test/data_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def inspect
def verify_rows_are_same_length(raw)
raw.transpose
rescue IndexError
raise ArgumentError, "Rows must all be the same length"
raise ArgumentError, 'Rows must all be the same length'
end

def ensure_array_of_array(array)
Expand Down
10 changes: 5 additions & 5 deletions lib/cucumber/core/test/doc_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def doc_string?
end

def map
raise ArgumentError, "No block given" unless block_given?
raise ArgumentError, 'No block given' unless block_given?
new_content = yield content
self.class.new(new_content, content_type)
end
Expand All @@ -67,10 +67,10 @@ def ==(other)

def inspect
[
%{#<#{self.class}},
%{ """#{content_type}},
%{ #{@content}},
%{ """>}
%(#<#{self.class}),
%( """#{content_type}),
%( #{@content}),
%( """>)
].join("\n")
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Cucumber
module Core
module Test
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/core/test/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def self.from_source_location(file, line)
end

def self.new(file, raw_lines=nil)
file || raise(ArgumentError, "file is mandatory")
file || raise(ArgumentError, 'file is mandatory')
if raw_lines
Precise.new(file, Lines.new(raw_lines))
else
Expand Down Expand Up @@ -68,7 +68,7 @@ def match?(other)
end

def to_s
[file, lines.to_s].join(":")
[file, lines.to_s].join(':')
end

def hash
Expand Down Expand Up @@ -128,7 +128,7 @@ def to_s
return first.to_s if data.length == 1
return "#{data.min}..#{data.max}" if range?

data.to_a.join(":")
data.to_a.join(':')
end

def inspect
Expand Down
Loading

0 comments on commit c279d45

Please sign in to comment.