Skip to content
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

Rails/ContentTag should not capture #tag calls that's not the ActionView::Helpers::TagHelper#tag #543

Closed
FunnyHector opened this issue Sep 12, 2021 · 0 comments · Fixed by #544
Labels
bug Something isn't working

Comments

@FunnyHector
Copy link
Contributor

Expected behavior

Rails/ContentTag should not capture #tag calls that's not the ActionView::Helpers::TagHelper#tag

Actual behavior

It does

Steps to reproduce the problem

I have this code that tags intercom users, intercom.tags.tag(foo: 'foo, bar: 'bar'). The method comes from Intercom gem (https://github.com/intercom/intercom-ruby#tags), not ActionView::Helpers::TagHelper#tag. This code is inspected by this cop and error is raised:

An error occurred while Rails/ContentTag cop was inspecting /Users/***/hatch_repos/harvest/app/workers/intercom/hatch/tag_users.rb:11:10.
undefined method `value' for #<RuboCop::AST::HashNode:0x0000000145c88e80>
Did you mean?  values
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.12.2/lib/rubocop/cop/rails/content_tag.rb:41:in `on_send'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:158:in `on_block'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_block'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:154:in `on_def'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:154:in `on_class'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:138:in `on_while'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:138:in `on_while'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.11.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:310:in `inspect_file'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:281:in `loop'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:67:in `block in warm_cache'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:509:in `call_with_index'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:477:in `process_incoming_jobs'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:459:in `block in worker'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:450:in `fork'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:450:in `worker'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:441:in `block in create_workers'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:440:in `each'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:440:in `each_with_index'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:440:in `create_workers'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:380:in `work_in_processes'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:283:in `map'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/parallel-1.20.1/lib/parallel.rb:232:in `each'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:67:in `warm_cache'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/runner.rb:46:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:71:in `run_command'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:78:in `execute_runners'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/lib/rubocop/cli.rb:47:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/exe/rubocop:12:in `block in <top (required)>'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/benchmark-0.1.1/lib/benchmark.rb:308:in `realtime'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/rubocop-1.20.0/exe/rubocop:12:in `<top (required)>'
/Users/***/.rbenv/versions/2.7.4/bin/rubocop:23:in `load'
/Users/***/.rbenv/versions/2.7.4/bin/rubocop:23:in `<top (required)>'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli/exec.rb:58:in `load'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli/exec.rb:58:in `kernel_load'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli/exec.rb:23:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli.rb:477:in `exec'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli.rb:31:in `dispatch'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/cli.rb:25:in `start'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/exe/bundle:49:in `block in <top (required)>'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/Users/***/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/bundler-2.2.26/exe/bundle:37:in `<top (required)>'
/Users/***/.rbenv/versions/2.7.4/bin/bundle:23:in `load'
/Users/***/.rbenv/versions/2.7.4/bin/bundle:23:in `<main>'

RuboCop version

$ [bundle exec] rubocop -V
1.20.0 (using Parser 3.0.2.0, rubocop-ast 1.11.0, running on ruby 2.7.4 arm64-darwin20)
  - rubocop-performance 1.11.5
  - rubocop-rails 2.12.2
koic added a commit to koic/rubocop-rails that referenced this issue Sep 13, 2021
Fixes rubocop#543.

This PR fixes an error for `Rails/ContentTag` when `tag` is not a top-level method.
@koic koic added the bug Something isn't working label Sep 13, 2021
@koic koic closed this as completed in #544 Sep 14, 2021
koic added a commit that referenced this issue Sep 14, 2021
[Fix #543] Fix an error for `Rails/ContentTag`
gravitystorm added a commit to gravitystorm/openstreetmap-website that referenced this issue Sep 15, 2021
There is a bug in the Rails/ContentTag cop that causes rubocop to crash. The bug has already been fixed and so should be available in the next release.

See rubocop/rubocop-rails#543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants