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: 4 rules found
architecture
    Impact
      Clean code attribute
        1. Direct "Thread.current" usage should be avoided in favor of safer alternatives

           Code Smell
        2. Cognitive Complexity of functions should not be too high

           Code Smell
        3. Functions should not have too many lines of code

           Code Smell
        4. Files should not have too many lines of code

           Code Smell

        Direct "Thread.current" usage should be avoided in favor of safer alternatives

        adaptability - modular
        security
        reliability
        maintainability
        Code Smell
        • threading
        • architecture
        • memory-leak

        This rule raises an issue when code directly accesses Thread.current to store or retrieve values, which can lead to testing difficulties, memory leaks, and architectural problems.

        Why is this an issue?

        How can I fix it?

        More Info

        Direct usage of Thread.current creates several problems in Ruby applications:

        Testing Difficulties

        Thread.current creates hidden dependencies that make unit testing harder. Tests become unpredictable because they depend on thread-local state that may not be properly set up or cleaned up between test runs.

        Memory Leak Risks

        In web applications using thread pools (like Puma or Unicorn), threads are reused across requests. If thread-local variables are not properly cleaned up, they can persist between requests, causing memory leaks and potential security issues where one user’s data might leak to another user’s request.

        Architectural Problems

        Using Thread.current violates the Law of Demeter and breaks MVC patterns. It creates tight coupling between different layers of the application, making code harder to understand, maintain, and refactor. Models and services become dependent on global thread state instead of explicit dependencies.

        Concurrency Issues

        Thread-local storage can mask concurrency problems and make debugging more difficult. It’s harder to reason about code behavior when state is stored in thread-local variables rather than being passed explicitly.

        What is the potential impact?

        Using Thread.current can lead to memory leaks in production environments, unpredictable test behavior, security vulnerabilities where user data leaks between requests, and code that is difficult to maintain and debug. In severe cases, it can cause application instability and data corruption.

          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