Skip to content

docs: Correct semi-colon for semicolon (without dash) #464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2024
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ Additionally, thanks to [Alexander Turek][@derrabus] for consulting on the repo
- Thanks to [Juliette Reinders Folmer][@jrfnl] for the patch
- Squiz.WhiteSpace.SuperfluousWhitespace no longer throws errors for spacing between functions and properties in anon classes
- Thanks to [Juliette Reinders Folmer][@jrfnl] for the patch
- Zend.Files.ClosingTag no longer adds a semi-colon during fixing of a file that only contains a comment
- Zend.Files.ClosingTag no longer adds a semicolon during fixing of a file that only contains a comment
- Thanks to [Juliette Reinders Folmer][@jrfnl] for the patch
- Zend.NamingConventions.ValidVariableName now supports variables inside anonymous classes correctly
- Thanks to [Juliette Reinders Folmer][@jrfnl] for the patch
Expand Down
4 changes: 2 additions & 2 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ public function getTokensAsString($start, $length, $origContent=false)
* be returned.
* @param bool $local If true, tokens outside the current statement
* will not be checked. IE. checking will stop
* at the previous semi-colon found.
* at the previous semicolon found.
*
* @return int|false
* @see findNext()
Expand Down Expand Up @@ -2341,7 +2341,7 @@ public function findPrevious(
* be returned.
* @param bool $local If true, tokens outside the current statement
* will not be checked. i.e., checking will stop
* at the next semi-colon found.
* at the next semicolon found.
*
* @return int|false
* @see findPrevious()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
</code_comparison>
<standard>
<![CDATA[
Superfluous semi-colons are not allowed.
Superfluous semicolons are not allowed.
]]>
</standard>
<code_comparison>
<code title="Valid: There is no superfluous semi-colon after a PHP statement.">
<code title="Valid: There is no superfluous semicolon after a PHP statement.">
<![CDATA[
function_call()<em>;</em>
if (true) {
echo 'Hello World'<em>;</em>
}
]]>
</code>
<code title="Invalid: There are one or more superfluous semi-colons after a PHP statement.">
<code title="Invalid: There are one or more superfluous semicolons after a PHP statement.">
<![CDATA[
function_call()<em>;;;</em>
if (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Checks against empty PHP statements.
*
* - Check against two semi-colons with no executable code in between.
* - Check against two semicolons with no executable code in between.
* - Check against an empty PHP open - close tag combination.
*
* @author Juliette Reinders Folmer <[email protected]>
Expand Down Expand Up @@ -76,7 +76,7 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// Else, it's something like `if (foo) {};` and the semi-colon is not needed.
// Else, it's something like `if (foo) {};` and the semicolon is not needed.
}

if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
Expand All @@ -91,7 +91,7 @@ public function process(File $phpcsFile, $stackPtr)
}

$fix = $phpcsFile->addFixableWarning(
'Empty PHP statement detected: superfluous semi-colon.',
'Empty PHP statement detected: superfluous semicolon.',
$stackPtr,
'SemicolonWithoutCodeDetected'
);
Expand All @@ -101,7 +101,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($tokens[$prevNonEmpty]['code'] === T_OPEN_TAG
|| $tokens[$prevNonEmpty]['code'] === T_OPEN_TAG_WITH_ECHO
) {
// Check for superfluous whitespace after the semi-colon which will be
// Check for superfluous whitespace after the semicolon which will be
// removed as the `<?php ` open tag token already contains whitespace,
// either a space or a new line.
if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Test empty statement: two consecutive semi-colons without executable code between them.
* Test empty statement: two consecutive semicolons without executable code between them.
*/
function_call(); // OK.

Expand Down Expand Up @@ -50,10 +50,10 @@ function_call();
<input name="<?= ; ?>" /> <!-- Bad. -->

<?php
// Guard against false positives for two consecutive semi-colons in a for statement.
// Guard against false positives for two consecutive semicolons in a for statement.
for ( $i = 0; ; $i++ ) {}

// Test for useless semi-colons
// Test for useless semicolons
for ( $i = 0; ; $i++ ) {};

if (true) {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
* Test empty statement: two consecutive semi-colons without executable code between them.
* Test empty statement: two consecutive semicolons without executable code between them.
*/
function_call(); // OK.

Expand Down Expand Up @@ -45,10 +45,10 @@ function_call();
<input name="" /> <!-- Bad. -->

<?php
// Guard against false positives for two consecutive semi-colons in a for statement.
// Guard against false positives for two consecutive semicolons in a for statement.
for ( $i = 0; ; $i++ ) {}

// Test for useless semi-colons
// Test for useless semicolons
for ( $i = 0; ; $i++ ) {}

if (true) {}
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/PSR12/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<!-- checked by PSR12.Namespaces.CompoundNamespaceDepth -->

<!-- When wishing to declare strict types in files containing markup outside PHP opening and closing tags, the declaration MUST be on the first line of the file and include an opening PHP tag, the strict types declaration and closing tag. -->
<!-- Declare statements MUST contain no spaces and MUST be exactly declare(strict_types=1) (with an optional semi-colon terminator). -->
<!-- Declare statements MUST contain no spaces and MUST be exactly declare(strict_types=1) (with an optional semicolon terminator). -->
<!-- Block declare statements are allowed and MUST be formatted as below. -->
<!-- checked by PSR12.Files.DeclareStatement -->

Expand Down
4 changes: 2 additions & 2 deletions src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ public function process(File $phpcsFile, $stackPtr)
}
} while ($next !== false);

// Remove closing curly,semi-colon and any whitespace between last child and closing curly.
// Remove closing curly, semicolon and any whitespace between last child and closing curly.
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($closingCurly + 1), null, true);
if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
// Parse error, forgotten semi-colon.
// Parse error, forgotten semicolon.
$next = $closingCurly;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Squiz/Sniffs/CSS/SemicolonSpacingSniff.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Ensure each style definition has a semi-colon and it is spaced correctly.
* Ensure each style definition has a semicolon and it is spaced correctly.
*
* @author Greg Sherwood <[email protected]>
* @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Expand Down Expand Up @@ -73,7 +73,7 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// There is a semi-colon, so now find the last token in the statement.
// There is a semicolon, so now find the last token in the statement.
$prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($endOfThisStatement - 1), null, true);
$found = $tokens[($endOfThisStatement - 1)]['length'];
if ($tokens[$prevNonEmpty]['line'] !== $tokens[$endOfThisStatement]['line']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function process(File $phpcsFile, $stackPtr)
}

