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
 
Tags
    Impact
      Clean code attribute
        1. Before destroy callbacks should use proper halt mechanism

           Bug
        2. Rails applications should define a root route with proper controller#action syntax

           Bug
        3. Non-mutating sort methods should have their return values used

           Bug
        4. "return" statements should not be used in blocks

           Bug
        5. Rails API controllers using "respond_to" should include "ActionController::MimeResponds"

           Bug
        6. Environment variables should be validated or have default values

           Bug
        7. Regular expressions should not be passed to "String#include?"

           Bug
        8. Symbol keys containing hyphens should be quoted

           Bug
        9. Column names should not use SQL reserved words

           Bug
        10. ActiveRecord models should override "as_json" instead of "to_json" for custom JSON serialization

           Bug
        11. All branches in a conditional structure should not have exactly the same implementation

           Bug
        12. Non-existent operators like "=+" should not be used

           Bug
        13. Related "if/elsif" statements and "when" in a "case" should not have the same condition

           Bug
        14. Identical expressions should not be used on both sides of a binary operator

           Bug
        15. All code should be reachable

           Bug
        16. Variables should not be self-assigned

           Bug
        17. Useless "if true ..." and "if false ..." blocks should be removed

           Bug

        Regular expressions should not be passed to "String#include?"

        intentionality - logical
        reliability
        maintainability
        Bug
        • ruby
        • regex

        This rule raises an issue when the include? method is called with a regular expression argument instead of a string.

        Why is this an issue?

        How can I fix it?

        More Info

        The include? method in Ruby only accepts string arguments. When you pass a regular expression to include?, Ruby raises a TypeError with the message "can’t convert regexp to string".

        This error occurs at runtime and will cause your application to crash. The include? method is designed to check if a string contains another string as a substring, not to perform pattern matching.

        For pattern matching with regular expressions, Ruby provides several dedicated methods that are designed for this purpose and handle regex objects correctly.

        What is the potential impact?

        This issue causes a runtime TypeError that will crash the application when the problematic code is executed. This can lead to service disruption and poor user experience.

          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