Skip to content
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

PhpdocAnnotationWithoutDotFixer - Handle trailing whitespaces #3867

Merged
merged 1 commit into from Aug 1, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php
Expand Up @@ -78,14 +78,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$content = $annotation->getContent();

if (
1 !== Preg::match('/[.。]$/u', $content)
|| 0 !== Preg::match('/[.。](?!$)/u', $content, $matches)
1 !== Preg::match('/[.。]\h*$/u', $content)
|| 0 !== Preg::match('/[.。](?!\h*$)/u', $content, $matches)
) {
continue;
}

$endLine = $doc->getLine($annotation->getEnd());
$endLine->setContent(Preg::replace('/(?<![.。])[.。](\s+)$/u', '\1', $endLine->getContent()));
$endLine->setContent(Preg::replace('/(?<![.。])[.。]\h*(\H+)$/u', '\1', $endLine->getContent()));

$startLine = $doc->getLine($annotation->getStart());
$optionalTypeRegEx = $annotation->supportTypes()
Expand Down
20 changes: 20 additions & 0 deletions tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php
Expand Up @@ -137,6 +137,26 @@ public function provideFixCases()
/**
* @return bool|null Returns `true` if the class has a single-column ID
* and Returns `false` otherwise.
*/',
],
[
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having whitespaces after dot, yet I am fixed. '.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test case for trailing tab character too, as we are using \h

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I've missed that. Done.

*/',
],
[
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed
*/',
'<?php
/**
* @throws \Exception having tabs after dot, yet I am fixed. '.'
*/',
],
];
Expand Down