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
confusing
    Impact
      Clean code attribute
        1. Non-mutating sort methods should have their return values used

           Bug
        2. "return" statements should not be used in blocks

           Bug
        3. "unless" statements should be used appropriately to avoid confusing logic

           Code Smell
        4. Symbol keys containing hyphens should be quoted

           Bug
        5. Constants in modules should use explicit class scoping when they may be overridden by including classes

           Code Smell
        6. Methods should not have identical implementations

           Code Smell
        7. Redundant pairs of parentheses should be removed

           Code Smell

        "return" statements should not be used in blocks

        intentionality - logical
        reliability
        Bug
        • confusing

        This rule raises an issue when a return statement is used inside a block (created with {} or do…​end).

        Why is this an issue?

        How can I fix it?

        More Info

        In Ruby, blocks are closures that capture the lexical environment where they are defined. When you use return inside a block, it doesn’t return from the block itself - it returns from the method that lexically contains the block definition.

        This behavior can lead to two main problems:

        • LocalJumpError at runtime: If the block is called outside the context of its defining method, Ruby raises a LocalJumpError because there’s no method to return from.
        • Unexpected early method returns: When the block is executed within its defining method, the return statement causes the entire method to exit immediately, potentially skipping important cleanup code or logic.

        This confusion often arises because developers expect blocks to behave like methods, but blocks are actually more like anonymous functions that share the same scope as their surrounding method.

        The distinction becomes clearer when you understand that Ruby has different types of callable objects:

        • Blocks: Created with {} or do…​end, they share scope with the surrounding method
        • Procs: Objects created from blocks, they retain the same return behavior as blocks
        • Lambdas: Special procs that have their own scope and handle return statements locally

        What is the potential impact?

        Using return in blocks can cause applications to crash with LocalJumpError exceptions at runtime, making the code unreliable. It can also lead to subtle bugs where methods exit unexpectedly, bypassing important logic, cleanup operations, or error handling code. This makes the application’s behavior unpredictable and difficult to debug.

          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