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

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

        intentionality - clear
        maintainability
        Code Smell
        • confusing

        This rule raises an issue when a module directly references a constant that is also defined in an including class, as the module’s constant will always take precedence due to lexical scoping.

        Why is this an issue?

        How can I fix it?

        More Info

        Ruby uses lexical scoping for constants, which means that when a module references a constant directly (like CONSTANT), Ruby looks for that constant in the module’s own namespace first. This happens even if the same constant is defined in a class that includes the module.

        This behavior can be surprising to developers who expect the including class’s constant to override or customize the module’s behavior. The module will always use its own constant, ignoring any constants with the same name defined in including classes.

        This can lead to:

        • Unexpected behavior where configuration constants don’t work as intended
        • Difficult-to-debug issues where changes to class constants have no effect
        • Code that appears to be customizable but actually isn’t

        The lexical scoping rule exists for good reasons in Ruby, but when you want a module to be customizable by including classes, you need to explicitly access the including class’s namespace.

        What is the potential impact?

        This issue can cause configuration problems and unexpected behavior in applications. When developers define constants in classes to customize module behavior, those constants will be silently ignored, leading to the module using default values instead of the intended customized ones. This can result in incorrect application behavior that may be 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