if ($startCondition['code'] === T_MATCH) {
// Move the stackPtr to after the semi-colon/comma if there is one.
// Move the stackPtr to after the semicolon/comma if there is one.
$nextToken = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($nextToken !== false
&& ($tokens[$nextToken]['code'] === T_SEMICOLON
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function process(File $phpcsFile, $stackPtr)

$end = $phpcsFile->findNext([T_SEMICOLON, T_CLOSE_TAG], $stackPtr, null, false);

// If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
// If the token before the semicolon is not a closing parenthesis, then we are not concerned.
$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), null, true);
if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr)

$nonSpace = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 2), null, true);

// Detect whether this is a semi-colon for a condition in a `for()` control structure.
// Detect whether this is a semicolon for a condition in a `for()` control structure.
$forCondition = false;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$nestedParens = $tokens[$stackPtr]['nested_parenthesis'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ for (
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test with semi-colon not belonging to for.
// Test with semicolon not belonging to for.
for ($i = function() { return $this->i ; }; $i < function() { return $this->max; }; $i++) {}
for ($i = function() { return $this->i; }; $i < function() { return $this->max; } ; $i++) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for ( $i = 0; $i < 10; $i++ ) {}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test with semi-colon not belonging to for.
// Test with semicolon not belonging to for.
for ($i = function() { return $this->i ; }; $i < function() { return $this->max; }; $i++) {}
for ($i = function() { return $this->i; }; $i < function() { return $this->max; }; $i++) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ for (
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test with semi-colon not belonging to for.
// Test with semicolon not belonging to for.
for (i = function() {self.widgetLoaded(widget.id) ; }; i < function() {self.widgetLoaded(widget.id);}; i++) {}
for (i = function() {self.widgetLoaded(widget.id);}; i < function() {self.widgetLoaded(widget.id);} ; i++) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for ( i = 0; i < 10; i++ ) {}
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesAfterOpen 0
// phpcs:set Squiz.ControlStructures.ForLoopDeclaration requiredSpacesBeforeClose 0

// Test with semi-colon not belonging to for.
// Test with semicolon not belonging to for.
for (i = function() {self.widgetLoaded(widget.id) ; }; i < function() {self.widgetLoaded(widget.id);}; i++) {}
for (i = function() {self.widgetLoaded(widget.id);}; i < function() {self.widgetLoaded(widget.id);}; i++) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MyOtherClass
$varQ = 'string',
$varR = 123;

// Intentionally missing a semi-colon for testing.
// Intentionally missing a semicolon for testing.
public
$varS,
$varT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MyOtherClass
$varQ = 'string',
$varR = 123;

// Intentionally missing a semi-colon for testing.
// Intentionally missing a semicolon for testing.
public
$varS,
$varT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ $sum = $a /* + $b
+ $c */ ;

/*
* Test that the sniff does *not* throw incorrect errors for semi-colons in
* Test that the sniff does *not* throw incorrect errors for semicolons in
* "empty" parts of a `for` control structure.
*/
for ($i = 1; ; $i++) {}
for ( ; $ptr >= 0; $ptr-- ) {}
for ( ; ; ) {}

// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
// But it should when the semicolon in a `for` follows a comment (but shouldn't move the semicolon).
for ( /* Deliberately left empty. */ ; $ptr >= 0; $ptr-- ) {}
for ( $i = 1 ; /* Deliberately left empty. */ ; $i++ ) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ $sum = $a; /* + $b
+ $c */

/*
* Test that the sniff does *not* throw incorrect errors for semi-colons in
* Test that the sniff does *not* throw incorrect errors for semicolons in
* "empty" parts of a `for` control structure.
*/
for ($i = 1; ; $i++) {}
for ( ; $ptr >= 0; $ptr-- ) {}
for ( ; ; ) {}

// But it should when the semi-colon in a `for` follows a comment (but shouldn't move the semi-colon).
// But it should when the semicolon in a `for` follows a comment (but shouldn't move the semicolon).
for ( /* Deliberately left empty. */; $ptr >= 0; $ptr-- ) {}
for ( $i = 1; /* Deliberately left empty. */; $i++ ) {}

Expand Down