PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
805 stars 47 forks source link

Tokenizers/Comment: add tests + fix two edge case bugs #494

Closed jrfnl closed 2 months ago

jrfnl commented 2 months ago

Description

Tokenizers/Comment: add tests

The Tokenizers\Comment class did not have any tests associated with it. This commit fixes that and documents the existing behaviour.

Note: code coverage is as high as it can go, but not 100%. The reason for this, is the tokenizer debug statements, which are conditional on a verbosity flag, which is turned off for the tests.

Loosely related to #484.

Tokenizers/PHP: bug fix - empty block comment

This commit fixes an edge case tokenizer bug, where a - completely empty, not even whitespace - block comment, would be tokenized as a docblock.

Without this commit, the /**/ code snippet was tokenized as:

  8 | L07 | C  1 | CC 0 | ( 0) | T_DOC_COMMENT_OPEN_TAG     | [  4]: /**/
  9 | L07 | C  5 | CC 0 | ( 0) | T_DOC_COMMENT_CLOSE_TAG    | [  0]:

With the fix applied, it will be tokenized as:

  8 | L07 | C  1 | CC 0 | ( 0) | T_COMMENT                  | [  4]: /**/

Tokenizers/Comment: bug fix - empty docblock

This commit fixes an edge case tokenizer bug, where a - completely empty, not even whitespace - DocBlock, would not be tokenized correctly.

Without this commit, the /***/ code snippet was tokenized as:

 13 | L10 | C  1 | CC 0 | ( 0) | T_DOC_COMMENT_OPEN_TAG     | [  5]: /***/
 14 | L10 | C  6 | CC 0 | ( 0) | T_DOC_COMMENT_CLOSE_TAG    | [  0]:

With the fix applied, it will be tokenized as:

 13 | L10 | C  1 | CC 0 | ( 0) | T_DOC_COMMENT_OPEN_TAG     | [  3]: /**
 14 | L10 | C  4 | CC 0 | ( 0) | T_DOC_COMMENT_CLOSE_TAG    | [  2]: */

Tokenizers/Comment: minor tweaks

Girlscouting.

Suggested changelog entry

Related issues/external references

Preliminary work to allow for #484 later on.

Related #146

Types of changes

jrfnl commented 2 months ago

Rebased without changes. Merging once the build passes.