-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update RSPEC before 9.3 release (#7336)
- Loading branch information
1 parent
e63e4bc
commit e47cf88
Showing
14 changed files
with
483 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
<h2>Why is this an issue?</h2> | ||
<p>In the absence of enclosing curly braces, the line immediately after a conditional is the one that is conditionally executed. By both convention | ||
and good practice, such lines are indented. In the absence of both curly braces and indentation the intent of the original programmer is entirely | ||
unclear and perhaps not actually what is executed. Additionally, such code is highly likely to be confusing to maintainers.</p> | ||
<h3>Noncompliant code example</h3> | ||
<p>When the line immediately after a conditional has neither curly braces nor indentation, the intent of the code is unclear and perhaps not what is | ||
executed. Additionally, such code is confusing to maintainers.</p> | ||
<pre> | ||
if (condition) // Noncompliant | ||
DoTheThing(); | ||
|
||
DoTheOtherThing(); | ||
SomethingElseEntirely(); | ||
|
||
Foo(); | ||
DoTheOtherThing(); // Was the intent to call this function unconditionally? | ||
</pre> | ||
<h3>Compliant solution</h3> | ||
<p>It becomes even more confusing and bug-prone if lines get commented out.</p> | ||
<pre> | ||
if (condition) // Noncompliant | ||
// DoTheThing(); | ||
DoTheOtherThing(); // Was the intent to call this function conditionally? | ||
</pre> | ||
<p>Indentation alone or together with curly braces makes the intent clear.</p> | ||
<pre> | ||
if (condition) | ||
DoTheThing(); | ||
DoTheOtherThing(); // Clear intent to call this function unconditionally | ||
|
||
DoTheOtherThing(); | ||
SomethingElseEntirely(); | ||
// or | ||
|
||
Foo(); | ||
if (condition) | ||
{ | ||
DoTheThing(); | ||
} | ||
DoTheOtherThing(); // Clear intent to call this function unconditionally | ||
</pre> | ||
<p>This rule raises an issue if the line controlled by a conditional has the same indentation as the conditional and is not enclosed in curly | ||
braces.</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.