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
Go

Go static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your GO code

  • All rules 94
  • Vulnerability21
  • Bug13
  • Security Hotspot14
  • Code Smell46
Filtered: 3 rules found
performance
    Impact
      Clean code attribute
        1. Context parameters should be reused instead of creating new background contexts

           Code Smell
        2. Use "bytes.Equal" instead of "bytes.Compare" for equality checks

           Code Smell
        3. Context cancellation functions should be deferred

           Code Smell

        Use "bytes.Equal" instead of "bytes.Compare" for equality checks

        intentionality - efficient
        maintainability
        Code Smell
        • performance

        This is an issue when using bytes.Compare(a, b) == 0 or bytes.Compare(a, b) != 0 to check if two byte slices are equal or not equal.

        Why is this an issue?

        How can I fix it?

        More Info

        The bytes.Compare function is designed for ordering comparisons and returns -1, 0, or 1 to indicate the relative order of two byte slices. When you only need to check equality, bytes.Compare does unnecessary work.

        The bytes.Equal function is specifically optimized for equality checks. It can return early as soon as it finds a difference, and it may use optimized assembly code for better performance on certain architectures.

        Using bytes.Compare for equality checks makes your code slower and less clear about its intent. The performance difference can be significant, especially when comparing large byte slices or when the comparison is performed frequently.

        What is the potential impact?

        Using bytes.Compare instead of bytes.Equal for equality checks results in unnecessary performance overhead. The impact increases with the size of the byte slices being compared and the frequency of comparisons in your application.

          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories

        © 2025 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use