Skip to content

Commit 616397b

Browse files
committed
Generic ScopeIndentSniff no longer does exact checking for content inside parenthesis (request #528)
1 parent 33306db commit 616397b

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

CodeSniffer/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
188188

189189
$checkToken = null;
190190
$checkIndent = null;
191-
$exact = $this->exact;
191+
192+
$exact = (bool) $this->exact;
193+
if ($exact === true && isset($tokens[$i]['nested_parenthesis']) === true) {
194+
// Don't check indents exactly between parenthesis as they
195+
// tend to have custom rules, such as with multi-line function calls
196+
// and control structure conditions.
197+
$exact = false;
198+
}
192199

193200
// Detect line changes and figure out where the indent is.
194201
if ($tokens[$i]['column'] === 1) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@codingStandardsChangeSetting Generic.WhiteSpace.ScopeIndent tabIndent false
2+
@codingStandardsChangeSetting Generic.WhiteSpace.ScopeIndent exact true
3+
<?php
4+
function test()
5+
{
6+
echo 'test';
7+
echo 'test2';
8+
echo 'test3';
9+
if (true) {
10+
echo 'test3';
11+
}
12+
echo 'test3';
13+
$x = f1(
14+
'test1', 'test2',
15+
'test3'
16+
);
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@codingStandardsChangeSetting Generic.WhiteSpace.ScopeIndent tabIndent false
2+
@codingStandardsChangeSetting Generic.WhiteSpace.ScopeIndent exact true
3+
<?php
4+
function test()
5+
{
6+
echo 'test';
7+
echo 'test2';
8+
echo 'test3';
9+
if (true) {
10+
echo 'test3';
11+
}
12+
echo 'test3';
13+
$x = f1(
14+
'test1', 'test2',
15+
'test3'
16+
);
17+
}

CodeSniffer/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
8888
);
8989
}
9090

91+
if ($testFile === 'ScopeIndentUnitTest.3.inc') {
92+
return array(
93+
6 => 1,
94+
7 => 1,
95+
10 => 1,
96+
);
97+
}
98+
9199
return array(
92100
7 => 1,
93101
10 => 1,

package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
3333
-- Thanks to Xaver Loppenstedt for helping with tests
3434
- Added Generic DisallowShortArraySyntaxSniff to ban the use of the PHP short array syntax (request #483)
3535
-- Thanks to Xaver Loppenstedt for helping with tests
36+
- Generic ScopeIndentSniff no longer does exact checking for content inside parenthesis (request #528)
37+
-- Only applies to custom coding standards that set the "exact" flag to TRUE
3638
- Squiz ConcatenationSpacingSniff now has a setting to ignore newline characters around operators (request #511)
3739
-- Default remains FALSE, so newlines are not allowed
3840
-- Override the "ignoreNewlines" setting in a ruleset.xml file to change
@@ -755,6 +757,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
755757
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.1.js.fixed" role="test" />
756758
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.2.inc" role="test" />
757759
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.2.inc.fixed" role="test" />
760+
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.3.inc" role="test" />
761+
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.3.inc.fixed" role="test" />
758762
<file baseinstalldir="PHP" name="ScopeIndentUnitTest.php" role="test">
759763
<tasks:replace from="@package_version@" to="version" type="package-info" />
760764
</file>

0 commit comments

Comments
 (0)