Skip to content

Commit

Permalink
Merge pull request #5 from martin-helmich/bugfix/constant-annotations
Browse files Browse the repository at this point in the history
DeadCode sniffs wrongfully complains about constant annotations
  • Loading branch information
martin-helmich committed Nov 8, 2015
2 parents 52c7be6 + 4762233 commit f5547cb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/Helmich/TypoScriptLint/Linter/Sniff/DeadCodeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class DeadCodeSniff implements TokenStreamSniffInterface
{


const ANNOTATION_COMMENT = '/^\s*([a-z0-9]+=(.*?))(;\s*[a-z0-9]+=(.*?))*\s*$/';


/**
* @param array $parameters
Expand Down Expand Up @@ -39,7 +41,11 @@ public function sniff(array $tokens, File $file, LinterConfiguration $configurat

$commentContent = preg_replace(',^\s*(#|/\*|/)\s*,', '', $token->getValue());

if (preg_match(Tokenizer::TOKEN_OPERATOR_LINE, $commentContent, $matches))
if (preg_match(static::ANNOTATION_COMMENT, $commentContent))
{
continue;
}
else if (preg_match(Tokenizer::TOKEN_OPERATOR_LINE, $commentContent, $matches))
{
$warning = new Warning(
$token->getLine(),
Expand All @@ -52,4 +58,4 @@ public function sniff(array $tokens, File $file, LinterConfiguration $configurat
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Define custom categories
# customsubcategory=pdf=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.category.pdf

plugin.tx_web2pdf {
view {
# cat=plugin.tx_web2pdf/file; type=string; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.file.templates
templateRootPath = EXT:web2pdf/Resources/Private/Templates/
# cat=plugin.tx_web2pdf/file; type=string; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.file.partials
partialRootPath = EXT:web2pdf/Resources/Private/Partials/
# cat=plugin.tx_web2pdf/file; type=string; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.file.layouts
layoutRootPath = EXT:web2pdf/Resources/Private/Layouts/
}

settings {
# cat=plugin.tx_web2pdf/pdf/1; type=options[A4,A3]; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.pageFormat
pdfPageFormat = A4
# cat=plugin.tx_web2pdf/pdf/2; type=options[LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.pageOrientation.portrait=P,LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.pageOrientation.landscape=L]; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.pageOrientation
pdfPageOrientation = P
# cat=plugin.tx_web2pdf/pdf/3; type=int+; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.leftMargin
pdfLeftMargin = 15
# cat=plugin.tx_web2pdf/pdf/4; type=int+; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.rightMargin
pdfRightMargin = 15
# cat=plugin.tx_web2pdf/pdf/5; type=int+; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.topMargin
pdfTopMargin = 15
# cat=plugin.tx_web2pdf/pdf/6; type=options[LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.styleSheet.print=print,LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.styleSheet.screen=screen]; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.styleSheet
pdfStyleSheet = allAndPrint
# cat=plugin.tx_web2pdf/pdf/8; type=boolean; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.useCustomFooter
useCustomFooter = 0
# cat=plugin.tx_web2pdf/pdf/8; type=boolean; label=LLL:EXT:web2pdf/Resources/Private/Language/locallang.xlf:constants.pdf.useCustomHeader
useCustomHeader = 0
}
}
25 changes: 15 additions & 10 deletions tests/functional/Helmich/TypoScriptLint/Tests/Linter/LinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,24 @@ public function testLinterCreatesExpectedOutput($typoscriptFile, array $expected
new NullOutput()
);

$actualWarnings = $report->getFiles()[0]->getWarnings();
try
$this->assertCount(count($expectedWarnings) > 0 ? 1 : 0, $report->getFiles());
if (count($expectedWarnings) > 0)
{
$this->assertEquals($expectedWarnings, $actualWarnings);
}
catch (\PHPUnit_Framework_AssertionFailedError $error)
{
foreach($actualWarnings as $warning)
$actualWarnings = $report->getFiles()[0]->getWarnings();
try
{
echo $warning->getLine() . ";" . $warning->getColumn() . ";" . $warning->getMessage() . ";" .
$warning->getSeverity() . ";" . $warning->getSource() . "\n";
$this->assertEquals($expectedWarnings, $actualWarnings);
}
catch (\PHPUnit_Framework_AssertionFailedError $error)
{
foreach($actualWarnings as $warning)
{
echo $warning->getLine() . ";" . $warning->getColumn() . ";" . $warning->getMessage() . ";" .
$warning->getSeverity() . ";" . $warning->getSource() . "\n";
}

throw $error;
throw $error;
}
}
}

Expand All @@ -95,6 +99,7 @@ public function getFunctionalTestFixtures()
{
$output = dirname($file) . '/output.txt';
$outputLines = explode("\n", file_get_contents($output));
$outputLines = array_filter($outputLines, 'strlen');

$reports = array_map(function($line) use ($file) {
$values = str_getcsv($line, ';');
Expand Down

0 comments on commit f5547cb

Please sign in to comment.