-
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
-
Covered Languages:ABAP, C#, C, C++, Flex, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Python, RPG, Ruby, Scala, Swift, TypeScript, VB.Net, VB6
-
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
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.
- is implemented by
-
SONARABAP-345 Rule: Nested blocks of code should not be left empty
-
- Open
-
-
SONARPLI-157 Rule: Nested blocks of code should not be left empty
-
- Open
-
-
SONARABAP-395 Rule 108: Nested blocks of code should not be left empty
-
- Closed
-
-
SONARPY-12 Rule: Nested blocks of code should not be left empty
-
- Closed
-
-
SONARRPG-101 Rule: Nested blocks of code should not be left empty
-
- Closed
-
-
SONARSLANG-212 [Scala] Enable Rule: S108 Nested blocks of code should not be left empty
-
- Closed
-
-
SONARSLANG-297 [Apex] Enable Rule: S108 Nested blocks of code should not be left empty
-
- Closed
-
-
SONARSWIFT-68 Rule: Nested blocks of code should not be left empty
-
- Closed
-
-
SONARVBSIX-232 Rule: Nested blocks of code should not be left empty
-
- Closed
-
-
CPP-707 Create Objective-C rules repository containing targeted rules
-
- Closed
-
- is related to
-
RSPEC-3532 Empty "default" clauses should be removed
- Active
- relates to
-
SONARJAVA-2547 Empty lambda should not raise an issue for S108 : nested block should not be left empty
-
- Closed
-
-
RSPEC-1186 Methods should not be empty
- Active
- links to
1.
|
JavaScript | RSPEC-2171 |
|
Active | Unassigned | |
2.
|
PHP | RSPEC-2172 |
|
Active | Unassigned | |
3.
|
RPG | RSPEC-2173 |
|
Active | Unassigned | |
4.
|
Java | RSPEC-2174 |
|
Active | Unassigned | |
5.
|
Swift | RSPEC-2501 |
|
Active | Unassigned | |
6.
|
C-Family | RSPEC-2899 |
|
Active | Unassigned | |
7.
|
Flex | RSPEC-3302 |
|
Active | Unassigned | |
8.
|
Python | RSPEC-4007 |
|
Active | Unassigned | |
9.
|
Go | RSPEC-4570 |
|
Active | Unassigned | |
10.
|
Kotlin | RSPEC-4785 |
|
Active | Unassigned | |
11.
|
Scala | RSPEC-4927 |
|
Active | Unassigned | |
12.
|
Ruby | RSPEC-4757 |
|
Active | Unassigned | |
13.
|
Apex | RSPEC-4991 |
|
Active | Unassigned | |
14.
|
ABAP | RSPEC-5114 |
|
Active | Unassigned | |
15.
|
VB.NET | RSPEC-5203 |
|
Active | Unassigned | |
16.
|
VB6 | RSPEC-6044 |
|
Active | Unassigned |