From a863fafae40f506c136b2eea1dbab1b220db1812 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Thu, 21 Nov 2024 16:57:59 -0500 Subject: [PATCH 1/2] Add Rubocop rule to catch .any? without block --- cop/development/none_without_block_cop.rb | 20 +++++++++++++++----- lib/graphql/dataloader/source.rb | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/cop/development/none_without_block_cop.rb b/cop/development/none_without_block_cop.rb index 71d43ed350..caff5bc916 100644 --- a/cop/development/none_without_block_cop.rb +++ b/cop/development/none_without_block_cop.rb @@ -8,12 +8,12 @@ module Development # @see https://github.com/rmosolgo/graphql-ruby/pull/2090 class NoneWithoutBlockCop < RuboCop::Cop::Cop MSG = <<-MD -Instead of `.none?` without a block: +Instead of `.none?` or `.any?` without a block: - Use `.empty?` to check for an empty collection (faster) - Add a block to explicitly check for `false` (more clear) -Run `-a` to replace this with `.empty?`. +Run `-a` to replace this with `%{bang}.empty?`. MD def on_block(node) # Since this method was called with a block, it can't be @@ -22,14 +22,24 @@ def on_block(node) end def on_send(node) - if !ignored_node?(node) && node.method_name == :none? && node.arguments.size == 0 - add_offense(node) + if !ignored_node?(node) && (node.method_name == :none? || node.method_name == :any?) && node.arguments.size == 0 + add_offense(node, message: MSG % { bang: node.method_name == :none? ? "" : "!.." } ) end end def autocorrect(node) lambda do |corrector| - corrector.replace(node.location.selector, "empty?") + if node.method_name == :none? + corrector.replace(node.location.selector, "empty?") + else + # Backtrack to any chained method calls so we can insert `!` before them + full_exp = node + while node.parent.send_type? + full_exp = node.parent + end + new_source = "!" + full_exp.source_range.source.sub("any?", "empty?") + corrector.replace(full_exp, new_source) + end end end end diff --git a/lib/graphql/dataloader/source.rb b/lib/graphql/dataloader/source.rb index 9aa3ac2d2c..46aa19e36d 100644 --- a/lib/graphql/dataloader/source.rb +++ b/lib/graphql/dataloader/source.rb @@ -73,7 +73,7 @@ def load_all(values) end } - if pending_keys.size.positive? + if !pending_keys.empty? sync(pending_keys) end From b4b4966b8106d5862ff4b4f308c6543bdd21f994 Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Tue, 26 Nov 2024 14:33:43 -0500 Subject: [PATCH 2/2] Update cops, run autocorrect --- cop/development/context_is_passed_cop.rb | 2 +- cop/development/no_focus_cop.rb | 2 +- cop/development/none_without_block_cop.rb | 2 +- lib/graphql/analysis.rb | 6 +++--- lib/graphql/analysis/visitor.rb | 2 +- lib/graphql/dataloader.rb | 10 +++++----- lib/graphql/dataloader/async_dataloader.rb | 4 ++-- lib/graphql/execution/interpreter.rb | 8 ++++---- lib/graphql/execution/interpreter/resolve.rb | 6 +++--- lib/graphql/execution/interpreter/runtime.rb | 8 ++++---- .../document_from_schema_definition.rb | 6 +++--- lib/graphql/language/printer.rb | 16 +++++++-------- lib/graphql/query.rb | 4 ++-- lib/graphql/query/context/scoped_context.rb | 2 +- .../query/variable_validation_error.rb | 2 +- lib/graphql/schema.rb | 18 ++++++++--------- lib/graphql/schema/addition.rb | 2 +- lib/graphql/schema/directive.rb | 2 +- lib/graphql/schema/directive/flagged.rb | 2 +- lib/graphql/schema/field.rb | 20 +++++++++---------- lib/graphql/schema/field_extension.rb | 2 +- .../schema/has_single_input_argument.rb | 2 +- lib/graphql/schema/interface.rb | 2 +- lib/graphql/schema/loader.rb | 2 +- lib/graphql/schema/member/has_arguments.rb | 14 ++++++------- lib/graphql/schema/member/has_directives.rb | 6 +++--- lib/graphql/schema/member/has_interfaces.rb | 8 ++++---- lib/graphql/schema/member/has_validators.rb | 2 +- lib/graphql/schema/resolver.rb | 10 +++++----- lib/graphql/schema/subscription.rb | 4 ++-- lib/graphql/schema/union.rb | 2 +- lib/graphql/schema/validator.rb | 2 +- lib/graphql/schema/visibility.rb | 12 +++++------ lib/graphql/schema/visibility/profile.rb | 2 +- lib/graphql/schema/visibility/visit.rb | 4 ++-- lib/graphql/schema/warden.rb | 8 ++++---- .../rules/argument_names_are_unique.rb | 2 +- .../fields_have_appropriate_selections.rb | 2 +- .../rules/no_definitions_are_present.rb | 2 +- .../rules/required_arguments_are_present.rb | 2 +- .../rules/unique_directives_per_location.rb | 2 +- .../rules/variable_names_are_unique.rb | 2 +- .../rules/variable_usages_are_allowed.rb | 2 +- lib/graphql/subscriptions.rb | 2 +- .../action_cable_subscriptions.rb | 2 +- lib/graphql/testing/helpers.rb | 4 ++-- spec/graphql/schema/warden_spec.rb | 2 +- spec/support/dummy_scheduler.rb | 6 +++--- 48 files changed, 118 insertions(+), 118 deletions(-) diff --git a/cop/development/context_is_passed_cop.rb b/cop/development/context_is_passed_cop.rb index 6c594c62a2..9d8049fa9c 100644 --- a/cop/development/context_is_passed_cop.rb +++ b/cop/development/context_is_passed_cop.rb @@ -3,7 +3,7 @@ module Cop module Development - class ContextIsPassedCop < RuboCop::Cop::Cop + class ContextIsPassedCop < RuboCop::Cop::Base MSG = <<-MSG This method also accepts `context` as an argument. Pass it so that the returned value will reflect the current query, or use another method that isn't context-dependent. MSG diff --git a/cop/development/no_focus_cop.rb b/cop/development/no_focus_cop.rb index e7b33566c7..8622823429 100644 --- a/cop/development/no_focus_cop.rb +++ b/cop/development/no_focus_cop.rb @@ -4,7 +4,7 @@ module Cop module Development # Make sure no tests are focused, from https://github.com/rubocop-hq/rubocop/issues/3773#issuecomment-420662102 - class NoFocusCop < RuboCop::Cop::Cop + class NoFocusCop < RuboCop::Cop::Base MSG = 'Remove `focus` from tests.' def_node_matcher :focused?, <<-MATCHER diff --git a/cop/development/none_without_block_cop.rb b/cop/development/none_without_block_cop.rb index caff5bc916..73b428c700 100644 --- a/cop/development/none_without_block_cop.rb +++ b/cop/development/none_without_block_cop.rb @@ -6,7 +6,7 @@ module Development # A custom Rubocop rule to catch uses of `.none?` without a block. # # @see https://github.com/rmosolgo/graphql-ruby/pull/2090 - class NoneWithoutBlockCop < RuboCop::Cop::Cop + class NoneWithoutBlockCop < RuboCop::Cop::Base MSG = <<-MD Instead of `.none?` or `.any?` without a block: diff --git a/lib/graphql/analysis.rb b/lib/graphql/analysis.rb index 26e4ce70ef..1d6c0df3ea 100644 --- a/lib/graphql/analysis.rb +++ b/lib/graphql/analysis.rb @@ -55,10 +55,10 @@ def analyze_query(query, analyzers, multiplex_analyzers: []) .tap { _1.select!(&:analyze?) } analyzers_to_run = query_analyzers + multiplex_analyzers - if analyzers_to_run.any? + if !analyzers_to_run.empty? analyzers_to_run.select!(&:visit?) - if analyzers_to_run.any? + if !analyzers_to_run.empty? visitor = GraphQL::Analysis::Visitor.new( query: query, analyzers: analyzers_to_run @@ -69,7 +69,7 @@ def analyze_query(query, analyzers, multiplex_analyzers: []) visitor.visit end - if visitor.rescued_errors.any? + if !visitor.rescued_errors.empty? return visitor.rescued_errors end end diff --git a/lib/graphql/analysis/visitor.rb b/lib/graphql/analysis/visitor.rb index 5ee8422450..1720d77c78 100644 --- a/lib/graphql/analysis/visitor.rb +++ b/lib/graphql/analysis/visitor.rb @@ -264,7 +264,7 @@ def leave_fragment_spread_inline(_fragment_spread) def skip?(ast_node) dir = ast_node.directives - dir.any? && !GraphQL::Execution::DirectiveChecks.include?(dir, query) + !dir.empty? && !GraphQL::Execution::DirectiveChecks.include?(dir, query) end def on_fragment_with_type(node) diff --git a/lib/graphql/dataloader.rb b/lib/graphql/dataloader.rb index b2e72d7a91..de261b4355 100644 --- a/lib/graphql/dataloader.rb +++ b/lib/graphql/dataloader.rb @@ -194,7 +194,7 @@ def run next_source_fibers = [] first_pass = true manager = spawn_fiber do - while first_pass || job_fibers.any? + while first_pass || !job_fibers.empty? first_pass = false while (f = (job_fibers.shift || (((next_job_fibers.size + job_fibers.size) < jobs_fiber_limit) && spawn_job_fiber))) @@ -207,7 +207,7 @@ def run end join_queues(job_fibers, next_job_fibers) - while (source_fibers.any? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) }) + while (!source_fibers.empty? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) }) while (f = source_fibers.shift || (((job_fibers.size + source_fibers.size + next_source_fibers.size + next_job_fibers.size) < total_fiber_limit) && spawn_source_fiber)) if f.alive? finished = run_fiber(f) @@ -227,10 +227,10 @@ def run raise "Invariant: Manager fiber didn't terminate properly." end - if job_fibers.any? + if !job_fibers.empty? raise "Invariant: job fibers should have exited but #{job_fibers.size} remained" end - if source_fibers.any? + if !source_fibers.empty? raise "Invariant: source fibers should have exited but #{source_fibers.size} remained" end rescue UncaughtThrowError => e @@ -270,7 +270,7 @@ def join_queues(prev_queue, new_queue) end def spawn_job_fiber - if @pending_jobs.any? + if !@pending_jobs.empty? spawn_fiber do while job = @pending_jobs.shift job.call diff --git a/lib/graphql/dataloader/async_dataloader.rb b/lib/graphql/dataloader/async_dataloader.rb index e8d730eb74..aa3a1de52d 100644 --- a/lib/graphql/dataloader/async_dataloader.rb +++ b/lib/graphql/dataloader/async_dataloader.rb @@ -20,7 +20,7 @@ def run first_pass = true sources_condition = Async::Condition.new manager = spawn_fiber do - while first_pass || job_fibers.any? + while first_pass || !job_fibers.empty? first_pass = false fiber_vars = get_fiber_variables @@ -37,7 +37,7 @@ def run Sync do |root_task| set_fiber_variables(fiber_vars) - while source_tasks.any? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) } + while !source_tasks.empty? || @source_cache.each_value.any? { |group_sources| group_sources.each_value.any?(&:pending?) } while (task = (source_tasks.shift || (((job_fibers.size + next_job_fibers.size + source_tasks.size + next_source_tasks.size) < total_fiber_limit) && spawn_source_task(root_task, sources_condition)))) if task.alive? root_task.yield # give the source task a chance to run diff --git a/lib/graphql/execution/interpreter.rb b/lib/graphql/execution/interpreter.rb index 8dbe6295c7..0d3c7cdb0a 100644 --- a/lib/graphql/execution/interpreter.rb +++ b/lib/graphql/execution/interpreter.rb @@ -57,7 +57,7 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl end multiplex.dataloader.append_job { operation = query.selected_operation - result = if operation.nil? || !query.valid? || query.context.errors.any? + result = if operation.nil? || !query.valid? || !query.context.errors.empty? NO_OPERATION else begin @@ -100,12 +100,12 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl # Then, find all errors and assign the result to the query object results.each_with_index do |data_result, idx| query = queries[idx] - if (events = query.context.namespace(:subscriptions)[:events]) && events.any? + if (events = query.context.namespace(:subscriptions)[:events]) && !events.empty? schema.subscriptions.write_subscription(query, events) end # Assign the result so that it can be accessed in instrumentation query.result_values = if data_result.equal?(NO_OPERATION) - if !query.valid? || query.context.errors.any? + if !query.valid? || !query.context.errors.empty? # A bit weird, but `Query#static_errors` _includes_ `query.context.errors` { "errors" => query.static_errors.map(&:to_h) } else @@ -114,7 +114,7 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl else result = {} - if query.context.errors.any? + if !query.context.errors.empty? error_result = query.context.errors.map(&:to_h) result["errors"] = error_result end diff --git a/lib/graphql/execution/interpreter/resolve.rb b/lib/graphql/execution/interpreter/resolve.rb index 92ddce0ba2..99bb674835 100644 --- a/lib/graphql/execution/interpreter/resolve.rb +++ b/lib/graphql/execution/interpreter/resolve.rb @@ -22,7 +22,7 @@ def self.resolve_each_depth(lazies_at_depth, dataloader) if smallest_depth lazies = lazies_at_depth.delete(smallest_depth) - if lazies.any? + if !lazies.empty? dataloader.append_job { lazies.each(&:value) # resolve these Lazy instances } @@ -55,7 +55,7 @@ def self.resolve(results, dataloader) # these approaches. dataloader.run next_results = [] - while results.any? + while !results.empty? result_value = results.shift if result_value.is_a?(Runtime::GraphQLResultHash) || result_value.is_a?(Hash) results.concat(result_value.values) @@ -81,7 +81,7 @@ def self.resolve(results, dataloader) end end - if next_results.any? + if !next_results.empty? # Any pending data loader jobs may populate the # resutl arrays or result hashes accumulated in # `next_results``. Run those **to completion** diff --git a/lib/graphql/execution/interpreter/runtime.rb b/lib/graphql/execution/interpreter/runtime.rb index 7c6818e6f4..ea96f71d82 100644 --- a/lib/graphql/execution/interpreter/runtime.rb +++ b/lib/graphql/execution/interpreter/runtime.rb @@ -142,7 +142,7 @@ def gather_selections(owner_object, owner_type, selections, selections_to_run = end else # This is an InlineFragment or a FragmentSpread - if @runtime_directive_names.any? && node.directives.any? { |d| @runtime_directive_names.include?(d.name) } + if !@runtime_directive_names.empty? && node.directives.any? { |d| @runtime_directive_names.include?(d.name) } next_selections = {} next_selections[:graphql_directives] = node.directives if selections_to_run @@ -332,7 +332,7 @@ def evaluate_selection_with_args(arguments, field_defn, ast_node, field_ast_node extra_args[extra] = field_defn.fetch_extra(extra, context) end end - if extra_args.any? + if !extra_args.empty? resolved_arguments = resolved_arguments.merge_extras(extra_args) end resolved_arguments.keyword_arguments @@ -361,7 +361,7 @@ def evaluate_selection_with_resolved_keyword_args(kwarg_arguments, resolved_argu end field_result = call_method_on_directives(:resolve, object, directives) do - if directives.any? + if !directives.empty? # This might be executed in a different context; reset this info runtime_state = get_current_runtime_state runtime_state.current_field = field_defn @@ -525,7 +525,7 @@ def continue_value(value, field, is_non_null, ast_node, result_name, selection_r end when Array # It's an array full of execution errors; add them all. - if value.any? && value.all?(GraphQL::ExecutionError) + if !value.empty? && value.all?(GraphQL::ExecutionError) list_type_at_all = (field && (field.type.list?)) if selection_result.nil? || !selection_result.graphql_dead value.each_with_index do |error, index| diff --git a/lib/graphql/language/document_from_schema_definition.rb b/lib/graphql/language/document_from_schema_definition.rb index ff00c71605..28d278a9f9 100644 --- a/lib/graphql/language/document_from_schema_definition.rb +++ b/lib/graphql/language/document_from_schema_definition.rb @@ -52,7 +52,7 @@ def build_schema_node def build_object_type_node(object_type) ints = @types.interfaces(object_type) - if ints.any? + if !ints.empty? ints.sort_by!(&:graphql_name) ints.map! { |iface| build_type_name_node(iface) } end @@ -247,7 +247,7 @@ def build_type_definition_node(type) end def build_argument_nodes(arguments) - if arguments.any? + if !arguments.empty? nodes = arguments.map { |arg| build_argument_node(arg) } nodes.sort_by!(&:name) nodes @@ -271,7 +271,7 @@ def build_definition_nodes all_types = @types.all_types type_nodes = build_type_definition_nodes(all_types) - if (ex_t = schema.extra_types).any? + if !(ex_t = schema.extra_types).empty? dummy_query = Class.new(GraphQL::Schema::Object) do graphql_name "DummyQuery" (all_types + ex_t).each_with_index do |type, idx| diff --git a/lib/graphql/language/printer.rb b/lib/graphql/language/printer.rb index eb8a683351..c861f33404 100644 --- a/lib/graphql/language/printer.rb +++ b/lib/graphql/language/printer.rb @@ -92,7 +92,7 @@ def print_directive(directive) print_string("@") print_string(directive.name) - if directive.arguments.any? + if !directive.arguments.empty? print_string("(") directive.arguments.each_with_index do |a, i| print_argument(a) @@ -117,7 +117,7 @@ def print_field(field, indent: "") print_string(": ") end print_string(field.name) - if field.arguments.any? + if !field.arguments.empty? print_string("(") field.arguments.each_with_index do |a, i| print_argument(a) @@ -182,7 +182,7 @@ def print_operation_definition(operation_definition, indent: "") print_string(operation_definition.name) end - if operation_definition.variables.any? + if !operation_definition.variables.empty? print_string("(") operation_definition.variables.each_with_index do |v, i| print_variable_definition(v) @@ -230,7 +230,7 @@ def print_schema_definition(schema, extension: false) extension ? print_string("extend schema") : print_string("schema") - if schema.directives.any? + if !schema.directives.empty? schema.directives.each do |dir| print_string("\n ") print_node(dir) @@ -332,7 +332,7 @@ def print_interface_type_definition(interface_type, extension: false) extension ? print_string("extend ") : print_description_and_comment(interface_type) print_string("interface ") print_string(interface_type.name) - print_implements(interface_type) if interface_type.interfaces.any? + print_implements(interface_type) if !interface_type.interfaces.empty? print_directives(interface_type.directives) print_field_definitions(interface_type.fields) end @@ -342,7 +342,7 @@ def print_union_type_definition(union_type, extension: false) print_string("union ") print_string(union_type.name) print_directives(union_type.directives) - if union_type.types.any? + if !union_type.types.empty? print_string(" = ") i = 0 union_type.types.each do |t| @@ -360,7 +360,7 @@ def print_enum_type_definition(enum_type, extension: false) print_string("enum ") print_string(enum_type.name) print_directives(enum_type.directives) - if enum_type.values.any? + if !enum_type.values.empty? print_string(" {\n") enum_type.values.each.with_index do |value, i| print_description(value, indent: " ", first_in_block: i == 0) @@ -401,7 +401,7 @@ def print_directive_definition(directive) print_string("directive @") print_string(directive.name) - if directive.arguments.any? + if !directive.arguments.empty? print_arguments(directive.arguments) end diff --git a/lib/graphql/query.rb b/lib/graphql/query.rb index 03a347b344..769ab224fb 100644 --- a/lib/graphql/query.rb +++ b/lib/graphql/query.rb @@ -133,7 +133,7 @@ def initialize(schema, query_string = nil, query: nil, document: nil, context: n end end - if context_tracers.any? && !(schema.trace_class <= GraphQL::Tracing::CallLegacyTracers) + if !context_tracers.empty? && !(schema.trace_class <= GraphQL::Tracing::CallLegacyTracers) raise ArgumentError, "context[:tracers] are not supported without `trace_with(GraphQL::Tracing::CallLegacyTracers)` in the schema configuration, please add it." end @@ -479,7 +479,7 @@ def prepare_ast @mutation = false @subscription = false operation_name_error = nil - if @operations.any? + if !@operations.empty? @selected_operation = find_operation(@operations, @operation_name) if @selected_operation.nil? operation_name_error = GraphQL::Query::OperationNameMissingError.new(@operation_name) diff --git a/lib/graphql/query/context/scoped_context.rb b/lib/graphql/query/context/scoped_context.rb index 96048b40c6..c0b3d80f5a 100644 --- a/lib/graphql/query/context/scoped_context.rb +++ b/lib/graphql/query/context/scoped_context.rb @@ -60,7 +60,7 @@ def dig(key, *other_keys) each_present_path_ctx do |path_ctx| if path_ctx.key?(key) found_value = path_ctx[key] - if other_keys.any? + if !other_keys.empty? return found_value.dig(*other_keys) else return found_value diff --git a/lib/graphql/query/variable_validation_error.rb b/lib/graphql/query/variable_validation_error.rb index b112979f55..3a934dfc16 100644 --- a/lib/graphql/query/variable_validation_error.rb +++ b/lib/graphql/query/variable_validation_error.rb @@ -10,7 +10,7 @@ def initialize(variable_ast, type, value, validation_result, msg: nil) msg ||= "Variable $#{variable_ast.name} of type #{type.to_type_signature} was provided invalid value" - if problem_fields.any? + if !problem_fields.empty? msg += " for #{problem_fields.join(", ")}" end diff --git a/lib/graphql/schema.rb b/lib/graphql/schema.rb index 55dfe0226a..e34c5af2b5 100644 --- a/lib/graphql/schema.rb +++ b/lib/graphql/schema.rb @@ -233,7 +233,7 @@ def build_trace_mode(mode) add_trace_options_for(mode, default_options) Class.new(base_class) do - mods.any? && include(*mods) + !mods.empty? && include(*mods) end end end @@ -321,7 +321,7 @@ def static_validator # @param plugin [#use] A Schema plugin # @return void def use(plugin, **kwargs) - if kwargs.any? + if !kwargs.empty? plugin.use(self, **kwargs) else plugin.use(self) @@ -691,7 +691,7 @@ def references_to(to_type = nil, from: nil) # and generally speaking, we won't inherit any values. # So optimize the most common case -- don't create a duplicate Hash. inherited_value = find_inherited_value(:references_to, EMPTY_HASH) - if inherited_value.any? + if !inherited_value.empty? inherited_value.merge(own_references_to) else own_references_to @@ -977,7 +977,7 @@ def disable_type_introspection_entry_point? # @param new_extra_types [Module] Type definitions to include in printing and introspection, even though they aren't referenced in the schema # @return [Array] Type definitions added to this schema def extra_types(*new_extra_types) - if new_extra_types.any? + if !new_extra_types.empty? new_extra_types = new_extra_types.flatten @own_extra_types ||= [] @own_extra_types.concat(new_extra_types) @@ -1002,10 +1002,10 @@ def extra_types(*new_extra_types) # @param new_orphan_types [Array>] Object types to register as implementations of interfaces in the schema. # @return [Array>] All previously-registered orphan types for this schema def orphan_types(*new_orphan_types) - if new_orphan_types.any? + if !new_orphan_types.empty? new_orphan_types = new_orphan_types.flatten non_object_types = new_orphan_types.reject { |ot| ot.is_a?(Class) && ot < GraphQL::Schema::Object } - if non_object_types.any? + if !non_object_types.empty? raise ArgumentError, <<~ERR Only object type classes should be added as `orphan_types(...)`. @@ -1022,7 +1022,7 @@ def orphan_types(*new_orphan_types) inherited_ot = find_inherited_value(:orphan_types, nil) if inherited_ot - if own_orphan_types.any? + if !own_orphan_types.empty? inherited_ot + own_orphan_types else inherited_ot @@ -1332,12 +1332,12 @@ def instrument(instrument_step, instrumenter, options = {}) # Add several directives at once # @param new_directives [Class] def directives(*new_directives) - if new_directives.any? + if !new_directives.empty? new_directives.flatten.each { |d| directive(d) } end inherited_dirs = find_inherited_value(:directives, default_directives) - if own_directives.any? + if !own_directives.empty? inherited_dirs.merge(own_directives) else inherited_dirs diff --git a/lib/graphql/schema/addition.rb b/lib/graphql/schema/addition.rb index 3a17687eee..2ffd289d42 100644 --- a/lib/graphql/schema/addition.rb +++ b/lib/graphql/schema/addition.rb @@ -40,7 +40,7 @@ def get_local_type(name) end def add_directives_from(owner) - if (dir_instances = owner.directives).any? + if !(dir_instances = owner.directives).empty? dirs = dir_instances.map(&:class) @directives.merge(dirs) add_type_and_traverse(dirs) diff --git a/lib/graphql/schema/directive.rb b/lib/graphql/schema/directive.rb index 7cd243ad50..12c5921e7f 100644 --- a/lib/graphql/schema/directive.rb +++ b/lib/graphql/schema/directive.rb @@ -29,7 +29,7 @@ def default_graphql_name end def locations(*new_locations) - if new_locations.any? + if !new_locations.empty? new_locations.each do |new_loc| if !LOCATIONS.include?(new_loc.to_sym) raise ArgumentError, "#{self} (#{self.graphql_name}) has an invalid directive location: `locations #{new_loc}` " diff --git a/lib/graphql/schema/directive/flagged.rb b/lib/graphql/schema/directive/flagged.rb index 97b72f53ba..3fe4351022 100644 --- a/lib/graphql/schema/directive/flagged.rb +++ b/lib/graphql/schema/directive/flagged.rb @@ -45,7 +45,7 @@ def self.included(schema_class) def visible?(context) if dir = self.directives.find { |d| d.is_a?(Flagged) } relevant_flags = (f = context[:flags]) && dir.arguments[:by] & f # rubocop:disable Development/ContextIsPassedCop -- definition-related - relevant_flags && relevant_flags.any? && super + relevant_flags && !relevant_flags.empty? && super else super end diff --git a/lib/graphql/schema/field.rb b/lib/graphql/schema/field.rb index bc659896bb..56ce96e271 100644 --- a/lib/graphql/schema/field.rb +++ b/lib/graphql/schema/field.rb @@ -42,8 +42,8 @@ def resolver_method end def directives - if @resolver_class && (r_dirs = @resolver_class.directives).any? - if (own_dirs = super).any? + if @resolver_class && !(r_dirs = @resolver_class.directives).empty? + if !(own_dirs = super).empty? own_dirs + r_dirs else r_dirs @@ -81,7 +81,7 @@ def introspection? end def inspect - "#<#{self.class} #{path}#{all_argument_definitions.any? ? "(...)" : ""}: #{type.to_type_signature}>" + "#<#{self.class} #{path}#{!all_argument_definitions.empty? ? "(...)" : ""}: #{type.to_type_signature}>" end alias :mutation :resolver @@ -335,15 +335,15 @@ def initialize(type: nil, name: nil, owner: nil, null: nil, description: NOT_CON @call_after_define = false set_pagination_extensions(connection_extension: connection_extension) # Do this last so we have as much context as possible when initializing them: - if extensions.any? + if !extensions.empty? self.extensions(extensions) end - if resolver_class && resolver_class.extensions.any? + if resolver_class && !resolver_class.extensions.empty? self.extensions(resolver_class.extensions) end - if directives.any? + if !directives.empty? directives.each do |(dir_class, options)| self.directive(dir_class, **options) end @@ -482,7 +482,7 @@ def extras(new_extras = nil) if new_extras.nil? # Read the value field_extras = @extras - if @resolver_class && @resolver_class.extras.any? + if @resolver_class && !@resolver_class.extras.empty? field_extras + @resolver_class.extras else field_extras @@ -732,7 +732,7 @@ def resolve(object, args, query_ctx) method_to_call = resolver_method method_receiver = obj # Call the method with kwargs, if there are any - if ruby_kwargs.any? + if !ruby_kwargs.empty? obj.public_send(resolver_method, **ruby_kwargs) else obj.public_send(resolver_method) @@ -752,7 +752,7 @@ def resolve(object, args, query_ctx) elsif inner_object.respond_to?(@method_sym) method_to_call = @method_sym method_receiver = obj.object - if ruby_kwargs.any? + if !ruby_kwargs.empty? inner_object.public_send(@method_sym, **ruby_kwargs) else inner_object.public_send(@method_sym) @@ -839,7 +839,7 @@ def assert_satisfactory_implementation(receiver, method_name, ruby_kwargs) unsatisfied_ruby_kwargs.clear end - if unsatisfied_ruby_kwargs.any? || unsatisfied_method_params.any? + if !unsatisfied_ruby_kwargs.empty? || !unsatisfied_method_params.empty? raise FieldImplementationFailed.new, <<-ERR Failed to call `#{method_name.inspect}` on #{receiver.inspect} because the Ruby method params were incompatible with the GraphQL arguments: diff --git a/lib/graphql/schema/field_extension.rb b/lib/graphql/schema/field_extension.rb index c7f75cea99..0b264af625 100644 --- a/lib/graphql/schema/field_extension.rb +++ b/lib/graphql/schema/field_extension.rb @@ -104,7 +104,7 @@ def after_define_apply end end end - if (extras = self.class.extras).any? + if !(extras = self.class.extras).empty? @added_extras = extras - field.extras field.extras(@added_extras) else diff --git a/lib/graphql/schema/has_single_input_argument.rb b/lib/graphql/schema/has_single_input_argument.rb index bf98d4d930..c58a8e94b8 100644 --- a/lib/graphql/schema/has_single_input_argument.rb +++ b/lib/graphql/schema/has_single_input_argument.rb @@ -32,7 +32,7 @@ def resolve_with_support(**inputs) input_kwargs = {} end - if input_kwargs.any? + if !input_kwargs.empty? super(**input_kwargs) else super() diff --git a/lib/graphql/schema/interface.rb b/lib/graphql/schema/interface.rb index ada8e2428d..a026c184dd 100644 --- a/lib/graphql/schema/interface.rb +++ b/lib/graphql/schema/interface.rb @@ -90,7 +90,7 @@ def included(child_class) # @param types [Class, Module] # @return [Array] Implementers of this interface, if they're registered def orphan_types(*types) - if types.any? + if !types.empty? @orphan_types ||= [] @orphan_types.concat(types) else diff --git a/lib/graphql/schema/loader.rb b/lib/graphql/schema/loader.rb index e5806a2440..228cb5161b 100644 --- a/lib/graphql/schema/loader.rb +++ b/lib/graphql/schema/loader.rb @@ -187,7 +187,7 @@ def build_fields(type_defn, fields, type_resolver) camelize: false, connection_extension: nil, ) do - if field_hash["args"].any? + if !field_hash["args"].empty? loader.build_arguments(self, field_hash["args"], type_resolver) end end diff --git a/lib/graphql/schema/member/has_arguments.rb b/lib/graphql/schema/member/has_arguments.rb index 3aa52a56ea..77c164d534 100644 --- a/lib/graphql/schema/member/has_arguments.rb +++ b/lib/graphql/schema/member/has_arguments.rb @@ -77,7 +77,7 @@ def remove_argument(arg_defn) # @return [Hash GraphQL::Schema::Argument] Arguments defined on this thing, keyed by name. Includes inherited definitions def arguments(context = GraphQL::Query::NullContext.instance, _require_defined_arguments = nil) - if own_arguments.any? + if !own_arguments.empty? own_arguments_that_apply = {} own_arguments.each do |name, args_entry| if (visible_defn = Warden.visible_entry?(:visible_argument?, args_entry, context)) @@ -90,7 +90,7 @@ def arguments(context = GraphQL::Query::NullContext.instance, _require_defined_a end def any_arguments? - own_arguments.any? + !own_arguments.empty? end module ClassConfigured @@ -104,8 +104,8 @@ def arguments(context = GraphQL::Query::NullContext.instance, require_defined_ar own_arguments = super(context, require_defined_arguments) inherited_arguments = superclass.arguments(context, false) - if own_arguments.any? - if inherited_arguments.any? + if !own_arguments.empty? + if !inherited_arguments.empty? # Local definitions override inherited ones inherited_arguments.merge(own_arguments) else @@ -153,8 +153,8 @@ def arguments(context = GraphQL::Query::NullContext.instance, _require_defined_a own_arguments = super if @resolver_class inherited_arguments = @resolver_class.field_arguments(context) - if own_arguments.any? - if inherited_arguments.any? + if !own_arguments.empty? + if !inherited_arguments.empty? inherited_arguments.merge(own_arguments) else own_arguments @@ -198,7 +198,7 @@ def all_argument_definitions end def all_argument_definitions - if own_arguments.any? + if !own_arguments.empty? all_defns = own_arguments.values all_defns.flatten! all_defns diff --git a/lib/graphql/schema/member/has_directives.rb b/lib/graphql/schema/member/has_directives.rb index ba6e1dcf4c..2081997958 100644 --- a/lib/graphql/schema/member/has_directives.rb +++ b/lib/graphql/schema/member/has_directives.rb @@ -55,14 +55,14 @@ def get_directives(schema_member, directives, directives_method) else GraphQL::EmptyObjects::EMPTY_ARRAY end - if inherited_directives.any? && directives + if !inherited_directives.empty? && directives dirs = [] merge_directives(dirs, inherited_directives) merge_directives(dirs, directives) dirs elsif directives directives - elsif inherited_directives.any? + elsif !inherited_directives.empty? inherited_directives else GraphQL::EmptyObjects::EMPTY_ARRAY @@ -71,7 +71,7 @@ def get_directives(schema_member, directives, directives_method) dirs = nil schema_member.ancestors.reverse_each do |ancestor| if ancestor.respond_to?(:own_directives) && - (anc_dirs = ancestor.own_directives).any? + !(anc_dirs = ancestor.own_directives).empty? dirs ||= [] merge_directives(dirs, anc_dirs) end diff --git a/lib/graphql/schema/member/has_interfaces.rb b/lib/graphql/schema/member/has_interfaces.rb index 1b8c9aa76a..1fcc1ee57e 100644 --- a/lib/graphql/schema/member/has_interfaces.rb +++ b/lib/graphql/schema/member/has_interfaces.rb @@ -24,7 +24,7 @@ def implements(*new_interfaces, **options) implements(next_interface) end elsif int.is_a?(String) || int.is_a?(GraphQL::Schema::LateBoundType) - if options.any? + if !options.empty? raise ArgumentError, "`implements(...)` doesn't support options with late-loaded types yet. Remove #{options} and open an issue to request this feature." end new_memberships << int @@ -73,13 +73,13 @@ module InheritedInterfaces def interfaces(context = GraphQL::Query::NullContext.instance) visible_interfaces = super inherited_interfaces = superclass.interfaces(context) - if visible_interfaces.any? - if inherited_interfaces.any? + if !visible_interfaces.empty? + if !inherited_interfaces.empty? visible_interfaces.concat(inherited_interfaces) visible_interfaces.uniq! end visible_interfaces - elsif inherited_interfaces.any? + elsif !inherited_interfaces.empty? inherited_interfaces else EmptyObjects::EMPTY_ARRAY diff --git a/lib/graphql/schema/member/has_validators.rb b/lib/graphql/schema/member/has_validators.rb index 46804a0e4b..7e877f9325 100644 --- a/lib/graphql/schema/member/has_validators.rb +++ b/lib/graphql/schema/member/has_validators.rb @@ -32,7 +32,7 @@ module ClassValidators def validators inherited_validators = superclass.validators - if inherited_validators.any? + if !inherited_validators.empty? if @own_validators.nil? inherited_validators else diff --git a/lib/graphql/schema/resolver.rb b/lib/graphql/schema/resolver.rb index 45bc3376d5..20a33d4131 100644 --- a/lib/graphql/schema/resolver.rb +++ b/lib/graphql/schema/resolver.rb @@ -67,7 +67,7 @@ def arguments # @api private def resolve_with_support(**args) # First call the ready? hook which may raise - raw_ready_val = if args.any? + raw_ready_val = if !args.empty? ready?(**args) else ready? @@ -88,7 +88,7 @@ def resolve_with_support(**args) @prepared_arguments = loaded_args Schema::Validator.validate!(self.class.validators, object, context, loaded_args, as: @field) # Then call `authorized?`, which may raise or may return a lazy object - raw_authorized_val = if loaded_args.any? + raw_authorized_val = if !loaded_args.empty? authorized?(**loaded_args) else authorized? @@ -117,7 +117,7 @@ def resolve_with_support(**args) # @api private {GraphQL::Schema::Mutation} uses this to clear the dataloader cache def call_resolve(args_hash) - if args_hash.any? + if !args_hash.empty? public_send(self.class.resolve_method, **args_hash) else public_send(self.class.resolve_method) @@ -208,7 +208,7 @@ def load_arguments(args) end # Avoid returning a lazy if none are needed - if prepare_lazies.any? + if !prepare_lazies.empty? GraphQL::Execution::Lazy.all(prepare_lazies).then { prepared_args } else prepared_args @@ -394,7 +394,7 @@ def extensions if superclass.respond_to?(:extensions) s_exts = superclass.extensions if own_exts - if s_exts.any? + if !s_exts.empty? own_exts + s_exts else own_exts diff --git a/lib/graphql/schema/subscription.rb b/lib/graphql/schema/subscription.rb index 76cec85729..702702c0bd 100644 --- a/lib/graphql/schema/subscription.rb +++ b/lib/graphql/schema/subscription.rb @@ -55,7 +55,7 @@ def resolve(**args) # Wrap the user-defined `#subscribe` hook def resolve_subscribe(**args) - ret_val = args.any? ? subscribe(**args) : subscribe + ret_val = !args.empty? ? subscribe(**args) : subscribe if ret_val == :no_response context.skip else @@ -72,7 +72,7 @@ def subscribe(args = {}) # Wrap the user-provided `#update` hook def resolve_update(**args) - ret_val = args.any? ? update(**args) : update + ret_val = !args.empty? ? update(**args) : update if ret_val == NO_UPDATE context.namespace(:subscriptions)[:no_update] = true context.skip diff --git a/lib/graphql/schema/union.rb b/lib/graphql/schema/union.rb index aaef250038..f0ad4feec7 100644 --- a/lib/graphql/schema/union.rb +++ b/lib/graphql/schema/union.rb @@ -11,7 +11,7 @@ def inherited(child_class) end def possible_types(*types, context: GraphQL::Query::NullContext.instance, **options) - if types.any? + if !types.empty? types.each do |t| assert_valid_union_member(t) type_memberships << type_membership_class.new(self, t, **options) diff --git a/lib/graphql/schema/validator.rb b/lib/graphql/schema/validator.rb index 0f1385b6de..fac5c34511 100644 --- a/lib/graphql/schema/validator.rb +++ b/lib/graphql/schema/validator.rb @@ -143,7 +143,7 @@ def self.validate!(validators, object, context, value, as: nil) end end - if all_errors.any? + if !all_errors.empty? raise ValidationFailedError.new(errors: all_errors) end nil diff --git a/lib/graphql/schema/visibility.rb b/lib/graphql/schema/visibility.rb index 9de7bc11b9..7f3c1bf08f 100644 --- a/lib/graphql/schema/visibility.rb +++ b/lib/graphql/schema/visibility.rb @@ -146,7 +146,7 @@ def migration_errors? attr_reader :cached_profiles def profile_for(context, visibility_profile) - if @profiles.any? + if !@profiles.empty? if visibility_profile.nil? if @dynamic if context.is_a?(Query::NullContext) @@ -154,7 +154,7 @@ def profile_for(context, visibility_profile) else @schema.visibility_profile_class.new(context: context, schema: @schema) end - elsif @profiles.any? + elsif !@profiles.empty? raise ArgumentError, "#{@schema} expects a visibility profile, but `visibility_profile:` wasn't passed. Provide a `visibility_profile:` value or add `dynamic: true` to your visibility configuration." end elsif !@profiles.include?(visibility_profile) @@ -230,7 +230,7 @@ def load_all(types: nil) elsif member.is_a?(GraphQL::Schema::Argument) member.validate_default_value @all_references[member.type.unwrap] << member - if (dirs = member.directives).any? + if !(dirs = member.directives).empty? dir_owner = member.owner if dir_owner.respond_to?(:owner) dir_owner = dir_owner.owner @@ -239,12 +239,12 @@ def load_all(types: nil) end elsif member.is_a?(GraphQL::Schema::Field) @all_references[member.type.unwrap] << member - if (dirs = member.directives).any? + if !(dirs = member.directives).empty? dir_owner = member.owner dirs.each { |dir| @all_references[dir.class] << dir_owner } end elsif member.is_a?(GraphQL::Schema::EnumValue) - if (dirs = member.directives).any? + if !(dirs = member.directives).empty? dir_owner = member.owner dirs.each { |dir| @all_references[dir.class] << dir_owner } end @@ -273,7 +273,7 @@ def load_all(types: nil) # only the ones that may have been modified @interface_type_memberships.each do |int_type, type_memberships| referers = @all_references[int_type].select { |r| r.is_a?(GraphQL::Schema::Field) } - if referers.any? + if !referers.empty? type_memberships.each do |type_membership| implementor_type = type_membership.object_type # Add new items only: diff --git a/lib/graphql/schema/visibility/profile.rb b/lib/graphql/schema/visibility/profile.rb index 4a093c4d21..1e6d2ae278 100644 --- a/lib/graphql/schema/visibility/profile.rb +++ b/lib/graphql/schema/visibility/profile.rb @@ -111,7 +111,7 @@ def field_on_visible_interface?(field, owner) end def type(type_name) - t = @schema.visibility.get_type(type_name) # rubocop:disable ContextIsPassedCop + t = @schema.visibility.get_type(type_name) # rubocop:disable Development/ContextIsPassedCop if t if t.is_a?(Array) vis_t = nil diff --git a/lib/graphql/schema/visibility/visit.rb b/lib/graphql/schema/visibility/visit.rb index 4b144009c0..51c3e1e8c6 100644 --- a/lib/graphql/schema/visibility/visit.rb +++ b/lib/graphql/schema/visibility/visit.rb @@ -35,7 +35,7 @@ def visit_each(types: entry_point_types, directives: entry_point_directives) @late_bound_types = [] directives_to_visit = directives - while @unvisited_types.any? || @late_bound_types.any? + while !@unvisited_types.empty? || !@late_bound_types.empty? while (type = @unvisited_types.pop) if @visited_types.add?(type) && @visit_block.call(type) directives_to_visit.concat(type.directives) @@ -156,7 +156,7 @@ def update_type_owner(owner, type) pt << owner end int.interfaces.each do |indirect_int| - if indirect_int.is_a?(LateBoundType) && (indirect_int_type = get_type(indirect_int.graphql_name)) # rubocop:disable ContextIsPassedCop + if indirect_int.is_a?(LateBoundType) && (indirect_int_type = get_type(indirect_int.graphql_name)) # rubocop:disable Development/ContextIsPassedCop update_type_owner(owner, indirect_int_type) end end diff --git a/lib/graphql/schema/warden.rb b/lib/graphql/schema/warden.rb index 57ab2e2afe..d1241eb017 100644 --- a/lib/graphql/schema/warden.rb +++ b/lib/graphql/schema/warden.rb @@ -297,7 +297,7 @@ def fields(type_defn) def arguments(argument_owner, ctx = nil) @visible_arguments ||= read_through { |o| args = o.arguments(@context) - if args.any? + if !args.empty? args = args.values args.select! { |a| visible_argument?(a, @context) } args @@ -329,7 +329,7 @@ def visible_enum_value?(enum_value, _ctx = nil) def interfaces(obj_type) @visible_interfaces ||= read_through { |t| ints = t.interfaces(@context) - if ints.any? + if !ints.empty? ints.select! { |i| visible_type?(i) } end ints @@ -389,9 +389,9 @@ def visible_and_reachable_type?(type_defn) next true if root_type?(type_defn) || type_defn.introspection? if type_defn.kind.union? - possible_types(type_defn).any? && (referenced?(type_defn) || orphan_type?(type_defn)) + !possible_types(type_defn).empty? && (referenced?(type_defn) || orphan_type?(type_defn)) elsif type_defn.kind.interface? - if possible_types(type_defn).any? + if !possible_types(type_defn).empty? true else if @context.respond_to?(:logger) && (logger = @context.logger) diff --git a/lib/graphql/static_validation/rules/argument_names_are_unique.rb b/lib/graphql/static_validation/rules/argument_names_are_unique.rb index bc8fcea305..be26bb8707 100644 --- a/lib/graphql/static_validation/rules/argument_names_are_unique.rb +++ b/lib/graphql/static_validation/rules/argument_names_are_unique.rb @@ -16,7 +16,7 @@ def on_directive(node, parent) def validate_arguments(node) argument_defns = node.arguments - if argument_defns.any? + if !argument_defns.empty? args_by_name = Hash.new { |h, k| h[k] = [] } argument_defns.each { |a| args_by_name[a.name] << a } args_by_name.each do |name, defns| diff --git a/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb b/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb index feaab2e733..c17530bc2b 100644 --- a/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb +++ b/lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb @@ -25,7 +25,7 @@ def on_operation_definition(node, _parent) def validate_field_selections(ast_node, resolved_type) msg = if resolved_type.nil? nil - elsif ast_node.selections.any? && resolved_type.kind.leaf? + elsif !ast_node.selections.empty? && resolved_type.kind.leaf? selection_strs = ast_node.selections.map do |n| case n when GraphQL::Language::Nodes::InlineFragment diff --git a/lib/graphql/static_validation/rules/no_definitions_are_present.rb b/lib/graphql/static_validation/rules/no_definitions_are_present.rb index 7debd19b55..00b68246c2 100644 --- a/lib/graphql/static_validation/rules/no_definitions_are_present.rb +++ b/lib/graphql/static_validation/rules/no_definitions_are_present.rb @@ -32,7 +32,7 @@ def on_invalid_node(node, parent) def on_document(node, parent) super - if @schema_definition_nodes.any? + if !@schema_definition_nodes.empty? add_error(GraphQL::StaticValidation::NoDefinitionsArePresentError.new(%|Query cannot contain schema definitions|, nodes: @schema_definition_nodes)) end end diff --git a/lib/graphql/static_validation/rules/required_arguments_are_present.rb b/lib/graphql/static_validation/rules/required_arguments_are_present.rb index 3140828447..81e15f2d35 100644 --- a/lib/graphql/static_validation/rules/required_arguments_are_present.rb +++ b/lib/graphql/static_validation/rules/required_arguments_are_present.rb @@ -24,7 +24,7 @@ def assert_required_args(ast_node, defn) .map!(&:name) missing_names = required_argument_names - present_argument_names - if missing_names.any? + if !missing_names.empty? add_error(GraphQL::StaticValidation::RequiredArgumentsArePresentError.new( "#{ast_node.class.name.split("::").last} '#{ast_node.name}' is missing required arguments: #{missing_names.join(", ")}", nodes: ast_node, diff --git a/lib/graphql/static_validation/rules/unique_directives_per_location.rb b/lib/graphql/static_validation/rules/unique_directives_per_location.rb index 66b0b77c86..2d043a406b 100644 --- a/lib/graphql/static_validation/rules/unique_directives_per_location.rb +++ b/lib/graphql/static_validation/rules/unique_directives_per_location.rb @@ -21,7 +21,7 @@ module UniqueDirectivesPerLocation DIRECTIVE_NODE_HOOKS.each do |method_name| define_method(method_name) do |node, parent| - if node.directives.any? + if !node.directives.empty? validate_directive_location(node) end super(node, parent) diff --git a/lib/graphql/static_validation/rules/variable_names_are_unique.rb b/lib/graphql/static_validation/rules/variable_names_are_unique.rb index 8870846771..8b1b44fb9f 100644 --- a/lib/graphql/static_validation/rules/variable_names_are_unique.rb +++ b/lib/graphql/static_validation/rules/variable_names_are_unique.rb @@ -4,7 +4,7 @@ module StaticValidation module VariableNamesAreUnique def on_operation_definition(node, parent) var_defns = node.variables - if var_defns.any? + if !var_defns.empty? vars_by_name = Hash.new { |h, k| h[k] = [] } var_defns.each { |v| vars_by_name[v.name] << v } vars_by_name.each do |name, defns| diff --git a/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb b/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb index eb8376cad5..af2343753d 100644 --- a/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb +++ b/lib/graphql/static_validation/rules/variable_usages_are_allowed.rb @@ -21,7 +21,7 @@ def on_argument(node, parent) end node_values = node_values.select { |value| value.is_a? GraphQL::Language::Nodes::VariableIdentifier } - if node_values.any? + if !node_values.empty? argument_owner = case parent when GraphQL::Language::Nodes::Field context.field_definition diff --git a/lib/graphql/subscriptions.rb b/lib/graphql/subscriptions.rb index 95ec321c16..a39d422d87 100644 --- a/lib/graphql/subscriptions.rb +++ b/lib/graphql/subscriptions.rb @@ -291,7 +291,7 @@ def normalize_arguments(event_name, arg_owner, args, context) end end - if missing_arg_names.any? + if !missing_arg_names.empty? arg_owner_name = if arg_owner.is_a?(GraphQL::Schema::Field) arg_owner.path elsif arg_owner.is_a?(Class) diff --git a/lib/graphql/subscriptions/action_cable_subscriptions.rb b/lib/graphql/subscriptions/action_cable_subscriptions.rb index 3c6a7a399d..5c01517877 100644 --- a/lib/graphql/subscriptions/action_cable_subscriptions.rb +++ b/lib/graphql/subscriptions/action_cable_subscriptions.rb @@ -171,7 +171,7 @@ def setup_stream(channel, initial_event) events_by_fingerprint = @events[topic] object = nil events_by_fingerprint.each do |_fingerprint, events| - if events.any? && events.first == initial_event + if !events.empty? && events.first == initial_event # The fingerprint has told us that this response should be shared by all subscribers, # so just run it once, then deliver the result to every subscriber first_event = events.first diff --git a/lib/graphql/testing/helpers.rb b/lib/graphql/testing/helpers.rb index 9df3c8171a..0469d566f4 100644 --- a/lib/graphql/testing/helpers.rb +++ b/lib/graphql/testing/helpers.rb @@ -58,7 +58,7 @@ def run_graphql_field(schema, field_path, object, arguments: {}, context: {}, as query_context[:current_field] = visible_field field_args = visible_field.coerce_arguments(graphql_result, arguments, query_context) field_args = schema.sync_lazy(field_args) - if visible_field.extras.any? + if !visible_field.extras.empty? extra_args = {} visible_field.extras.each do |extra| extra_args[extra] = case extra @@ -92,7 +92,7 @@ def run_graphql_field(schema, field_path, object, arguments: {}, context: {}, as end graphql_result else - unfiltered_type = schema.use_visibility_profile? ? schema.visibility.get_type(type_name) : schema.get_type(type_name) # rubocop:disable ContextIsPassedCop + unfiltered_type = schema.use_visibility_profile? ? schema.visibility.get_type(type_name) : schema.get_type(type_name) # rubocop:disable Development/ContextIsPassedCop if unfiltered_type raise TypeNotVisibleError.new(type_name: type_name) else diff --git a/spec/graphql/schema/warden_spec.rb b/spec/graphql/schema/warden_spec.rb index 961c6df149..565a8e4cd0 100644 --- a/spec/graphql/schema/warden_spec.rb +++ b/spec/graphql/schema/warden_spec.rb @@ -291,7 +291,7 @@ def self.run_query(str, **kwargs) if (except = kwargs.delete(:except)) filters[:except] = except end - if filters.any? + if !filters.empty? context = kwargs[:context] ||= {} context[:filters] = filters end diff --git a/spec/support/dummy_scheduler.rb b/spec/support/dummy_scheduler.rb index f1247f6ec2..98ef83cf82 100644 --- a/spec/support/dummy_scheduler.rb +++ b/spec/support/dummy_scheduler.rb @@ -45,7 +45,7 @@ def next_timeout def run # $stderr.puts [__method__, Fiber.current].inspect - while @readable.any? or @writable.any? or @waiting.any? or @blocking.positive? + while !@readable.empty? or !@writable.empty? or !@waiting.empty? or @blocking.positive? # Can only handle file descriptors up to 1024... readable, writable = IO.select(@readable.keys + [@urgent.first], @writable.keys, [], next_timeout) @@ -72,7 +72,7 @@ def run fiber.resume(events) end - if @waiting.any? + if !@waiting.empty? time = current_time waiting, @waiting = @waiting, {} @@ -87,7 +87,7 @@ def run end end - if @ready.any? + if !@ready.empty? ready = nil @lock.synchronize do