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: 19 rules found
convention
    Impact
      Clean code attribute
        1. Modules should use "extend self" instead of "module_function"

           Code Smell
        2. Array and hash literals should be used instead of constructors when no parameters are needed

           Code Smell
        3. Logical operators "and" and "or" should be replaced with "&&" and "||"

           Code Smell
        4. Private methods should be declared at the end of Ruby classes

           Code Smell
        5. Predicate methods should not use redundant "is_" prefix

           Code Smell
        6. Controllers should inherit from appropriate base classes

           Code Smell
        7. Rails model callback methods should be private

           Code Smell
        8. Rails collections should use "ids" instead of "pluck(:id)" for primary keys

           Code Smell
        9. Rails queries should use "find_by" instead of "where.take" for single record retrieval

           Code Smell
        10. Safe navigation operator should be preferred over ActiveSupport's "try!"

           Code Smell
        11. Use "require_relative" instead of "require" for loading local files

           Code Smell
        12. Require statements should be placed at the top of files

           Code Smell
        13. Track lack of copyright and license headers

           Code Smell
        14. Statements should be on separate lines

           Code Smell
        15. Function and block parameter names should comply with a naming convention

           Code Smell
        16. Tabulation characters should not be used

           Code Smell
        17. Lines should not be too long

           Code Smell
        18. Class names should comply with a naming convention

           Code Smell
        19. Method names should comply with a naming convention

           Code Smell

        Controllers should inherit from appropriate base classes

        consistency - conventional
        maintainability
        security
        Code Smell
        • rails
        • convention
        • inheritance

        This is an issue when Rails controllers inherit directly from ActionController::Base instead of ApplicationController, or when specialized controllers (like Avo controllers) inherit from inappropriate base classes that break the intended inheritance chain.

        Why is this an issue?

        How can I fix it?

        More Info

        Rails follows a convention where controllers should inherit from ApplicationController, which itself inherits from ActionController::Base. This pattern allows you to add application-wide functionality like authentication, authorization, and shared methods in one place.

        When controllers inherit directly from ActionController::Base, they bypass ApplicationController and miss out on any shared functionality you’ve defined there. This can lead to inconsistent behavior across your application and make it harder to maintain common controller logic.

        Similarly, specialized frameworks like Avo have their own inheritance hierarchies. Avo controllers should inherit from Avo::ResourcesController to get framework-specific functionality. When they inherit from ApplicationController or ActionController::Base instead, they lose important framework features and may not work correctly.

        Following proper inheritance patterns makes your code more maintainable, ensures consistent behavior, and respects the architectural decisions of the frameworks you’re using.

        What is the potential impact?

        Controllers that don’t follow proper inheritance patterns may miss critical application-wide functionality like authentication, authorization, or error handling. This can create security vulnerabilities, inconsistent user experiences, and maintenance difficulties. Specialized controllers that use incorrect base classes may not function properly within their intended frameworks.

          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