Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Tokenizers/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ private function createPositionMap()
$this->tokens[$i]['code'] = T_PHPCS_DISABLE;
$this->tokens[$i]['type'] = 'T_PHPCS_DISABLE';
$this->tokens[$i]['sniffCodes'] = $disabledSniffs;
} else if ($ignoring !== null
&& substr($commentTextLower, 0, 12) === 'phpcs:enable'
) {
} else if (substr($commentTextLower, 0, 12) === 'phpcs:enable') {
if ($ignoring !== null) {
$enabledSniffs = [];

$additionalText = substr($commentText, 13);
Expand Down Expand Up @@ -383,9 +382,11 @@ private function createPositionMap()
$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
}

$this->tokens[$i]['sniffCodes'] = $enabledSniffs;
}//end if

$this->tokens[$i]['code'] = T_PHPCS_ENABLE;
$this->tokens[$i]['type'] = 'T_PHPCS_ENABLE';
$this->tokens[$i]['sniffCodes'] = $enabledSniffs;
} else if (substr($commentTextLower, 0, 12) === 'phpcs:ignore') {
$ignoreRules = [];

Expand Down
14 changes: 14 additions & 0 deletions tests/Core/ErrorSuppressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,20 @@ public function testCommenting()
$this->assertEquals(1, $numWarnings);
$this->assertCount(1, $warnings);

// Ignore an enable before a disable.
$content = '<?php '.PHP_EOL.'// phpcs:enable Generic.PHP.NoSilencedErrors -- Because reasons'.PHP_EOL.'$var = @delete( $filename );'.PHP_EOL;
$file = new DummyFile($content, $ruleset, $config);
$file->process();

$errors = $file->getErrors();
$numErrors = $file->getErrorCount();
$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(0, $numErrors);
$this->assertCount(0, $errors);
$this->assertEquals(0, $numWarnings);
$this->assertCount(0, $warnings);

}//end testCommenting()


Expand Down