wongjn / vscode-php-sniffer

Visual Studio Code extension for PHP_Codesniffer validation and formatting.
https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer
MIT License
46 stars 7 forks source link

Indentation not fixed completely when adding and removing curly brace #36

Closed finn-matti closed 4 years ago

finn-matti commented 4 years ago

Describe the bug When using format on save ad when accidently adding a curly brace (or similar), saving, removing the brace and saving again, the indentation is not fixed completely.

Gif showing the problem:

Kapture 2020-03-25 at 15 35 01

To Reproduce Steps to reproduce the behavior:

  1. Add curly brace, where it doesn't belong
  2. Save
  3. Remove curly brace
  4. Save again

Expected behavior Everything should look like before with all correct indentations.

Environment

Extension settings

{
    "phpSniffer.run": "onSave",
    "phpSniffer.onTypeDelay": 250,
    "phpSniffer.executablesFolder": "",
    "phpSniffer.autoDetect": false,
    "phpSniffer.standard": "~/phpcs.xml",
    "phpSniffer.snippetExcludeSniffs" : [],
}

Additional context Contents of phpcs.xml

<?xml version="1.0" ?>
<ruleset name="Custom Standard">
    <rule ref="PSR2">
        <exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace" />
    </rule>
</ruleset>
wongjn commented 4 years ago

This is something to do with PHP_CodeSniffer package itself, not this extension.

You can see this by running phpcbf from the command line, e.g.

Given ./index.php that contains:

<?php

<?php
$a = [
'b' => [
'c' => 1,
]
];

Running ./vendor/bin/phpcbf --standard=PSR2 ./index.php does nothing.

Please consider raising an issue in the squizlabs/PHP_CodeSniffer repo.