Skip to content

Conversation

schlndh
Copy link

@schlndh schlndh commented Oct 11, 2025

Description

Fixes squizlabs/PHP_CodeSniffer#3556

Suggested changelog entry

Added --allow-empty-file-list argument to suppress "No files were checked error".

Related issues/external references

Fixes squizlabs/PHP_CodeSniffer#3556

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

@jrfnl
Copy link
Member

jrfnl commented Oct 11, 2025

@schlndh Thanks for this PR.

Some feedback:

src/Runner.php Outdated

$numFiles = count($todo);
if ($numFiles === 0) {
if ($numFiles === 0 && $this->config->allowEmptyFileList === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. I believe the flag (whatever it's going to be called) should only affect the exit code, not the error message.

The way this is coded now, if the flag is set, PHPCS would try to process an empty file list, while there is nothing to do.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use --report=json to achieve baseline-like behavior (gist: I'm not sure whether it's up-to-date). Therefore, I want phpcs to output JSON instead of nothing to stdout. Though, if necessary I could handle the empty output as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a reason to break things for everyone else.

Copy link
Author

@schlndh schlndh Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. I'm adding a new, non-default option to suppress the "No files were checked" error. I suppose that some people might prefer to have the error message and a 0 exit code, but I'm not breaking anything for them: they can simply keep the default behavior.

I'm definitely interested in not having the error message at all. Would you be willing to accept multiple configuration values? Something like empty_file_list: prohibit (default, error + exit code), warn (error message only, 0 exit code), allow (no error message, 0 exit code)?

@schlndh
Copy link
Author

schlndh commented Oct 11, 2025

@jrfnl

Can you explain why you added a CLI option instead of a config option ?

I plan to use it as a config option via <arg name="allow-empty-file-list"/> (mainly because of Phpstorm). But IMO having it as a configuration option only seems a bit inflexible. The default behavior makes sense if you run phpcs manually. So I can imagine someone adding --allow-empty-file-list to CI scripts, git hooks, ... but keeping the default behavior otherwise.

@jrfnl
Copy link
Member

jrfnl commented Oct 11, 2025

I plan to use it as a config option via <arg name="allow-empty-file-list"/> (mainly because of Phpstorm). But IMO having it as a configuration option only seems a bit inflexible. The default behavior makes sense if you run phpcs manually. So I can imagine someone adding --allow-empty-file-list to CI scripts, git hooks, ... but keeping the default behavior otherwise.

And that's perfectly possible with a config flag, just as well as with a CLI option, so I don't see why that would be a reason to have a CLI option.

Fixes squizlabs/PHP_CodeSniffer#3556

The "No files were checked" error can be undesirable in situations where
an external tools passes a list of files to phpcs to check, without
necessarily knowing whether the files are excluded or not.

Consider the following scenarios:

- CI running only on changed files.
- Git hooks.
- Phpstorm PHPCS inspection (currently it gives an error notification on
  excluded files).
@schlndh schlndh force-pushed the feature-allowSupressingNoFilesWereCheckedError branch from 0cdbdec to fbb065b Compare October 11, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4.0.x-dev: Option to ignore if no files were checked instead of exiting with an error code

2 participants