Skip to content
Snippets Groups Projects
Unverified Commit 70b03b11 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(FullyQualifiedNamespace): Fixer: Insert correct empty lines after file doc...

fix(FullyQualifiedNamespace): Fixer: Insert correct empty lines after file doc comment (#3109636 by Arkener)
parent 15f64e99
Branches
Tags
No related merge requests found
......@@ -83,7 +83,7 @@ class FullyQualifiedNamespaceSniff implements Sniff
if ($fix === true) {
$fullName = $phpcsFile->getTokensAsString(($before + 1), ($after - 1 - $before));
$fullName = trim($fullName, '\ ');
$fullName = trim($fullName, "\ \n");
$phpcsFile->fixer->beginChangeset();
......@@ -131,9 +131,10 @@ class FullyQualifiedNamespaceSniff implements Sniff
$fileComment = $phpcsFile->findNext(T_WHITESPACE, ($beginning + 1), null, true);
if ($tokens[$fileComment]['code'] === T_DOC_COMMENT_OPEN_TAG) {
$beginning = $tokens[$fileComment]['comment_closer'];
$phpcsFile->fixer->addContent($beginning, "\n\nuse $fullName;\n");
} else {
$phpcsFile->fixer->addContent($beginning, "use $fullName;\n");
}
$phpcsFile->fixer->addContent($beginning, "use $fullName;\n");
}
}
......
<?php
/**
* @file
* Example file.
*
* Disable commenting rules to check if use statements are placed correctly
* without them.
* phpcs:disable Drupal.Commenting
*/
/**
* Foo function.
*/
function foo() {
\Foo\Bar::load();
}
<?php
/**
* @file
* Example file.
*
* Disable commenting rules to check if use statements are placed correctly
* without them.
* phpcs:disable Drupal.Commenting
*/
use Foo\Bar;
/**
* Foo function.
*/
function foo() {
Bar::load();
}
......@@ -23,6 +23,8 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
switch ($testFile) {
case 'FullyQualifiedNamespaceUnitTest.inc':
return [3 => 1];
case 'FullyQualifiedNamespaceUnitTest.1.inc':
return [16 => 1];
}
return [];
......@@ -58,6 +60,7 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
{
return [
__DIR__.'/FullyQualifiedNamespaceUnitTest.inc',
__DIR__.'/FullyQualifiedNamespaceUnitTest.1.inc',
__DIR__.'/FullyQualifiedNamespaceUnitTest.api.php',
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment