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

IrreversibleMigration: Ignore methods that are part of another method call #49

Merged
merged 3 commits into from
Dec 10, 2024

Conversation

AlasdairWallaceMackie
Copy link
Contributor

@AlasdairWallaceMackie AlasdairWallaceMackie commented Dec 10, 2024

Reason for change

Resolves issue #48

Consider the following migration:

Sequel.migration do
  change do
    alter_table(:stores) do
      add_column(:products, JSON, null: false, default: Sequel.pg_json({}))
      add_constraint(
        :only_one_user,
        (
          Sequel.cast(Sequel.~(user_id: nil), Integer) +
          Sequel.cast(Sequel.~(owner_id: nil), Integer)
        ) => 1,
      )
    end
  end
end

In the current state, the following offenses would be registered:

Sequel/IrreversibleMigration: Avoid using "pg_json" inside a "change" block. Use "up" & "down" blocks instead.
Sequel/IrreversibleMigration: Avoid using "+" inside a "change" block. Use "up" & "down" blocks instead.
Sequel/IrreversibleMigration: Avoid using "cast" inside a "change" block. Use "up" & "down" blocks instead.
Sequel/IrreversibleMigration: Avoid using "~" inside a "change" block. Use "up" & "down" blocks instead.
Sequel/IrreversibleMigration: Avoid using "cast" inside a "change" block. Use "up" & "down" blocks instead.
Sequel/IrreversibleMigration: Avoid using "~" inside a "change" block. Use "up" & "down" blocks instead.

Methods that are part of another method argument can be safely ignored, because an offense will still be registered if the parent method is invalid within a change block

@cyberdelia cyberdelia merged commit 07b54ca into rubocop:master Dec 10, 2024
5 checks passed
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