plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Add option to define a minimal indentation

Open Angelisium opened this issue 3 years ago • 2 comments

Hi 👋 I don't know if many people would be interested, I think it would be nice to have an option to define a minimal indentation. like :

--minimal-tab-indent: <Number> (default = 0)

Who, according to --tab-width and --use-tabs would give : Input:

<?php

array_map(function($arg1,$arg2) use ( $var1, $var2 ) {
    return $arg1+$arg2/($var+$var2);
}, array("complex"=>"code","with"=>
    function() {return "inconsistent";}
,"formatting"=>"is", "hard" => "to", "maintain"=>true));

Output:

// With --tab-width=4, --use-tabs=false and --minimal-tab-indent=1
<?php

    array_map(
        function ($arg1, $arg2) use ($var1, $var2) {
            return $arg1 + $arg2 / ($var + $var2);
        },
        [
            "complex" => "code",
            "with" => function () {
                return "inconsistent";
            },
            "formatting" => "is",
            "hard" => "to",
            "maintain" => true,
        ]
    );

I know it's a really marginal addition but it makes me anxious not to have this indentation that I always use in all my projects 😭

Angelisium avatar Jan 26 '23 10:01 Angelisium

Hi @Angelisium, does this mean the entire source code would be indented by the given amount of tabs? Personally, I've never seen code formatted that way. What's the benefit of doing this?

czosel avatar Jan 26 '23 15:01 czosel

Sorry for the delay in responding, I did not see the notification.
Yes, it's to indent of +1 the whole document ; I don't think it has some benefit, personally I think it's just prettier.

I learned PHP a few years ago and it always seemed logical to me to indent the code between tag <?php ... ?> ; and it stayed even after I stopped using the ?> tag.

E.G. :

<?php
    // some stuff
    // foo bar
?>

As it is the case when I add CSS or JS between HTML tags.

E.G. :

<!DOCTYPE html>
<html lang="en">
    <!--  head -->
    <body>
        <style>
            body {
                /* some stuff */
            }
        </style>
    </body>
</html>

I know it's rare. I myself only do it when I'm working on solo projects (or personal projects of which I am the leader 😈) ; otherwise, I follow the formatting rule established beforehand (generally PSR-2/12 for simplicity)

I don't have many public examples... I found that in my gitlab code snippets: Time and Sql ; and this in my gitlab repo : Octave
there is not much code but it gives an idea of what it looks like with a +1 indentation everywhere.

Angelisium avatar Jan 26 '23 22:01 Angelisium