coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Correct indent inside block, comments - feature request/question

Open arxeiss opened this issue 4 years ago • 2 comments

I have noticed there is no sniff that would handle correct indentation inside a block or comments etc. Or am I wrong and there is a sniff that would handle those situations?

There are sniffs for bad indentation of closing braces, inside arrays, etc. But not for this, as far as I know.

16 spaces instead of 4

if (!App::isProduction()) {
                return;
}

Bad indentation of doc block

class HealthChecksService
{
        /**
         * @param int|string $exitStatus
         */
    public function exitStatus(
        string $checkName,
        $exitStatus,
        ?string $log = null,
        int $retry = 3,
        float $timeout = 3
    ): void {
        $this->makeRequest("$exitStatus", $checkName, $log, $retry, $timeout);
    }
}

arxeiss avatar Oct 28 '21 13:10 arxeiss

I think it's solved by Generic.WhiteSpace.ScopeIndent

kukulich avatar Oct 29 '21 15:10 kukulich

I thought too, but it is not. I created file below and run Code Sniffer. This is result with 2 errors, but there are much more indent errors in the code.

./vendor/bin/phpcs --sniffs=Generic.WhiteSpace.ScopeIndent ./indent.php 
E 1 / 1 (100%)

FILE: indent.php
------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------
 18 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
    |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
 29 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 4
    |       |     (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------

Time: 87ms; Memory: 14MB

<?php

function add($a, $b)
{
    $ret = $a + $b;
            return $ret;
}

class Math
{
            /**
             * Perform addition
             */
    public function add($a, $b)
    {
                $ret = $a + $b;
        return $ret;
        } // <-- Line 18

    /**
     * Perform subtraction
     */
    public function sub($a, $b)
    {
        $ret = $a - $b;

            return $ret;
    }
    } // <-- Line 29

arxeiss avatar Oct 29 '21 21:10 arxeiss