Skip to content

Commit

Permalink
Don't enforce closure open paren spacing by default
Browse files Browse the repository at this point in the history
Fixes #439
  • Loading branch information
JDGrimes committed Sep 30, 2015
1 parent e9bb0a2 commit c3e0e45
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
18 changes: 15 additions & 3 deletions WordPress/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff extends WordPress
*
* @var int
*/
public $spaces_before_closure_open_paren = 0;
public $spaces_before_closure_open_paren = -1;

/**
* Returns an array of tokens this test wants to listen for.
Expand Down Expand Up @@ -106,7 +106,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE
&& ! ( $tokens[$stackPtr]['code'] === T_ELSE && $tokens[($stackPtr + 1)]['code'] === T_COLON )
&& ! ( T_CLOSURE === $tokens[ $stackPtr ]['code'] && 0 === (int) $this->spaces_before_closure_open_paren )
&& ! (
T_CLOSURE === $tokens[ $stackPtr ]['code']
&& (
0 === (int) $this->spaces_before_closure_open_paren
|| -1 === (int) $this->spaces_before_closure_open_paren
)
)
) {
$error = 'Space after opening control structure is required';
if (isset($phpcsFile->fixer) === true) {
Expand Down Expand Up @@ -263,7 +269,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}

} elseif ( ($stackPtr + 1) === $parenthesisOpener ) {
} elseif (
(
T_CLOSURE !== $tokens[ $stackPtr ]['code']
|| 1 === (int) $this->spaces_before_closure_open_paren
)
&& ($stackPtr + 1) === $parenthesisOpener
) {

// Checking this: if[*](...) {}.
$error = 'No space before opening parenthesis is prohibited';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,11 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; //

// Namespaces.
use Foo\Admin;

// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1

function( $arg ) {} // OK
function ( $arg ) {} // OK

$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // OK
$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // OK
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ $closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; //

// Namespaces.
use Foo\Admin;

// @codingStandardsChangeSetting WordPress.WhiteSpace.ControlStructureSpacing spaces_before_closure_open_paren -1

function( $arg ) {} // OK
function ( $arg ) {} // OK

$closureWithArgsAndVars = function( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // OK
$closureWithArgsAndVars = function ( $arg1, $arg2 ) use ( $var1, $var2 ) {}; // OK

0 comments on commit c3e0e45

Please sign in to comment.