Skip to content

Commit

Permalink
Address offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 7, 2025
1 parent 959efb9 commit 62b33fb
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,7 @@ Naming/VariableNumber:

Naming/BinaryOperatorParameterName:
Enabled: false

Style/SymbolProc:
Exclude:
- "spec/**/*.rb"
2 changes: 1 addition & 1 deletion lib/dry/monads/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(failure)
class ConstructorNotAppliedError < ::NoMethodError
def initialize(method_name, constructor_name)
super(
"For calling .#{method_name} on #{constructor_name}() build a value "\
"For calling .#{method_name} on #{constructor_name}() build a value " \
"by appending parens: #{constructor_name}()"
)
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/monads/lazy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Lazy < Task

class << self
# @private
def new(promise = nil, &block)
def new(promise = nil, &)
if promise
super(promise)
else
super(Concurrent::Promise.new(executor: :immediate, &block))
super(Concurrent::Promise.new(executor: :immediate, &))
end
end

Expand Down Expand Up @@ -79,8 +79,8 @@ module Constructors
#
# @param block [Proc]
# @return [Lazy]
def Lazy(&block)
Lazy.new(&block)
def Lazy(&)
Lazy.new(&)
end
end

Expand Down
16 changes: 8 additions & 8 deletions lib/dry/monads/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def last
#
# @param initial [Object] Initial value
# @return [Object]
def fold_left(initial, &block)
value.reduce(initial, &block)
def fold_left(initial, &)
value.reduce(initial, &)
end
alias_method :foldl, :fold_left
alias_method :reduce, :fold_left
Expand Down Expand Up @@ -214,8 +214,8 @@ def sort
# Filters elements with a block
#
# @return [List]
def filter(&block)
coerce(value.select(&block))
def filter(&)
coerce(value.select(&))
end
alias_method :select, :filter

Expand Down Expand Up @@ -258,8 +258,8 @@ def typed(type = nil)
raise ArgumentError, "Cannot infer a monad for an empty list"
else
self.class.warn(
"Automatic monad inference is deprecated, pass a type explicitly "\
"or use a predefined constant, e.g. List::Result\n"\
"Automatic monad inference is deprecated, pass a type explicitly " \
"or use a predefined constant, e.g. List::Result\n" \
"#{caller.find { _1 !~ %r{(lib/dry/monads)|(gems)} }}"
)
self.class.new(value, value[0].monad)
Expand Down Expand Up @@ -305,8 +305,8 @@ def traverse(proc = nil, &block)
#
# @param list [List]
# @return [List]
def apply(list = Undefined, &block)
v = Undefined.default(list, &block)
def apply(list = Undefined, &)
v = Undefined.default(list, &)
fmap(Curry).bind { |f| v.fmap { f.(_1) } }
end

Expand Down
10 changes: 5 additions & 5 deletions lib/dry/monads/maybe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def fmap(...)
if next_value.nil?
if self.class.warn_on_implicit_nil_coercion
Core::Deprecations.warn(
"Block passed to Some#fmap returned `nil` and was chained to None. "\
"This is literally an unlawful behavior and it will not be supported in "\
"dry-monads 2. \nPlease, replace `.fmap` with `.maybe` in places where you "\
"expect `nil` as block result.\n"\
"You can opt out of these warnings with\n"\
"Block passed to Some#fmap returned `nil` and was chained to None. " \
"This is literally an unlawful behavior and it will not be supported in " \
"dry-monads 2. \nPlease, replace `.fmap` with `.maybe` in places where you " \
"expect `nil` as block result.\n" \
"You can opt out of these warnings with\n" \
"Dry::Monads::Maybe.warn_on_implicit_nil_coercion false",
uplevel: 0,
tag: :"dry-monads"
Expand Down
28 changes: 14 additions & 14 deletions lib/dry/monads/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class << self
# @param block [Proc] a task to run
# @return [Task]
#
def new(promise = nil, &block)
def new(promise = nil, &)
if promise
super(promise)
else
super(Promise.execute(&block))
super(Promise.execute(&))
end
end

Expand All @@ -50,8 +50,8 @@ def new(promise = nil, &block)
# from concurrent-ruby
#
# @return [Task]
def [](executor, &block)
new(Promise.execute(executor: executor, &block))
def [](executor, &)
new(Promise.execute(executor: executor, &))
end

# Returns a completed task from the given value
Expand Down Expand Up @@ -110,8 +110,8 @@ def value!
# @param block [Proc]
# @return [Task]
# @api public
def fmap(&block)
self.class.new(promise.then(&block))
def fmap(&)
self.class.new(promise.then(&))
end

# Composes two tasks to run one after another.
Expand Down Expand Up @@ -148,8 +148,8 @@ def to_s
#
# @param block [Proc]
# @return [Task]
def or_fmap(&block)
self.class.new(promise.rescue(&block))
def or_fmap(&)
self.class.new(promise.rescue(&))
end

# Rescues the error with a block that returns another task.
Expand Down Expand Up @@ -180,8 +180,8 @@ def or(&block)
#
# @param block [Proc]
# @return [Object]
def value_or(&block)
promise.rescue(&block).wait.value
def value_or(&)
promise.rescue(&).wait.value
end

# Blocks the current thread until the task is complete.
Expand Down Expand Up @@ -233,8 +233,8 @@ def to_monad
#
# @param val [Task]
# @return [Task]
def apply(val = Undefined, &block)
arg = Undefined.default(val, &block)
def apply(val = Undefined, &)
arg = Undefined.default(val, &)
bind { |f| arg.fmap { curry(f).(_1) } }
end

Expand Down Expand Up @@ -302,8 +302,8 @@ module Constructors
#
# @param block [Proc]
# @return Task
def Task(&block)
Task.new(&block)
def Task(&)
Task.new(&)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/dry/monads/validated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def value!
# @yieldreturn [Validated::Valid,Validated::Invalid]
# @return [Validated::Valid,Validated::Invalid]
#
def apply(val = Undefined, &block)
Undefined.default(val, &block).fmap(Curry.(value!))
def apply(val = Undefined, &)
Undefined.default(val, &).fmap(Curry.(value!))
end

# Lifts a block/proc over Valid
Expand Down
2 changes: 1 addition & 1 deletion lib/json/add/dry/monads/maybe.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: false

require "json" unless defined?(::JSON::JSON_LOADED) && ::JSON::JSON_LOADED
require "json" unless defined?(JSON::JSON_LOADED) && JSON::JSON_LOADED

require "dry/monads"

Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

require "dry/monads/all"

Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
Dir["./spec/shared/**/*.rb"].each { |f| require f }

module Kernel
def suppress_warnings
Expand Down Expand Up @@ -50,7 +50,7 @@ def re_require(*paths)
module Dry::Monads
def self.unload_monad(name)
if registry.key?(name.to_sym)
self.registry = registry.reject { |k, _| k.eql?(name.to_sym) }
self.registry = registry.except(name.to_sym)
end
end
end
Expand Down

0 comments on commit 62b33fb

Please sign in to comment.