Skip to content

Cache makes phpcbf fix unexpected sniff #3781

Open
@takaram

Description

@takaram

Describe the bug
I ran phpcbf with --sniffs option.

$ vendor/bin/phpcbf --sniffs=Generic.PHP.DisallowShortOpenTag /path/to/files

I expected this command to only fix Generic.PHP.DisallowShortOpenTag, but some other errors are fixed too.

Code sample

<?

function test() {
if (true) {
  echo 1;
}
}

Custom ruleset

<?xml version="1.0" ?>
<ruleset>
  <rule ref="Generic.PHP.DisallowShortOpenTag"/>
  <rule ref="Generic.WhiteSpace.ScopeIndent"/>
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs --report=diff --sniffs=Generic.PHP.DisallowShortOpenTag --cache=.phpcs-cache test.php
  3. See the result
--- test.php
+++ PHP_CodeSniffer
@@ -1,7 +1,7 @@
-<?
+<?php

 function test() {
 if (true) {
-  echo 1;
+          echo 1;
 }
 }

Expected behavior
Indentation of line 5 should not be fixed.

Removing --cache solves the problem.

Versions (please complete the following information):

  • OS: Ubuntu 18.04 on Windows 10 WSL 2
  • PHP: 8.2
  • PHPCS: 3.7.2
  • Standard: Custom

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