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

Functions should not have too many lines of code

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      This [function|method|module|subroutine] "XXXX" has {0} lines of code, which is greater than the {1} authorized. Split it into smaller [functions|methods|modules|subroutines].
    • List of parameters:
      Hide

      Key: max
      Description: Maximum authorized lines of code in a function
      Default Value: 100
      Default Value for Go: 120
      Default Value for RPG : 300
      Default Value for PHP: 150
      Default Value for C#: 80
      Default Value for JavaScript: 200
      Default Value for TypeScript: 200
      Type: INTEGER

      Show
      Key: max Description: Maximum authorized lines of code in a function Default Value: 100 Default Value for Go: 120 Default Value for RPG : 300 Default Value for PHP: 150 Default Value for C#: 80 Default Value for JavaScript: 200 Default Value for TypeScript: 200 Type: INTEGER
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      too-many-loc-in-function
    • Targeted languages:
      ABAP, PL/I, PL/SQL, Python
    • Covered Languages:
      C#, C, C++, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, RPG, Ruby, Scala, Swift, T-SQL, TypeScript, VB.Net, VB6
    • Irrelevant for Languages:
      Cobol, HTML, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      20min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources
    • Common Rule:
      Yes
    • Checkstyle:
      MethodLength
    • ESLint:
      max-lines-per-function
    • PMD:
      ExcessiveMethodLength, NcssConstructorCount, NcssMethodCount
    • SwiftLint:
      function_body_length
    • TSLint-SonarTS:
      no-big-function

      Description

      A function that grows too large tends to aggregate too many responsibilities.
      Such functions inevitably become harder to understand and therefore harder to maintain.

      Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.
      Those smaller functions will not only be easier to understand, but also probably easier to test.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                freddy.mallet Freddy Mallet (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: