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
880 stars 54 forks source link

Generic/InlineControlStructure: remove redundant condition #596

Open rodrigoprimo opened 4 weeks ago

rodrigoprimo commented 4 weeks ago

Description

As discussed in https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/482#pullrequestreview-2062765716 (see "Commit 4" and "Commit 5" sections), this PR removes a redundant condition that was added in https://github.com/PHPCSStandards/PHP_CodeSniffer/commit/fbea31936a2fe50ce7d4d8739d17412f0301237c to support JS braceless do-while loops. A subsequent commit added a similar code to support braceless do-while loops (plus for/while loops without body) for PHP. The new code also works for JS (https://github.com/PHPCSStandards/PHP_CodeSniffer/commit/13c803bb14d01641ca089d515eab4287c71e8156).

There are a few syntax error cases that were handled by the code that is removed by this commit and are not handled by the code introduced in https://github.com/PHPCSStandards/PHP_CodeSniffer/commit/13c803bb14d01641ca089d515eab4287c71e8156. Without the removed code, they are now handled in the if condition right below. I added two tests with those cases to ensure the sniff continues working as expected.

The PR also includes a separate commit to rename the JS test case file.

Related issues/external references

Originally discussed in https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/482#pullrequestreview-2062765716

Types of changes

PR checklist