Skip to content

Add new Rails/SkipsModelCallbacks cop for detecting methods that skip callbacks #1581

Description

@Yuhi-Sato

Is your feature request related to a problem? Please describe.

The Rails/SkipsModelValidations cop currently only mentions "validations" in its name, message, and documentation. However, the methods detected by this cop (such as update_column, update_all, touch, increment!, etc.) actually skip both validations and callbacks.

According to the official Rails guide on callbacks, these methods bypass callbacks.

Since skipping callbacks can have significant consequences, users should be made aware that callbacks are also skipped.

Describe the solution you'd like

Create a new separate cop Rails/SkipsModelCallbacks:

  • Keep Rails/SkipsModelValidations for validation-focused warnings
  • Create a new Rails/SkipsModelCallbacks cop specifically for callback-skipping warnings
  • This provides more granular control, allowing users to enable/disable each concern independently
  • Both cops would detect the same methods but with different messages and purposes

I would be happy to submit a PR for this if the approach is acceptable.

Describe alternatives you've considered

Alternative 1: Update documentation and message only (minimal change)

  • Add "and callbacks" to the existing SkipsModelValidations message and documentation
  • Simple but lacks granular control

Alternative 2: Rename the cop (breaking change)

  • Rename to something like Rails/SkipsModelValidationsAndCallbacks or Rails/SkipsActiveRecordFeatures
    This would be a breaking change.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions