Skip to content

Commit 2f3d62e

Browse files
authored
Merge pull request #975 from PHPCSStandards/phpcs-4.0/feature/sq-1954-tokenizer-drop-old-style-annotations-support
Tokenizer: remove support for the deprecated @CodingStandard annotation syntax
2 parents ff7a908 + 847a11e commit 2f3d62e

File tree

7 files changed

+9
-176
lines changed

7 files changed

+9
-176
lines changed

src/Files/File.php

+1-32
Original file line numberDiff line numberDiff line change
@@ -361,38 +361,7 @@ public function process()
361361
) {
362362
$commentText = ltrim($this->tokens[$stackPtr]['content'], " \t/*#");
363363
$commentTextLower = strtolower($commentText);
364-
if (strpos($commentText, '@codingStandards') !== false) {
365-
if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
366-
// Ignoring the whole file, just a little late.
367-
$this->errors = [];
368-
$this->warnings = [];
369-
$this->errorCount = 0;
370-
$this->warningCount = 0;
371-
$this->fixableCount = 0;
372-
return;
373-
} else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
374-
$start = strpos($commentText, '@codingStandardsChangeSetting');
375-
$comment = substr($commentText, ($start + 30));
376-
$parts = explode(' ', $comment);
377-
if (count($parts) >= 2) {
378-
$sniffParts = explode('.', $parts[0]);
379-
if (count($sniffParts) >= 3) {
380-
// If the sniff code is not known to us, it has not been registered in this run.
381-
// But don't throw an error as it could be there for a different standard to use.
382-
if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
383-
$listenerCode = array_shift($parts);
384-
$propertyCode = array_shift($parts);
385-
$settings = [
386-
'value' => rtrim(implode(' ', $parts), " */\r\n"),
387-
'scope' => 'sniff',
388-
];
389-
$listenerClass = $this->ruleset->sniffCodes[$listenerCode];
390-
$this->ruleset->setSniffProperty($listenerClass, $propertyCode, $settings);
391-
}
392-
}
393-
}
394-
}//end if
395-
} else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
364+
if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
396365
|| substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
397366
) {
398367
// Ignoring the whole file, just a little late.

src/Files/LocalFile.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public function __construct($path, Ruleset $ruleset, Config $config)
4848
$firstContent .= fgets($handle);
4949
fclose($handle);
5050

51-
if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false
52-
|| stripos($firstContent, 'phpcs:ignorefile') !== false
53-
) {
51+
if (stripos($firstContent, 'phpcs:ignorefile') !== false) {
5452
// We are ignoring the whole file.
5553
$this->ignored = true;
5654
return;

src/Standards/Generic/Tests/NamingConventions/CamelCapsFunctionNameUnitTest.1.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ function test() {
8383
$foo = function() { echo 'foo'; };
8484
}
8585

86-
/* @codingStandardsIgnoreStart */
86+
/* phpcs:disable */
8787
class MyClass
8888
{
89-
/* @codingStandardsIgnoreEnd */
89+
/* phpcs:enable */
9090
public function __construct() {}
9191
}
9292

src/Standards/PEAR/Tests/NamingConventions/ValidFunctionNameUnitTest.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ function test() {
158158
$foo = function() { echo 'foo'; };
159159
}
160160

161-
/* @codingStandardsIgnoreStart */
161+
/* phpcs:disable */
162162
class MyClass
163163
{
164-
/* @codingStandardsIgnoreEnd */
164+
/* phpcs:enable */
165165
public function __construct() {}
166166
}
167167

src/Standards/Squiz/Tests/NamingConventions/ValidFunctionNameUnitTest.inc

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function xmlParser() {}
1818

1919
echo preg_replace_callback('~-([a-z])~', function ($match) { return strtoupper($match[1]); }, 'hello-world');
2020

21-
/* @codingStandardsIgnoreStart */
21+
/* phpcs:disable */
2222
class MyClass
2323
{
24-
/* @codingStandardsIgnoreEnd */
24+
/* phpcs:enable */
2525
public function __construct() {}
2626
}
2727
?>

src/Tokenizers/Tokenizer.php

+1-50
Original file line numberDiff line numberDiff line change
@@ -259,56 +259,7 @@ private function createPositionMap()
259259
$commentText = ltrim($this->tokens[$i]['content'], " \t/*#");
260260
$commentText = rtrim($commentText, " */\t\r\n");
261261
$commentTextLower = strtolower($commentText);
262-
if (strpos($commentText, '@codingStandards') !== false) {
263-
// If this comment is the only thing on the line, it tells us
264-
// to ignore the following line. If the line contains other content
265-
// then we are just ignoring this one single line.
266-
$ownLine = false;
267-
if ($i > 0) {
268-
for ($prev = ($i - 1); $prev >= 0; $prev--) {
269-
if ($this->tokens[$prev]['code'] === T_WHITESPACE) {
270-
continue;
271-
}
272-
273-
break;
274-
}
275-
276-
if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
277-
$ownLine = true;
278-
}
279-
}
280-
281-
if ($ignoring === null
282-
&& strpos($commentText, '@codingStandardsIgnoreStart') !== false
283-
) {
284-
$ignoring = ['.all' => true];
285-
if ($ownLine === true) {
286-
$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
287-
}
288-
} else if ($ignoring !== null
289-
&& strpos($commentText, '@codingStandardsIgnoreEnd') !== false
290-
) {
291-
if ($ownLine === true) {
292-
$this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
293-
} else {
294-
$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
295-
}
296-
297-
$ignoring = null;
298-
} else if ($ignoring === null
299-
&& strpos($commentText, '@codingStandardsIgnoreLine') !== false
300-
) {
301-
$ignoring = ['.all' => true];
302-
if ($ownLine === true) {
303-
$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
304-
$this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoring;
305-
} else {
306-
$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
307-
}
308-
309-
$ignoring = null;
310-
}//end if
311-
} else if (substr($commentTextLower, 0, 6) === 'phpcs:'
262+
if (substr($commentTextLower, 0, 6) === 'phpcs:'
312263
|| substr($commentTextLower, 0, 7) === '@phpcs:'
313264
) {
314265
// If the @phpcs: syntax is being used, strip the @ to make

tests/Core/ErrorSuppressionTest.php

-85
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,6 @@ public static function dataSuppressError()
133133
'before' => '/** phpcs:disable */'.PHP_EOL,
134134
'after' => '/** phpcs:enable */',
135135
],
136-
137-
// Deprecated syntax.
138-
'old style: slash comment' => [
139-
'before' => '// @codingStandardsIgnoreStart'.PHP_EOL,
140-
'after' => '// @codingStandardsIgnoreEnd',
141-
],
142-
'old style: star comment' => [
143-
'before' => '/* @codingStandardsIgnoreStart */'.PHP_EOL,
144-
'after' => '/* @codingStandardsIgnoreEnd */',
145-
],
146-
'old style: multi-line star comment' => [
147-
'before' => '/*'.PHP_EOL.' @codingStandardsIgnoreStart'.PHP_EOL.' */'.PHP_EOL,
148-
'after' => '/*'.PHP_EOL.' @codingStandardsIgnoreEnd'.PHP_EOL.' */',
149-
],
150-
'old style: single line docblock comment' => [
151-
'before' => '/** @codingStandardsIgnoreStart */'.PHP_EOL,
152-
'after' => '/** @codingStandardsIgnoreEnd */',
153-
],
154136
];
155137

156138
}//end dataSuppressError()
@@ -233,16 +215,6 @@ public static function dataSuppressSomeErrors()
233215
'before' => '/** phpcs:disable */',
234216
'between' => '/** phpcs:enable */',
235217
],
236-
237-
// Deprecated syntax.
238-
'old style: slash comment' => [
239-
'before' => '// @codingStandardsIgnoreStart',
240-
'between' => '// @codingStandardsIgnoreEnd',
241-
],
242-
'old style: single line docblock comment' => [
243-
'before' => '/** @codingStandardsIgnoreStart */',
244-
'between' => '/** @codingStandardsIgnoreEnd */',
245-
],
246218
];
247219

