Skip to content

Commit

Permalink
Fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 3, 2025
1 parent 586c98b commit 8a33f49
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ eval_gemfile "Gemfile.devtools"
gemspec

gem "dry-configurable", github: "dry-rb/dry-configurable", branch: "main"
gem "dry-core", github: "dry-rb/dry-core", branch: "main"
gem "dry-logic", github: "dry-rb/dry-logic", branch: "main"
gem "dry-types", github: "dry-rb/dry-types", branch: "main"
gem "dry-core", github: "dry-rb/dry-core", branch: "main"

group :test do
gem "dry-monads"
Expand Down
12 changes: 6 additions & 6 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ module Types
end

class Context
def schema(&block)
Dry::Schema.define(&block)
def schema(&)
Dry::Schema.define(&)
end

def params(&block)
Dry::Schema.Params(&block)
def params(&)
Dry::Schema.Params(&)
end

def json(&block)
Dry::Schema.JSON(&block)
def json(&)
Dry::Schema.JSON(&)
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/dry/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def self.config
# @see DSL.new
#
# @api public
def self.define(**options, &block)
DSL.new(**options, &block).call
def self.define(...)
DSL.new(...).call
end

# Define a schema suitable for HTTP params
Expand All @@ -83,8 +83,8 @@ def self.define(**options, &block)
# @see Schema#define
#
# @api public
def self.Params(**options, &block)
define(**options, processor_type: Params, &block)
def self.Params(**options, &)
define(**options, processor_type: Params, &)
end
singleton_class.send(:alias_method, :Form, :Params)

Expand All @@ -103,8 +103,8 @@ def self.Params(**options, &block)
# @see Schema#define
#
# @api public
def self.JSON(**options, &block)
define(**options, processor_type: JSON, &block)
def self.JSON(**options, &)
define(**options, processor_type: JSON, &)
end

loader.setup
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def inspect
# Forward to the underlying config object
#
# @api private
def method_missing(meth, *args, &block)
def method_missing(meth, ...)
super unless config.respond_to?(meth)
config.public_send(meth, *args)
config.public_send(meth, ...)
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/dry/schema/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def self.new(**options, &block)
# @return [DSL]
#
# @api public
def configure(&block)
config.configure(&block)
def configure(&)
config.configure(&)
self
end

Expand Down Expand Up @@ -141,8 +141,8 @@ def [](name)
# @return [Macros::Required]
#
# @api public
def required(name, &block)
key(name, macro: Macros::Required, &block)
def required(name, &)
key(name, macro: Macros::Required, &)
end

# Define an optional key
Expand All @@ -157,8 +157,8 @@ def required(name, &block)
# @return [Macros::Optional]
#
# @api public
def optional(name, &block)
key(name, macro: Macros::Optional, &block)
def optional(name, &)
key(name, macro: Macros::Optional, &)
end

# A generic method for defining keys
Expand Down Expand Up @@ -249,8 +249,8 @@ def array
# @return [DSL]
#
# @api public
def before(key, &block)
steps.before(key, &block)
def before(key, &)
steps.before(key, &)
self
end

Expand All @@ -264,8 +264,8 @@ def before(key, &block)
# @return [DSL]
#
# @api public
def after(key, &block)
steps.after(key, &block)
def after(key, &)
steps.after(key, &)
self
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def hints?

# @api private
def filter(messages, opts)
Array(messages).flatten.map { |msg| msg unless exclude?(msg, opts) }.compact.uniq
Array(messages).flatten.reject { |msg| exclude?(msg, opts) }.uniq
end

# @api private
Expand Down
2 changes: 1 addition & 1 deletion lib/dry/schema/extensions/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def visit_struct(node)
def call(*args)
if args.size >= 1 && struct?(args[0])
if block_given?
raise ArgumentError, "blocks are not supported when using "\
raise ArgumentError, "blocks are not supported when using " \
"a struct class (#{name.inspect} => #{args[0]})"
end

Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/key_coercer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def self.symbolized(*args)
end

# @api private
def initialize(key_map, &coercer)
@key_map = key_map.coercible(&coercer)
def initialize(key_map, &)
@key_map = key_map.coercible(&)
end

# @api private
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/key_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def to_dot_notation
# Iterate over keys
#
# @api public
def each(&block)
keys.each(&block)
def each(&)
keys.each(&)
end

# Return a new key map merged with the provided one
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/macros/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def merge_operation_types(op)

# @api private
# rubocop: disable Metrics/AbcSize
def define(*args, &block)
definition = schema_dsl.new(path: schema_dsl.path, &block)
def define(*args, &)
definition = schema_dsl.new(path: schema_dsl.path, &)
schema = definition.call
type_schema =
if array_type?(parent_type)
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/schema/macros/value.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def call(*args, **opts, &block)
end
end

