Skip to content

File without extensions are scanned despite --extensions #1317

@vaceletm

Description

@vaceletm

Describe the bug

Status of short_open_tag impact how phpcs determine if a file is php or not, despite --extensions being set.

To reproduce

  1. Create an file touch foo
  2. Run phpcs with any ruleset and short open tags allowed php -d short_open_tag=On src/vendor/bin/phpcs -s --extensions=php --standard=Squiz foo
  3. phpcs ignore foo as non php file.
  4. Run phpcs without short open tags: php -d short_open_tag=Off src/vendor/bin/phpcs -s --extensions=php --standard=Squiz foo
  5. phpcs raise an error:
FILE: 'foo --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 | WARNING | No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them. (Internal.NoCodeFound) --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Time: 29ms; Memory: 16MB 

Expected behavior

As file has no extension, it should be ignored, regardless of the status of short_open_tag

Versions (please complete the following information)

Operating System Nix
PHP version 8.4.13
PHP_CodeSniffer version 4.0.0
Standard anyone
Install type composer local

Additional context

I face this issue because I run phpcs in the context of CI and, in order to speed up the process, I pass to the CLI the list of files modified in a change. I caught the issue because I modified a .gitignore file and this was flagged with reported error.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the 4.x branch of PHP_CodeSniffer.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions