SonarQube Java
  1. SonarQube Java
  2. SONARJAVA-106

Rule to detect selector/flag arguments in functions/methods

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Component/s: Rules
    • Labels:
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      Description

      Hi folks,

      While rereading the book 'clean code' of Robert C. Martin I just wonder
      if sonar has a rule to detect 'selector arguments'.

      For anybody who need an example:

      public void printOut(String myName,boolean uppercase){
         if (uppercase){
      	System.out.print( myName.toUpperCase() );
         }
         else{
      	System.out.print( myName );
         }
      }
      

      could be written as two separate methods to decrease complexity:

      public void printOutAsItIs(String myName){
             System.out.print( myName );
      }
      public void printOutUppercase(String myName){
             System.out.print( myName.toUpperCase() );
      }

      For this request I prepared a possible implementation:

      A screenshot:

      My patch is here (on top of java-plugins-1.1): https://github.com/lkwg82/sonar-java/commit/9dcb5e1864d9deb6ce77c4f5e9c32e856b5a5505

      This is the discussion on the mailinglist: http://sonar.markmail.org/message/fvlcrk2p2wultkvm?q=list:org%2Ecodehaus%2Esonar%2Euser+selector/flag+arguments

        Activity

        Hide
        Freddy Mallet added a comment -

        The rule might log a violation when :

        • A methods has at least 2 parameters
        • Detect if at least one of the boolean parameters is used to create a branch : if(myBooleanParameter)
        Show
        Freddy Mallet added a comment - The rule might log a violation when : A methods has at least 2 parameters Detect if at least one of the boolean parameters is used to create a branch : if(myBooleanParameter)

          People

          • Assignee:
            Unassigned
            Reporter:
            Lars K. W. Gohlke
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: