Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-2234

Parameters should be passed in the correct order

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Parameters to "xxx" have the same names but not the same order as the method arguments.
    • Highlighting:
      • Primary: actual parameters clause
      • Secondary: formal parameters clause
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Flex, PHP, PL/SQL, Python, Swift, T-SQL, VB6
    • Covered Languages:
      C#, C, C++, Java, JavaScript, Objective-C, TypeScript, VB.Net
    • Irrelevant for Languages:
      ABAP, Cobol, HTML, PL/I, RPG, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Semantic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Implementation details:
    • Common Rule:
      Yes
    • TSLint-SonarTS:
      arguments-order

      Description

      When the names of parameters in a method call match the names of the method arguments, it contributes to clearer, more readable code. However, when the names match, but are passed in a different order than the method arguments, it indicates a mistake in the parameter order which will likely lead to unexpected results.

      Noncompliant Code Example

      public double divide(int divisor, int dividend) {
        return divisor/dividend;
      }
      
      public void doTheThing() {
        int divisor = 15;
        int dividend = 5;
      
        double result = divide(dividend, divisor);  // Noncompliant; operation succeeds, but result is unexpected
        //...
      }
      

      Compliant Solution

      public double divide(int divisor, int dividend) {
        return divisor/dividend;
      }
      
      public void doTheThing() {
        int divisor = 15;
        int dividend = 5;
      
        double result = divide(divisor, dividend);
        //...
      }
      

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-3478 Language-Specification Active Unassigned
          2.
          C# RSPEC-3790 Language-Specification Active Unassigned
          3.
          C-Family RSPEC-4255 Language-Specification Active Unassigned
          4.
          VB.NET RSPEC-5217 Language-Specification Active Unassigned

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ann.campbell.2 Ann Campbell
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: