SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Ruby

Ruby static code analysis

Unique rules to find Bugs, Security Hotspots, and Code Smells in your RUBY code

  • All rules 75
  • Bug17
  • Security Hotspot2
  • Code Smell56
Filtered: 1 rule found
encapsulation
    Impact
      Clean code attribute
        1. Rails model callback methods should be private

           Code Smell

        Rails model callback methods should be private

        adaptability - modular
        maintainability
        Code Smell
        • rails
        • convention
        • encapsulation

        This rule raises an issue when a method used as a Rails model callback (such as before_save, after_create, after_update, etc.) is declared as a public method instead of private.

        Why is this an issue?

        How can I fix it?

        More Info

        In Rails applications, callback methods are internal implementation details that should not be part of a model’s public interface. When callback methods are declared as public, they can be called directly from outside the model, which violates the principle of encapsulation and can lead to several problems.

        Callback methods are designed to be invoked automatically by the Rails framework at specific points in an object’s lifecycle. They often contain logic that assumes certain preconditions or state changes that only occur during the normal Rails callback chain. When these methods are called directly, they may not work as expected or could cause data inconsistency.

        Additionally, public callback methods expose internal implementation details that other parts of the application might inadvertently depend on. This creates tight coupling and makes the code harder to refactor or maintain over time.

        Following the Rails convention of making callback methods private also improves code readability by clearly distinguishing between the model’s public API and its internal implementation details.

        What is the potential impact?

        When callback methods are public, they can be called directly from outside the model, potentially bypassing important validation or state management logic. This can lead to data inconsistency, unexpected behavior, or security vulnerabilities if the callback methods contain sensitive operations that should only be triggered through the normal Rails lifecycle.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use