248220
}//end dataSuppressSomeErrors()
@@ -316,16 +288,6 @@ public static function dataSuppressWarning()
316288
'before' => '/** phpcs:disable */',
317289
'after' => '/** phpcs:enable */',
318290
],
319-
320-
// Deprecated syntax.
321-
'old style: slash comment' => [
322-
'before' => '// @codingStandardsIgnoreStart',
323-
'after' => '// @codingStandardsIgnoreEnd',
324-
],
325-
'old style: single line docblock comment' => [
326-
'before' => '/** @codingStandardsIgnoreStart */',
327-
'after' => '/** @codingStandardsIgnoreEnd */',
328-
],
329291
];
330292

331293
}//end dataSuppressWarning()
@@ -424,15 +386,6 @@ public static function dataSuppressLine()
424386
'before' => '',
425387
'after' => ' # @phpcs:ignore',
426388
],
427-
428-
// Deprecated syntax.
429-
'old style: line before, slash comment' => [
430-
'before' => '// @codingStandardsIgnoreLine',
431-
],
432-
'old style: end of line, slash comment' => [
433-
'before' => '',
434-
'after' => ' // @codingStandardsIgnoreLine',
435-
],
436389
];
437390

438391
}//end dataSuppressLine()
@@ -554,10 +507,6 @@ public static function dataNestedSuppressLine()
554507
'before' => '# phpcs:disable',
555508
'after' => '# phpcs:enable',
556509
],
557-
'old style: slash comment, no single line suppression' => [
558-
'before' => '// @codingStandardsIgnoreStart',
559-
'after' => '// @codingStandardsIgnoreEnd',
560-
],
561510

562511
// Process with line suppression nested within disable/enable suppression.
563512
'disable/enable: slash comment, next line nested single line suppression' => [
@@ -572,10 +521,6 @@ public static function dataNestedSuppressLine()
572521
'before' => '# @phpcs:disable'.PHP_EOL.'# @phpcs:ignore',
573522
'after' => '# @phpcs:enable',
574523
],
575-
'old style: slash comment, next line nested single line suppression' => [
576-
'before' => '// @codingStandardsIgnoreStart'.PHP_EOL.'// @codingStandardsIgnoreLine',
577-
'after' => '// @codingStandardsIgnoreEnd',
578-
],
579524
];
580525

581526
}//end dataNestedSuppressLine()
@@ -661,16 +606,6 @@ public static function dataSuppressScope()
661606
'before' => '/** @phpcs:disable */',
662607
'after' => '/** @phpcs:enable */',
663608
],
664-
665-
// Deprecated syntax.
666-
'old style: start/end, slash comment' => [
667-
'before' => '//@codingStandardsIgnoreStart',
668-
'after' => '//@codingStandardsIgnoreEnd',
669-
],
670-
'old style: start/end, single line docblock comment' => [
671-
'before' => '/** @codingStandardsIgnoreStart */',
672-
'after' => '/** @codingStandardsIgnoreEnd */',
673-
],
674609
];
675610

676611
}//end dataSuppressScope()
@@ -765,26 +700,6 @@ public static function dataSuppressFile()
765700
'before' => '',
766701
'after' => '// phpcs:ignoreFile',
767702
],
768-
769-
// Deprecated syntax.
770-
'old style: start of file, slash comment' => [
771-
'before' => '// @codingStandardsIgnoreFile',
772-
],
773-
'old style: start of file, single-line star comment' => [
774-
'before' => '/* @codingStandardsIgnoreFile */',
775-
],
776-
'old style: start of file, multi-line star comment' => [
777-
'before' => '/*'.PHP_EOL.' @codingStandardsIgnoreFile'.PHP_EOL.' */',
778-
],
779-
'old style: start of file, single-line docblock comment' => [
780-
'before' => '/** @codingStandardsIgnoreFile */',
781-
],
782-
783-
// Deprecated syntax, late comment.
784-
'old style: late comment, slash comment' => [
785-
'before' => '',
786-
'after' => '// @codingStandardsIgnoreFile',
787-
],
788703
];
789704

790705
}//end dataSuppressFile()

0 commit comments

Comments
 (0)