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: 1 rule found
ruby-style
    Impact
      Clean code attribute
        1. Require statements should be placed at the top of files

           Code Smell

        Require statements should be placed at the top of files

        consistency - conventional
        maintainability
        Code Smell
        • convention
        • readability
        • ruby-style

        This rule raises an issue when require statements are placed inside methods, classes, or other code blocks instead of at the top level of the file.

        Why is this an issue?

        How can I fix it?

        More Info

        When require statements are scattered throughout your code, it becomes difficult to understand what dependencies a file needs at a glance. This creates several problems:

        First, it hurts readability. Other developers (including your future self) have to scan through the entire file to understand what libraries and modules are being used. This makes code review and maintenance more time-consuming.

        Second, it can lead to performance issues. Ruby’s require method loads and executes files, which takes time. When requires are placed inside methods that might be called multiple times, you risk loading the same library repeatedly, even though Ruby’s require mechanism prevents duplicate loading.

        Third, it makes dependency management harder. Build tools, bundlers, and static analysis tools often look for require statements at the top of files to understand project dependencies. Scattered requires can be missed by these tools.

        Finally, it goes against Ruby community conventions. The Ruby style guide and most Ruby projects follow the practice of placing all requires at the top of files, making your code inconsistent with established patterns.

        What is the potential impact?

        Scattered require statements reduce code maintainability and readability. They make it harder for developers to understand file dependencies, can impact performance when requires are placed in frequently-called methods, and may cause issues with dependency analysis tools.

          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