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: 2 rules found
performance
    Impact
      Clean code attribute
        1. Safe navigation operator should be preferred over ActiveSupport's "try!"

           Code Smell
        2. Asset compilation should be disabled in production environments

           Code Smell

        Safe navigation operator should be preferred over ActiveSupport's "try!"

        consistency - conventional
        maintainability
        Code Smell
        • performance
        • convention
        • ruby

        This rule raises an issue when ActiveSupport’s try! method is used instead of Ruby’s native safe navigation operator &..

        Why is this an issue?

        How can I fix it?

        More Info

        Ruby 2.3 introduced the safe navigation operator (&.) as a native language feature that provides the same functionality as ActiveSupport’s try! method but with better performance characteristics.

        The safe navigation operator is part of Ruby’s core language, which means:

        • Better performance: Native language features are typically faster than library-based implementations
        • Reduced dependencies: Using built-in language features reduces reliance on external libraries
        • Improved readability: The &. syntax is more concise and widely recognized by Ruby developers
        • Future compatibility: Native language features are more stable and less likely to change compared to library methods

        ActiveSupport’s try! method was useful before Ruby 2.3, but now that the safe navigation operator is available, it’s the preferred approach for safe method chaining.

        What is the potential impact?

        Using try! instead of the safe navigation operator can lead to:

        • Performance degradation: Method-based approaches are slower than native language operators
        • Unnecessary complexity: Additional dependency on ActiveSupport when native Ruby features suffice
        • Maintenance overhead: Code that relies on library methods when language features are available
          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