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

Nested blocks of code should not be left empty

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Either remove or fill this block of code.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Legacy Key:
      EmptyBlock, EmptyCompoundStatement
    • Targeted languages:
      PL/I, VB6
    • Covered Languages:
      ABAP, C#, C, C++, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Python, RPG, Ruby, Scala, Swift, TypeScript, VB.Net
    • Irrelevant for Languages:
      Cobol, HTML, PL/SQL, T-SQL, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Level:
      Syntactic Analysis
    • Analysis Scope:
      Main Sources, Test Sources
    • Common Rule:
      Yes
    • Checkstyle:
      EmptyBlock, EmptyCatchBlock
    • ESLint:
      no-empty
    • FindBugs:
      ESync_EMPTY_SYNC, DE_MIGHT_DROP, DE_MIGHT_IGNORE, UCF_USELESS_CONTROL_FLOW
    • PC-Lint:
      9063
    • PMD:
      EmptyInitializer, EmptyCatchBlock, EmptyFinallyBlock, EmptyIfStmt, EmptyStatementBlock, EmptyStaticInitializer, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt
    • ReSharper:
      RedundantEmptyFinallyBlock, EmptyForStatement
    • TSLint:
      no-empty
    • TSLint-SonarTS:
      no-empty-nested-blocks

      Description

      Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.

      Noncompliant Code Example

      for (int i = 0; i < 42; i++){}  // Empty on purpose or missing piece of code ?
      

      Exceptions

      When a block contains a comment, this block is not considered to be empty.

        Attachments

          Issue Links

          1.
          JavaScript RSPEC-2171 Language-Specification Active Unassigned
          2.
          PHP RSPEC-2172 Language-Specification Active Unassigned
          3.
          RPG RSPEC-2173 Language-Specification Active Unassigned
          4.
          Java RSPEC-2174 Language-Specification Active Unassigned
          5.
          Swift RSPEC-2501 Language-Specification Active Unassigned
          6.
          C-Family RSPEC-2899 Language-Specification Active Unassigned
          7.
          Flex RSPEC-3302 Language-Specification Active Unassigned
          8.
          Python RSPEC-4007 Language-Specification Active Unassigned
          9.
          Go RSPEC-4570 Language-Specification Active Unassigned
          10.
          Kotlin RSPEC-4785 Language-Specification Active Unassigned
          11.
          Scala RSPEC-4927 Language-Specification Active Unassigned
          12.
          Ruby RSPEC-4757 Language-Specification Active Unassigned
          13.
          Apex RSPEC-4991 Language-Specification Active Unassigned
          14.
          ABAP RSPEC-5114 Language-Specification Active Unassigned
          15.
          VB.NET RSPEC-5203 Language-Specification Active Unassigned

            Activity

              People

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

                Dates

                • Created:
                  Updated: