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

Fix errors that occur when unrelated tag is investigated by Rails/ContentTag #813

Merged
merged 1 commit into from
Oct 13, 2022

Conversation

r7kamura
Copy link
Contributor

@r7kamura r7kamura commented Oct 12, 2022

I encountered a strange error when running rubocop-rails on our Rails app that uses FactoryBot.

The file that caused the problem was, in simplified form, the following code:

FactoryBot.define do
  factory :article do
    tag factory: :article_tag
  end
end

and the error output was like this:

$ bundle exec rubocop spec/factories/articles.rb 
Inspecting 1 file
An error occurred while Rails/ContentTag cop was inspecting /workspace/spec/factories/articles.rb:3:4.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/ContentTag cop was inspecting /workspace/spec/factories/articles.rb:3:4.
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.36.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 2.7.2) [x86_64-linux]

This Pull Request has been created to fix this problem.

We could add {spec,test}/factories/**/*.rb to Exclude section of this cop, but that would not prevent the problem from reoccuring in other places. Since extensive investigation is performed on the generic method name tag, I think it should be checked more rigorously in this way.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@koic
Copy link
Member

koic commented Oct 12, 2022

Nice! Can you add a changelog entry?

@r7kamura r7kamura force-pushed the feature/content-tag-fix branch from f34bc2b to d2f63de Compare October 12, 2022 23:50
@koic koic merged commit dd60ff4 into rubocop:master Oct 13, 2022
@r7kamura r7kamura deleted the feature/content-tag-fix branch October 21, 2022 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants