Skip to content

Commit

Permalink
Update target syntax in rucocop.yml and fix offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent ffd4659 commit 1b4d444
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This is a config synced from dry-rb/template-gem repo

AllCops:
TargetRubyVersion: 3.0
NewCops: disable
TargetRubyVersion: 3.1
NewCops: enable
SuggestExtensions: false
Exclude:
- "**/vendor/**/*" # For GitHub Actions, see rubocop/rubocop#9832
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/core/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def cache
#
# @return [Object] block's return value (cached for subsequent calls with
# the same argument values)
def fetch_or_store(*args, &block)
cache.fetch_or_store(args.hash, &block)
def fetch_or_store(*args, &)
cache.fetch_or_store(args.hash, &)
end

# Instance methods
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/core/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Constants
# An empty string
EMPTY_STRING = ""
# Identity function
IDENTITY = (-> x { x }).freeze
IDENTITY = ->(x) { x }.freeze

# A special value you can use as a default to know if no arguments
# were passed to the method
Expand Down
22 changes: 11 additions & 11 deletions lib/dry/core/container/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def inherited(subclass)

# @private
module Initializer
def initialize(*args, &block)
def initialize(...)
@_container = ::Concurrent::Hash.new
super
end
Expand Down Expand Up @@ -112,8 +112,8 @@ def register(key, contents = nil, options = EMPTY_HASH, &block)
config.registry.call(_container, key, item, options)

self
rescue FrozenError
raise FrozenError,
rescue ::FrozenError
raise ::FrozenError,
"can't modify frozen #{self.class} (when attempting to register '#{key}')"
end

Expand All @@ -128,8 +128,8 @@ def register(key, contents = nil, options = EMPTY_HASH, &block)
# @return [Mixed]
#
# @api public
def resolve(key, &block)
config.resolver.call(_container, key, &block)
def resolve(key, &)
config.resolver.call(_container, key, &)
end

# Resolve an item from the container
Expand Down Expand Up @@ -198,8 +198,8 @@ def keys
# @return [Dry::Core::Container::Mixin] self
#
# @api public
def each_key(&block)
config.resolver.each_key(_container, &block)
def each_key(&)
config.resolver.each_key(_container, &)
self
end

Expand All @@ -215,8 +215,8 @@ def each_key(&block)
# @note In discussions with other developers, it was felt that being able to iterate
# over not just the registered keys, but to see what was registered would be
# very helpful. This is a step toward doing that.
def each(&block)
config.resolver.each(_container, &block)
def each(&)
config.resolver.each(_container, &)
end

# Decorates an item from the container with specified decorator
Expand Down Expand Up @@ -250,12 +250,12 @@ def decorate(key, with: nil, &block)
# @return [Dry::Core::Container::Mixin] self
#
# @api public
def namespace(namespace, &block)
def namespace(namespace, &)
::Dry::Core::Container::NamespaceDSL.new(
self,
namespace,
config.namespace_separator,
&block
&
)

self
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/core/container/namespace_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def initialize(container, namespace, namespace_separator, &block)
end
end

def register(key, *args, &block)
super(namespaced(key), *args, &block)
def register(key, ...)
super(namespaced(key), ...)
end

def namespace(namespace, &block)
super(namespaced(namespace), &block)
def namespace(namespace, &)
super(namespaced(namespace), &)
end

def import(namespace)
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/core/container/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def keys(container)
# @return Hash
#
# @api public
def each_key(container, &block)
container.each_key(&block)
def each_key(container, &)
container.each_key(&)
end

# Calls block once for each key in container, passing the key and
Expand All @@ -81,8 +81,8 @@ def each_key(container, &block)
# @note In discussions with other developers, it was felt that being able
# to iterate over not just the registered keys, but to see what was
# registered would be very helpful. This is a step toward doing that.
def each(container, &block)
container.map { |key, value| [key, value.call] }.each(&block)
def each(container, &)
container.map { |key, value| [key, value.call] }.each(&)
end
end
end
Expand Down
8 changes: 5 additions & 3 deletions lib/dry/core/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def self.realize_backend(path, backend_factory)
def self.detect_backend
BACKENDS.inject(nil) do |backend, (_, (path, factory))|
backend || realize_backend(path, factory)
end || raise(LoadError,
"No inflector library could be found: "\
"please install either the `inflecto` or `activesupport` gem.")
end || raise(
LoadError,
"No inflector library could be found: " \
"please install either the `inflecto` or `activesupport` gem."
)
end

# Set preferred backend
Expand Down
6 changes: 3 additions & 3 deletions spec/dry/core/basic_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def respond_to?(_method_name, _include_all = false) # rubocop:disable Style/Opti

context "when object is not instance of the given class" do
it "returns false" do
expect(subject.instance_of?(::String)).to be(false)
expect(subject.instance_of?(String)).to be(false)
end
end

Expand All @@ -118,7 +118,7 @@ def respond_to?(_method_name, _include_all = false) # rubocop:disable Style/Opti

context "when object is not instance of the given class" do
it "returns false" do
expect(subject.is_a?(::String)).to be(false)
expect(subject.is_a?(String)).to be(false)
end
end

Expand Down Expand Up @@ -170,7 +170,7 @@ def respond_to?(_method_name, _include_all = false) # rubocop:disable Style/Opti

context "when object is not instance of the given class" do
it "returns false" do
expect(subject.kind_of?(::String)).to be(false)
expect(subject.kind_of?(String)).to be(false)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/dry/core/class_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def self.testing; end
it "does not search for parent class through inheritance" do
expect(klass.name).to eql("Test::File")
expect(klass.superclass).to be(Test::File)
expect(Test::File).not_to be(::File)
expect(Test::File).not_to be(File)
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/dry/core/equalizer/universal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "spec_helper"

RSpec.describe Dry::Core::Equalizer do
let(:name) { "User" }
let(:klass) { ::Class.new }
let(:name) { "User" }
let(:klass) { Class.new }

context "with no keys" do
subject { Dry::Core::Equalizer() }
Expand Down Expand Up @@ -59,7 +59,7 @@
expect(klass.instance_method(:hash).arity).to be(0)
end

it { expect(instance.hash).to eql([klass].hash) }
it { expect(instance.hash).to eql([klass].hash) } # rubocop:disable Security/CompoundHash
end

describe "#inspect" do
Expand All @@ -80,7 +80,7 @@
let(:instance) { klass.new(firstname, lastname) }

let(:klass) do
::Class.new do
Class.new do
attr_reader :firstname, :lastname
attr_writer :firstname
private :firstname, :lastname
Expand Down Expand Up @@ -184,7 +184,7 @@ def initialize(firstname, lastname)
let(:instance) { klass.new(firstname, lastname) }

let(:klass) do
::Class.new do
Class.new do
attr_reader :firstname, :lastname
private :firstname, :lastname

Expand Down Expand Up @@ -223,7 +223,7 @@ def initialize(firstname, lastname)
let(:instance) { klass.new(firstname, lastname) }

let(:klass) do
::Struct.new(:firstname, :lastname)
Struct.new(:firstname, :lastname)
end

before { klass.include(subject) }
Expand Down
6 changes: 3 additions & 3 deletions spec/dry/core/inflector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
end

it "prefers ActiveSupport::Inflector" do
expect(api.inflector).to be ::ActiveSupport::Inflector
expect(api.inflector).to be ActiveSupport::Inflector
end
end

Expand All @@ -65,7 +65,7 @@
end

it "is ActiveSupport::Inflector" do
expect(api.inflector).to be(::ActiveSupport::Inflector)
expect(api.inflector).to be(ActiveSupport::Inflector)
end

it_behaves_like "an inflector"
Expand All @@ -78,7 +78,7 @@
end

it "is Inflecto" do
expect(api.inflector).to be(::Inflecto)
expect(api.inflector).to be(Inflecto)
end

it_behaves_like "an inflector"
Expand Down
21 changes: 6 additions & 15 deletions spec/support/memoized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def test9
}
include Dry::Core::Memoizable

def test1(arg1, *args, kwarg1:, kwarg2: "default", **kwargs, &block)
def test1(arg1, *args, kwarg1:, kwarg2: "default", **kwargs, &)
# NOP
end

def test2(arg1, arg2 = "default", *args, &block)
def test2(arg1, arg2 = "default", *args, &)
# NOP
end

def test3(&block)
def test3(&)
# NOP
end

Expand All @@ -40,22 +40,13 @@ def test8(args = 1, kwargs = 2, *, **)
# NOP
end

if RUBY_VERSION >= "2.7"
module_eval(<<~RUBY, __FILE__, __LINE__ + 1)
def test9(...)
super
end
RUBY
def test9(...)
super
end

def self.memoize_methods
@memoized ||= begin
if RUBY_VERSION >= "2.7"
memoize :test1, :test2, :test3, :test4, :test5, :test6, :test7, :test8, :test9
else
memoize :test1, :test2, :test3, :test4, :test5, :test6, :test7, :test8
end

memoize :test1, :test2, :test3, :test4, :test5, :test6, :test7, :test8, :test9
true
end
end
Expand Down

0 comments on commit 1b4d444

Please sign in to comment.