Rubocop errors on GraphQL/FieldTypeInBlock for module type interfaces
lasseebert opened this issue ยท 4 comments
Thank you very much for the previous two fixes of the rubocop cop ๐ ๐ฏ
Describe the bug
Rubocop throws errors on type interfaces (which are modules) for GraphQL/FieldTypeInBlock
Versions
graphql
version: Current master (also in 2.3.16
)
rails
: 7.2.1
GraphQL schema
module Types::FooType
include GraphQL::Schema::Interface
field :bar, Thing
end
Steps to reproduce
Run rubocop on the above file
Expected behavior
No exception thrown.
Actual behavior
Exception is thrown (see full stacktrace below)
$ bin/rubocop app/graphql/types/foo_type.rb
Inspecting 1 file
.
1 file inspected, no offenses detected
An error occurred while GraphQL/FieldTypeInBlock cop was inspecting /home/me/code/myapp/apps/api/app/graphql/types/foo_type.rb:7:2.
To see the complete backtrace run rubocop -d.
1 error occurred:
An error occurred while GraphQL/FieldTypeInBlock cop was inspecting /home/me/code/myapp/apps/api/app/graphql/types/foo_type.rb:7:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.66.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.5) +server [x86_64-linux]
Click to view exception backtrace
$ bin/rubocop app/graphql/types/foo_type.rb -d
For /home/me/code/myapp/apps/api: configuration from /home/me/code/myapp/apps/api/.rubocop.yml
Inheriting configuration from /home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/test-prof-1.4.2/config/rubocop-rspec.yml
Inheriting configuration from /home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/syntax_tree-6.1.1/config/rubocop.yml
Inheriting configuration from /home/me/code/myapp/apps/api/.rubocop_backlog.yml
Inheriting configuration from /home/me/code/myapp/apps/api/.rubocop_todo.yml
.rubocop.yml: Metrics/PerceivedComplexity:Exclude overrides the same parameter in .rubocop_backlog.yml
Inspecting 1 file
Scanning /home/me/code/myapp/apps/api/app/graphql/types/foo_type.rb
Invariant: Something went wrong in GraphQL-Ruby, couldn't find surrounding class definition for field ((send nil :field
(sym :bar)
(const nil :Thing))).
Please report this error on GitHub.
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/graphql-ruby-32e166297fcc/lib/graphql/rubocop/graphql/field_type_in_block.rb:126:in `determine_field_indent'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/graphql-ruby-32e166297fcc/lib/graphql/rubocop/graphql/field_type_in_block.rb:65:in `block (2 levels) in on_send'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/base.rb:416:in `correct'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/base.rb:210:in `add_offense'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/graphql-ruby-32e166297fcc/lib/graphql/rubocop/graphql/field_type_in_block.rb:63:in `block in on_send'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/graphql-ruby-32e166297fcc/lib/graphql/rubocop/graphql/field_type_in_block.rb:33:in `field_config_with_inline_type'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/bundler/gems/graphql-ruby-32e166297fcc/lib/graphql/rubocop/graphql/field_type_in_block.rb:58:in `on_send'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:107:in `public_send'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:107:in `block (2 levels) in trigger_responding_cops'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:171:in `with_cop_error_handling'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:106:in `block in trigger_responding_cops'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:105:in `each'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:105:in `trigger_responding_cops'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:69:in `on_send'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:137:in `each'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:138:in `on_while'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-ast-1.32.3/lib/rubocop/ast/traversal.rb:20:in `walk'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/commissioner.rb:87:in `investigate'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/team.rb:168:in `investigate_partial'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cop/team.rb:102:in `investigate'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:349:in `block in inspect_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `each'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `flat_map'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:348:in `inspect_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:291:in `block in do_inspection_loop'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:325:in `block in iterate_until_no_changes'
<internal:kernel>:187:in `loop'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:318:in `iterate_until_no_changes'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:287:in `do_inspection_loop'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:168:in `block in file_offenses'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:193:in `file_offense_cache'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:167:in `file_offenses'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:158:in `process_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:139:in `block in each_inspected_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `each'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `reduce'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:138:in `each_inspected_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:124:in `inspect_files'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/runner.rb:77:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/command.rb:11:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli/environment.rb:18:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli.rb:122:in `run_command'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli.rb:129:in `execute_runners'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli.rb:51:in `block in run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli.rb:81:in `profile_if_needed'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/cli.rb:43:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/server_command/exec.rb:22:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/server_command/base.rb:24:in `block in run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/server_command/base.rb:23:in `chdir'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/server_command/base.rb:23:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/socket_reader.rb:33:in `block in read!'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/helper.rb:26:in `redirect'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/socket_reader.rb:28:in `read!'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:90:in `read_socket'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:65:in `block in process_input'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/cache.rb:150:in `write_pid_file'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:64:in `process_input'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:53:in `block in detach_server'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:46:in `fork'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:46:in `detach_server'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/core.rb:38:in `start'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/client_command/start.rb:42:in `block in run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/cache.rb:137:in `acquire_lock'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/client_command/start.rb:29:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/client_command/exec.rb:40:in `ensure_server!'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/lib/rubocop/server/client_command/exec.rb:19:in `run'
/home/me/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/rubocop-1.66.1/exe/rubocop:12:in `<top (required)>'
/home/me/code/myapp/apps/api/bin/rubocop:31:in `load'
/home/me/code/myapp/apps/api/bin/rubocop:31:in `<main>'
.
1 file inspected, no offenses detected
configuration from /home/me/code/myapp/apps/api/.rubocop.yml
An error occurred while GraphQL/FieldTypeInBlock cop was inspecting /home/me/code/myapp/apps/api/app/graphql/types/foo_type.rb:7:2.
1 error occurred:
An error occurred while GraphQL/FieldTypeInBlock cop was inspecting /home/me/code/myapp/apps/api/app/graphql/types/foo_type.rb:7:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.66.1 (using Parser 3.3.5.0, rubocop-ast 1.32.3, running on ruby 3.3.5) +server [x86_64-linux]
Likewise, thanks for your patience reporting these issues! I've got a fix worked up at #5112.
By the way, how did you find this cop? (Soon, I'm going to document it and recommend it as a way to speed up application boot in development, but I haven't yet...)
Thanks, I will test in my repo asap ๐
In my project, all cops are enabled by default, and we disable cops as needed, so that's how I discovered it ๐
Yay, I have no more rubocop exceptions in our code base! ๐ ๐ฏ
๐ Thanks again for working with me on these!