Skip to content

Commit

Permalink
Merge branch 'fix/138' into develop
Browse files Browse the repository at this point in the history
Forward port #139
  • Loading branch information
michalbundyra committed Jan 11, 2021
2 parents d1d203b + f8ddb26 commit 2d54836
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#139](https://github.com/webimpress/coding-standard/pull/139) fixes calculating spaces before double arrow in arrays - `Arrays\DoubleArrow` sniff.

## 1.2.0 - 2020-11-27

Expand Down
38 changes: 19 additions & 19 deletions src/WebimpressCodingStandard/Sniffs/Arrays/DoubleArrowSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,29 @@ private function calculateExpectedSpaces(File $phpcsFile, array $indices) : arra
$res[$i] = $current;
$min = $length;
$current = $length;
}

if ($k > 0) {
$valueEnd = $phpcsFile->findPrevious(
Tokens::$emptyTokens,
$indices[$k]['index_start'] - 1,
null,
true
);
} else {
if ($k > 0) {
$valueEnd = $phpcsFile->findPrevious(
Tokens::$emptyTokens,
$indices[$k]['index_start'] - 1,
null,
true
);

if ($valueEnd && $tokens[$valueEnd]['line'] !== $tokens[$indices[$k]['index_start']]['line'] - 1) {
$res[$i] = $current;
$min = $length;
$current = $length;
}
}

if ($valueEnd && $tokens[$valueEnd]['line'] < $tokens[$indices[$k]['index_start']]['line'] - 1) {
$res[$i] = $current;
if ($length < $min) {
$min = $length;
$current = $length;
}
}

if ($length < $min) {
$min = $length;
}

if ($length > $current) {
$current = $length;
if ($length > $current) {
$current = $length;
}
}

if (! isset($chars[$k + 1])) {
Expand Down
6 changes: 6 additions & 0 deletions test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ $x = [
// comment
'8_____' => 'comment breaks alignment group',
];

$charMap = [
'a' => 'A', 'b' => 'B',
// Comment
'c' => 'C', 'd' => 'D',
];
6 changes: 6 additions & 0 deletions test/Sniffs/Arrays/DoubleArrowUnitTest.1.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ $x = [
// comment
'8_____' => 'comment breaks alignment group',
];

$charMap = [
'a' => 'A', 'b' => 'B',
// Comment
'c' => 'C', 'd' => 'D',
];

0 comments on commit 2d54836

Please sign in to comment.