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/MigrationClassName ignores acronyms (inflection rules) #664

Closed
jalyna opened this issue Mar 16, 2022 · 0 comments · Fixed by #665
Closed

Rails/MigrationClassName ignores acronyms (inflection rules) #664

jalyna opened this issue Mar 16, 2022 · 0 comments · Fixed by #665
Labels
enhancement New feature or request

Comments

@jalyna
Copy link

jalyna commented Mar 16, 2022

When using inflections, like:

# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym "OAuth"
end

this results in failures for past migrations that include the acronym OAuth in their class name like class RemoveUnusedOAuthScopeGrants.


Expected behavior

No cop should be raised.

Actual behavior

db/migrate/20210623095243_remove_unused_oauth_scope_grants.rb:1:7: C: [Correctable] Rails/MigrationClassName: Replace with RemoveUnusedOauthScopeGrants that matches the file name.
class RemoveUnusedOAuthScopeGrants < ActiveRecord::Migration[6.1]

Steps to reproduce the problem

Add

# config/initializers/inflections.rb
ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.acronym "OAuth"
end

Create a migration that includes OAuth acronym in its class name

RuboCop version

1.26.0 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 3.1.1 x86_64-darwin20)
  - rubocop-performance 1.13.3
  - rubocop-rails 2.14.1
@koic koic added the enhancement New feature or request label Mar 16, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Mar 16, 2022
… cop

Fixes rubocop#664.

This PR fixes a false positive for `Rails/MigrationClassName` when
`ActiveSupport::Inflector` is applied to the class name and the case
is different.

Occasionally user want to treat a word like `Oauth` as` OAuth`.
This PR is case insensitive for comparisons between migration class name
and filename. It's may not a big deal because it's based on filename.
@koic koic closed this as completed in #665 Mar 16, 2022
koic added a commit that referenced this issue Mar 16, 2022
…ation_class_name_cop

[Fix #664] Fix a false positive for `Rails/MigrationClassName` cop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants