Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR1.Files.SideEffects.FoundWithSymbols not being ignored #3386

Closed
quasipickle opened this issue Jul 9, 2021 · 7 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#54
Closed

Comments

@quasipickle
Copy link

quasipickle commented Jul 9, 2021

Describe the bug
A line that violates the PSR1.Files.SideEffects.FoundWithSymbols rule still generates a warning about it even when preceded with // phpcs:ignore

Code sample

<?php

// phpcs:ignore
define('MYCONST', 'myval');
$var = 'test';

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
-----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------
 1 | WARNING | A file should declare new symbols (classes, functions, constants, etc.) and
   |         | cause no other side effects, or it should execute logic with side effects, but
   |         | should not do both. The first symbol is defined on line 4 and the first side
   |         | effect is on line 5. (PSR1.Files.SideEffects.FoundWithSymbols)
-----------------------------------------------------------------------------------------------

Expected behavior
No warnings get generated

Versions (please complete the following information):

  • OS: Debian 8.11
  • PHP: 7.3.11
  • PHPCS: 3.6.0
  • Standard: PSR12

Additional context
When the offending line has a space removed between the parameters, thereby violating Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma, that error does get ignored.

If I instead wrap the line in disable/enable, the warning does not get generated

<?php

// phpcs:disable
define('MYCONST', 'myval');
// phpcs:enable
$var = 'test';

If I disable just that rule, the warning does get generated:

<?php

// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
define('MYCONST', 'myval');
// phpcs:enable
$var = 'test';
@gsherwood
Copy link
Member

Using the enable/disable method is exactly how this is done, as was included in the 3.2.0 release. The ignore comment just tells PHPCS to ignore any violations on that line, but there aren't any as the sniff adds it to the first line of the file.

Replicating the release notes here for clarrity:

    - PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax
      -- The sniff will no longer check any code that is between phpcs:disable and phpcs:enable comments
      -- The sniff does not support phpcs:ignore; you must wrap code structures with disable/enable comments
      -- Previously, there was no way to have this sniff ignore parts of a file

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Jul 18, 2021
@gsherwood gsherwood moved this from Idea Bank to Track in PHPCS v3 Development Jul 18, 2021
@quasipickle
Copy link
Author

Ah, I see. Then maybe instead of a bug report, this could be added to documentation somewhere?

@yakatz
Copy link

yakatz commented Dec 19, 2022

@gsherwood I found this issue while searching to see why FoundWithSymbols wasn't respected as part of // phpcs:disable.

My file has this as the first two lines:

<?php
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols

If I have just // phpcs:disable, it ignores everything in the file. This seems to be contrary to the release notes for 3.2.0.

I am using version 3.7.1.

@mindriven
Copy link

I'm facing same inconsistency as @yakatz. Any movement on that?

@nwehrhan
Copy link

nwehrhan commented Mar 2, 2023

Having this issue as well. I am using version 3.7.1.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 2, 2023

I have opened a PR to hopefully fix this issue. Please have a look at PR #3772.

Once that PR has been merged, the below code sample will work:

<?php

// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
define('MYCONST', 'myval');
// phpcs:enable
$var = 'test';

Testing appreciated.

@jrfnl
Copy link
Contributor

jrfnl commented Dec 8, 2023

FYI: the fix for this issue is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
6 participants