Skip to content
This repository was archived by the owner on Nov 21, 2019. It is now read-only.

Statements must not be empty, except catch blocks #34

Merged
merged 4 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Libero/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
</rule>

<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement">
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
</rule>
<rule ref="Generic.Commenting.Fixme"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.Files.InlineHTML"/>
Expand Down
28 changes: 28 additions & 0 deletions tests/cases/php/empty-statement
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---DESCRIPTION---
Statements must not be empty, except catch blocks
---CONTENTS---
<?php

declare(strict_types=1);

if ($foo) {
// Bar

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comments do not count? // a long explanation of why we shouldn't do anything here should suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we find a valid example of this? Will take a look.

Copy link
Contributor Author

@thewilkybarkid thewilkybarkid Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples are what I had in mind, they are edge cases of complex code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to ignore for now. If there really is a situation where it makes sense, then we can revisit/disable that individual check.

} elseif ($baz) {
// Qux
} else {
}

try {
} catch (Exception $e) {
} catch (Throwable $e) {
// Corge
} finally {
}

---MESSAGES---
5:1 Generic.CodeAnalysis.EmptyStatement.DetectedIf
7:3 Generic.CodeAnalysis.EmptyStatement.DetectedElseif
9:3 Generic.CodeAnalysis.EmptyStatement.DetectedElse
12:1 Generic.CodeAnalysis.EmptyStatement.DetectedTry
16:3 Generic.CodeAnalysis.EmptyStatement.DetectedFinally
---
2 changes: 2 additions & 0 deletions tests/cases/php/short-list
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare(strict_types=1);
list($foo, $bar) = [$baz, $qux];

foreach ($quux as list('quuz' => $corge, 'grault' => $plugh)) {
break;
}

---FIXED---
Expand All @@ -18,6 +19,7 @@ declare(strict_types=1);
[$foo, $bar] = [$baz, $qux];

foreach ($quux as ['quuz' => $corge, 'grault' => $plugh]) {
break;
}

---
10 changes: 6 additions & 4 deletions tests/cases/php/todo
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ TODO comments must not be used
declare(strict_types=1);

if ($foo) {
// TODO add code
$bar = 'baz';
// TODO add more code
}

// FIXME please
if ((1 + 1) === 3) {
// FIXME please
$qux = 'quuz';
}

---MESSAGES---
6:5 Generic.Commenting.Todo.TaskFound
10:5 Generic.Commenting.Fixme.TaskFound
7:5 Generic.Commenting.Todo.TaskFound
10:1 Generic.Commenting.Fixme.TaskFound
---