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
  • GroovyGroovy
  • 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 76
  • Bug17
  • Security Hotspot2
  • Code Smell57
Filtered: 2 rules found
runtime-error
    Impact
      Clean code attribute
        1. Rails API controllers using "respond_to" should include "ActionController::MimeResponds"

           Bug
        2. Variables and methods should be accessible in their usage context

           Bug

        Variables and methods should be accessible in their usage context

        intentionality - logical
        reliability
        maintainability
        Bug
        • scoping
        • runtime-error

        This rule raises an issue when code references local variables or methods that are undefined or inaccessible due to Ruby’s scoping rules.

        Why is this an issue?

        How can I fix it?

        More Info

        Ruby has strict scoping rules that determine where variables and methods can be accessed. Local variables are only accessible within the scope where they are defined, and method definitions create new scopes.

        When code attempts to reference a local variable that doesn’t exist in the current scope, Ruby will raise a NameError at runtime. This commonly happens in two scenarios:

        Local variables assigned in one method but referenced in another: In Ruby, local variables are scoped to the method where they are defined. Assigning current_user = user inside a method creates a local variable that cannot be accessed from other methods.

        Local variables referenced across scope boundaries: Method definitions create new scopes, so local variables defined outside a method are not accessible within that method. This is different from some other languages where inner scopes can access outer scope variables.

        Ruby’s method call syntax can make this confusing because method calls don’t require parentheses. When Ruby encounters an undefined identifier, it first checks for local variables, then looks for method calls. If neither exists, it raises a NameError.

        These scoping violations indicate a misunderstanding of Ruby’s variable accessibility rules and often suggest that the code needs to be restructured to use appropriate mechanisms for sharing data between different parts of the program.

        What is the potential impact?

        This issue will cause NameError exceptions at runtime, leading to application crashes. The error may not be discovered until the specific code path is executed, potentially causing failures in production environments. This can result in poor user experience and system reliability issues.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use