Skip to content

Commit 34543c8

Browse files
committed
Squiz FunctionOpeningBraceSpaceSniff no longer does additional checks for JS functions
1 parent 0461cf6 commit 34543c8

File tree

4 files changed

+6
-72
lines changed

4 files changed

+6
-72
lines changed

CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionOpeningBraceSpaceSniff.php

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -107,74 +107,6 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
107107
}
108108
}
109109

110-
if ($phpcsFile->tokenizerType !== 'JS') {
111-
return;
112-
}
113-
114-
// Do some additional checking before the function brace.
115-
$nestedFunction = false;
116-
if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
117-
|| $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
118-
|| isset($tokens[$stackPtr]['nested_parenthesis']) === true
119-
) {
120-
$nestedFunction = true;
121-
}
122-
123-
$functionLine = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['line'];
124-
$lineDifference = ($braceLine - $functionLine);
125-
126-
if ($nestedFunction === true) {
127-
if ($lineDifference > 0) {
128-
$error = 'Opening brace should be on the same line as the function keyword';
129-
$fix = $phpcsFile->addFixableError($error, $openBrace, 'SpacingAfterNested');
130-
if ($fix === true) {
131-
$phpcsFile->fixer->beginChangeset();
132-
for ($i = ($openBrace - 1); $i > $stackPtr; $i--) {
133-
if ($tokens[$i]['code'] !== T_WHITESPACE) {
134-
break;
135-
}
136-
137-
$phpcsFile->fixer->replaceToken($i, '');
138-
}
139-
140-
$phpcsFile->fixer->addContentBefore($openBrace, ' ');
141-
$phpcsFile->fixer->endChangeset();
142-
}
143-
}
144-
} else {
145-
if ($lineDifference === 0) {
146-
$error = 'Opening brace should be on a new line';
147-
$fix = $phpcsFile->addFixableError($error, $openBrace, 'ContentBefore');
148-
if ($fix === true) {
149-
$phpcsFile->fixer->addNewlineBefore($openBrace);
150-
}
151-
152-
return;
153-
}
154-
155-
if ($lineDifference > 1) {
156-
$error = 'Opening brace should be on the line after the declaration; found %s blank line(s)';
157-
$data = array(($lineDifference - 1));
158-
$fix = $phpcsFile->addError($error, $openBrace, 'SpacingBefore', $data);
159-
160-
if ($fix === true) {
161-
$phpcsFile->fixer->beginChangeset();
162-
for ($i = ($openBrace - 1); $i > $stackPtr; $i--) {
163-
if ($tokens[$i]['code'] !== T_WHITESPACE) {
164-
break;
165-
}
166-
167-
$phpcsFile->fixer->replaceToken($i, '');
168-
}
169-
170-
$phpcsFile->fixer->addNewlineBefore($openBrace);
171-
$phpcsFile->fixer->endChangeset();
172-
}
173-
174-
return;
175-
}//end if
176-
}//end if
177-
178110
}//end process()
179111

180112

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/FunctionOpeningBraceSpaceUnitTest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function FuncFour()
3636

3737
AbstractAttributeEditorWidgetType.prototype = {
3838
isActive: function() {
39+
3940
return this.active;
4041

4142
},
@@ -85,6 +86,8 @@ HelpWidgetType.prototype = {
8586
var x = 1;
8687
var y = {
8788
test: function() {
89+
90+
8891
alert(3);
8992
}
9093
}

CodeSniffer/Standards/Squiz/Tests/WhiteSpace/FunctionOpeningBraceSpaceUnitTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ public function getErrorList($testFile='FunctionOpeningBraceSpaceUnitTest.inc')
5656
11 => 1,
5757
31 => 1,
5858
38 => 1,
59-
57 => 1,
60-
60 => 1,
61-
73 => 1,
62-
84 => 1,
59+
88 => 1,
6360
);
6461
break;
6562
default:

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
4242
-- File paths are only processed if no files were specified on the command line
4343
- Squiz coding standard now requires lowercase PHP constants (true, false and null)
4444
-- Removed Squiz.NamingConventions.ConstantCase sniff as the rule is now consistent across PHP and JS files
45+
- Squiz FunctionOpeningBraceSpaceSniff no longer does additional checks for JS functions
46+
-- PHP and JS functions and closures are now treated the same way
4547
- Interactive mode no longer breaks if you also specify a report type on the command line
4648
- PEAR InlineCommentSniff now fixes the Perl-style comments that it finds (request #375)
4749
- PSR2 standard no longer fixes the placement of docblock open tags as comments are excluded from this standard

0 commit comments

Comments
 (0)