trace_opts = opts.reject { |key, _| %i[type_spec type_rule].include?(key) }
trace_opts = opts.except(:type_spec, :type_rule)

if (type_rule = opts[:type_rule])
trace.append(type_rule).evaluate(*predicates, **trace_opts)
Expand Down Expand Up @@ -112,9 +112,9 @@ def respond_to_missing?(meth, include_private = false)
private

# @api private
def method_missing(meth, *args, &block)
def method_missing(meth, ...)
if meth.to_s.end_with?(QUESTION_MARK)
trace.__send__(meth, *args, &block)
trace.__send__(meth, ...)
else
super
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/message_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ def message_tokens(args)
when ::Array
hash[arg[0]] = arg[1].join(LIST_SEPARATOR)
when ::Range
hash["#{arg[0]}_left".to_sym] = arg[1].first
hash["#{arg[0]}_right".to_sym] = arg[1].last
hash[:"#{arg[0]}_left"] = arg[1].first
hash[:"#{arg[0]}_right"] = arg[1].last
else
hash[arg[0]] = arg[1]
end
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/messages/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ def interpolate(key, options, **data)
# @api private
def evaluation_context(key, options)
cache.fetch_or_store(get(key, options).fetch(:text)) do |input|
tokens = input.scan(TOKEN_REGEXP).flatten(1).map(&:to_sym).to_set
tokens = input.scan(TOKEN_REGEXP).flatten(1).to_set(&:to_sym)
text = input.gsub("%", "#")

# rubocop:disable Security/Eval
evaluator = eval(<<~RUBY, EMPTY_CONTEXT, __FILE__, __LINE__ + 1)
-> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" }
-> (#{tokens.map { |token| "#{token}:" }.join(", ")}) { "#{text}" } # -> (a:, b:) { "Translation #\{a} #\{b}" }
RUBY
# rubocop:enable Security/Eval

Expand Down
8 changes: 4 additions & 4 deletions lib/dry/schema/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Path
def self.call(spec)
case spec
when ::Symbol, ::Array
new(::Array[*spec])
new([*spec])
when ::String
new(spec.split(DOT).map(&:to_sym))
when ::Hash
Expand All @@ -49,7 +49,7 @@ def self.[](spec)
# @api private
def self.keys_from_hash(hash)
hash.inject([]) { |a, (k, v)|
v.is_a?(::Hash) ? a.concat([k, *keys_from_hash(v)]) : a.concat([k, v])
v.is_a?(::Hash) ? a.push(k, *keys_from_hash(v)) : a.push(k, v)
}
end

Expand All @@ -66,8 +66,8 @@ def to_h(value = EMPTY_ARRAY.dup)
end

# @api private
def each(&block)
keys.each(&block)
def each(&)
keys.each(&)
end

# @api private
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/schema/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class << self
# @return [Class]
#
# @api public
def define(&block)
def define(&)
@definition ||= DSL.new(
processor_type: self, parent: superclass.definition, **config.to_h, &block
processor_type: self, parent: superclass.definition, **config.to_h, &
)
self
end
Expand Down
8 changes: 4 additions & 4 deletions lib/dry/schema/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ def self.new(*, **)
# @return [Result]
#
# @api private
def at(at_path, &block)
new(@output, path: Path.new([*path, *Path[at_path]]), &block)
def at(at_path, &)
new(@output, path: Path.new([*path, *Path[at_path]]), &)
end

# @api private
def new(output, **opts, &block)
def new(output, **opts, &)
self.class.new(
output,
message_compiler: message_compiler,
result_ast: result_ast,
**opts,
&block
&
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/issues_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
end

let(:calendar_date) do
Class.new(::Date) do
Class.new(Date) do
def to_json(*args)
strftime("--%m-%d").to_json(*args)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/messages/namespaced_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
config.messages.namespace = :post

required(:post_body).filled
required(:comment).hash(::Test::CommentSchema)
required(:comment).hash(Test::CommentSchema)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/schema/type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
context "constructor on optional type" do
let(:trimmed_string) do
Types::String.optional.constructor do |str, &block|
if str.is_a?(::String)
if str.is_a?(String)
stripped = str.strip

if stripped.empty?
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
rescue LoadError; end
SPEC_ROOT = Pathname(__dir__)

Dir[SPEC_ROOT.join("shared/**/*.rb")].sort.each(&method(:require))
Dir[SPEC_ROOT.join("support/**/*.rb")].sort.each(&method(:require))
Dir[SPEC_ROOT.join("shared/**/*.rb")].each(&method(:require))
Dir[SPEC_ROOT.join("support/**/*.rb")].each(&method(:require))

require "dry/schema"
require "dry/types"
Expand Down

0 comments on commit 8a33f49

Please sign in to comment.