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: 12 rules found
rails
    Impact
      Clean code attribute
        1. Private methods should be declared at the end of Ruby classes

           Code Smell
        2. Controllers should inherit from appropriate base classes

           Code Smell
        3. Rails model callback methods should be private

           Code Smell
        4. Rails collections should use "ids" instead of "pluck(:id)" for primary keys

           Code Smell
        5. Rails queries should use "find_by" instead of "where.take" for single record retrieval

           Code Smell
        6. HTTP status codes should use symbols instead of numeric values

           Code Smell
        7. Before destroy callbacks should use proper halt mechanism

           Bug
        8. Rails applications should define a root route with proper controller#action syntax

           Bug
        9. Rails API controllers using "respond_to" should include "ActionController::MimeResponds"

           Bug
        10. Asset compilation should be disabled in production environments

           Code Smell
        11. Global variables should not be used in Rails applications

           Code Smell
        12. ActiveRecord models should override "as_json" instead of "to_json" for custom JSON serialization

           Bug

        Private methods should be declared at the end of Ruby classes

        consistency - conventional
        maintainability
        Code Smell
        • convention
        • ruby
        • rails

        This rule raises an issue when the private keyword is used before public method definitions in a Ruby class, or when private methods are scattered throughout the class instead of being grouped at the end.

        Why is this an issue?

        How can I fix it?

        More Info

        In Ruby, the private keyword affects all methods defined after it within the same class. This behavior is different from many other programming languages where visibility is declared per method.

        When private is placed in the middle of a class definition, any methods defined after it become private, even if they were intended to be public. This can lead to several problems:

        • Runtime errors: In Rails applications, controller actions that accidentally become private will not be accessible via HTTP routes, causing AbstractController::ActionNotFound errors.
        • Broken public APIs: Methods that should be part of the class’s public interface become inaccessible to other parts of the application.
        • Debugging difficulties: The error messages may not clearly indicate that the issue is related to method visibility.

        The Ruby community convention is to place all private methods at the bottom of the class definition under a single private declaration. This creates a clear separation between the public interface (what the class exposes to other code) and the implementation details (private helper methods).

        What is the potential impact?

        When public methods are accidentally made private, it can cause runtime failures in production applications. In Rails controllers, this typically results in routing errors where users receive 404 or 500 errors when trying to access pages. The impact can be severe if critical functionality becomes inaccessible, and debugging can be time-consuming since the error may not clearly indicate the root cause is method visibility.

          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