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

           Code Smell
        2. Safe navigation operator should be preferred over ActiveSupport's "try!"

           Code Smell
        3. Regular expressions should not be passed to "String#include?"

           Bug
        4. Enumerable methods should be used instead of "each" with "break" or "return"

           Code Smell
        5. Exception classes should be used instead of raising generic strings

           Code Smell
        6. Use "Dir.chdir" instead of system calls for directory changes

           Code Smell
        7. Explicit RuntimeErrors should be omitted in raise statements

           Code Smell

        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

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use