Skip to content

style(Style/OptionalBooleanParameter): manual #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ Style/NumericLiterals:
Style/NumericPredicate:
Enabled: false

Style/OptionalBooleanParameter:
AllowedMethods:
- respond_to?
- respond_to_missing?
- set_parent=

Style/RaiseArgs:
EnforcedStyle: compact

Expand Down
19 changes: 0 additions & 19 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -830,25 +830,6 @@ Style/OpenStructUse:
- 'spec/rails/controller_extension/controller_runtime_spec.rb'
- 'spec/support/rails_mock.rb'

# Offense count: 17
# Configuration parameters: AllowedMethods.
# AllowedMethods: respond_to_missing?
Style/OptionalBooleanParameter:
Exclude:
- 'lib/mongoid/association/embedded/cyclic.rb'
- 'lib/mongoid/association/many.rb'
- 'lib/mongoid/association/one.rb'
- 'lib/mongoid/association/referenced/has_many/enumerable.rb'
- 'lib/mongoid/atomic.rb'
- 'lib/mongoid/attributes/dynamic.rb'
- 'lib/mongoid/criteria.rb'
- 'lib/mongoid/criteria/queryable/extensions/string.rb'
- 'lib/mongoid/criteria/queryable/extensions/symbol.rb'
- 'lib/mongoid/criteria/queryable/key.rb'
- 'lib/mongoid/criteria/queryable/options.rb'
- 'spec/support/models/address.rb'
- 'spec/support/models/name.rb'

# Offense count: 38
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantCurrentDirectoryInPath:
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/association/embedded/cyclic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def recursively_embeds_many(options = {})
# or its children.
def recursively_embeds_one(options = {})
embeds_one(
cyclic_child_name(false),
cyclic_child_name(many: false),
options.merge(class_name: name, cyclic: true)
)
embedded_in cyclic_parent_name, class_name: name, cyclic: true
Expand All @@ -92,7 +92,7 @@ def cyclic_parent_name
#
# @return [ String ] "child_" plus the class name underscored in
# singular or plural form.
def cyclic_child_name(many = true)
def cyclic_child_name(many: true)
:"child_#{name.demodulize.underscore.send(many ? :pluralize : :singularize)}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/atomic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def atomic_array_add_to_sets
# person.atomic_updates(children)
#
# @return [ Hash ] The updates and their modifiers.
def atomic_updates(_use_indexes = false)
def atomic_updates(_use_indexes: false)
process_flagged_destroys
mods = Modifiers.new
generate_atomic_updates(mods, self)
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/criteria/queryable/expandable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Expandable
#
# @return [ Array<String, Object> ] The expanded field and value.
def expand_one_condition(field, value)
kv = field.__expr_part__(value.__expand_complex__, negating?)
kv = field.__expr_part__(value.__expand_complex__, negating: negating?)
[kv.keys.first.to_s, kv.values.first]
end

Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/criteria/queryable/extensions/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def __sort_option__
# @param [ true | false ] negating If the selection should be negated.
#
# @return [ Hash ] The selection.
def __expr_part__(value, negating = false)
::String.__expr_part__(self, value, negating)
def __expr_part__(value, negating: false)
::String.__expr_part__(self, value, negating: negating)
end

module ClassMethods
Expand All @@ -79,7 +79,7 @@ module ClassMethods
# @param [ true | false ] negating If the selection should be negated.
#
# @return [ Hash ] The selection.
def __expr_part__(key, value, negating = false)
def __expr_part__(key, value, negating: false)
if negating
{ key => { "$#{__regexp?(value) ? 'not' : 'ne'}" => value } }
else
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/criteria/queryable/extensions/symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module Symbol
# @param [ true | false ] negating If the selection should be negated.
#
# @return [ Hash ] The selection.
def __expr_part__(value, negating = false)
::String.__expr_part__(self, value, negating)
def __expr_part__(value, negating: false)
::String.__expr_part__(self, value, negating: negating)
end

module ClassMethods
Expand Down
6 changes: 3 additions & 3 deletions lib/mongoid/criteria/queryable/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def initialize(name, strategy, operator, expanded = nil, &block)
# @param [ true | false ] negating If the selection should be negated.
#
# @return [ Hash ] The raw MongoDB selector.
def __expr_part__(object, negating = false)
{ name.to_s => transform_value(object, negating) }
def __expr_part__(object, negating: false)
{ name.to_s => transform_value(object, negating: negating) }
end

# Gets the raw selector condition that would be passed to Mongo.
Expand All @@ -144,7 +144,7 @@ def __expr_part__(object, negating = false)
# @param [ true | false ] negating If the selection should be negated.
#
# @return [ Hash ] The raw MongoDB selector.
def transform_value(value, negating = false)
def transform_value(value, negating: false)
expr = block ? block[value] : value
expr = { expanded => expr } if expanded
expr = { operator => expr }
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/criteria/queryable/mergeable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _mongoid_expand_keys(expr)

result = BSON::Document.new
expr.each do |field, value|
field.__expr_part__(value.__expand_complex__, negating?).each do |k, v|
field.__expr_part__(value.__expand_complex__, negating: negating?).each do |k, v|
if (existing = result[k])
if existing.is_a?(Hash)
# Existing value is an operator.
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/criteria/queryable/optional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def only(*args)
options.store(
:fields,
args.inject(options[:fields] || {}) { |sub, field| sub.tap { sub[field] = 1 } },
false
localize: false
)
end
end
Expand Down Expand Up @@ -241,7 +241,7 @@ def without(*args)
options.store(
:fields,
args.inject(options[:fields] || {}) { |sub, field| sub.tap { sub[field] = 0 } },
false
localize: false
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/mongoid/criteria/queryable/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def sort
# @param [ Object ] value The value to add.
#
# @return [ Object ] The stored object.
def store(key, value, localize = true)
super(key, evolve(value, localize))
def store(key, value, localize: true)
super(key, evolve(value, localize: localize))
end
alias_method :[]=, :store

Expand Down Expand Up @@ -103,10 +103,10 @@ def __deep_copy__
# @param [ Object ] value The value to serialize.
#
# @return [ Object ] The serialized object.
def evolve(value, localize = true)
def evolve(value, localize: true)
case value
when Hash
evolve_hash(value, localize)
evolve_hash(value, localize: localize)
else
value
end
Expand All @@ -122,7 +122,7 @@ def evolve(value, localize = true)
# @param [ Hash ] value The hash to serialize.
#
# @return [ Object ] The serialized hash.
def evolve_hash(value, localize = true)
def evolve_hash(value, localize: true)
value.each_with_object({}) do |(field, val), hash|
name, serializer = storage_pair(field)
name = localized_key(name, serializer) if localize
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/criteria/queryable/extensions/symbol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
context 'with a regexp' do

let(:specified) do
:field.__expr_part__(/test/, true)
:field.__expr_part__(/test/, negating: true)
end

it 'returns the symbol with the value negated' do
Expand All @@ -99,7 +99,7 @@
context 'with anything else' do

let(:specified) do
:field.__expr_part__('test', true)
:field.__expr_part__('test', negating: true)
end

it 'returns the symbol with the value negated' do
Expand Down