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
subprocess
    Impact
      Clean code attribute
        1. Use "Dir.chdir" instead of system calls for directory changes

           Code Smell

        Use "Dir.chdir" instead of system calls for directory changes

        intentionality - clear
        reliability
        maintainability
        Code Smell
        • ruby
        • filesystem
        • subprocess

        This rule raises an issue when using system calls like system "cd directory" to change the working directory.

        Why is this an issue?

        How can I fix it?

        More Info

        Directory changes made through system calls like system "cd directory" do not affect the current Ruby process. Each system call runs in a separate subprocess with its own environment. When the subprocess exits, any directory changes are lost, and the parent Ruby process remains in its original directory.

        This leads to unexpected behavior where subsequent system calls or file operations don’t run in the intended directory. For example, if you run system "cd my_app" followed by system "rails server", the Rails server will start in the original directory, not in the my_app directory.

        Ruby provides the Dir.chdir method specifically for changing the working directory within the current process. This method actually changes the directory for the Ruby process itself, making it the correct approach for directory navigation in Ruby scripts.

        What is the potential impact?

        Using system calls for directory changes can cause scripts to fail silently or behave unexpectedly. Commands may run in the wrong directory, leading to file not found errors, incorrect file operations, or applications starting in unexpected locations. This can result in deployment failures, data corruption, or security issues if files are created or modified in unintended directories.

          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