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

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

        intentionality - clear
        maintainability
        Code Smell
        • ruby
        • idiom

        This rule raises an issue when each is used with break or return statements for searching, existence checking, or membership testing.

        Why is this an issue?

        How can I fix it?

        More Info

        Using each with break or return statements is a common anti-pattern in Ruby that makes code less readable and less idiomatic.

        When you use each with break or return, you’re essentially implementing search or filtering logic manually. This approach has several problems:

        • Intent is unclear: Other developers need to read through the entire loop to understand what the code is trying to accomplish
        • More verbose: The code requires additional variables and control flow statements
        • Less idiomatic: Ruby provides specific enumerable methods designed for these exact use cases
        • Harder to maintain: Manual loop control is more error-prone than using built-in methods

        Ruby’s enumerable methods are designed to express intent clearly. When you see find, you immediately know the code is searching for an element. When you see any?, you know it’s checking for existence. This makes code self-documenting and easier to understand at a glance.

        What is the potential impact?

        This issue primarily affects code maintainability and readability. While the functional behavior remains the same, unclear intent can lead to:

        • Increased time spent understanding code during maintenance
        • Higher likelihood of introducing bugs when modifying the logic
        • Reduced code quality and team productivity
        • Difficulty for new team members to understand the codebase
          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