0

I've been playing around with Laravel Pint and I can't seem to make it work the way I want.

My goal is to have the curly brackets inline with class or function

so instead

function test() 
{

}

I want to have a format like this

function test() {

}

I have this on pint.json but doesn't change anything.

{
    "preset": "laravel",
    "braces": {
        "position_after_functions_and_oop_constructs": "same",
        "position_after_anonymous_constructs": "same"
    }
}

I event tried using psr12 preset and still does not change anything

{
    "preset": "psr12"
}

Additionally, I'd like to know how I can allow this format

if ( !$num ) 
    return;

it changes to this after running pint, (it removes the space between if condition and added a space after ! and wrap the state with brackets)

if (! $num) {
    return;
}
SymmetricsWeb
  • 586
  • 6
  • 20

1 Answers1

3

The rule in a pint.json will be

{
    "preset": "laravel",
    "rules": {
        "not_operator_with_successor_space": false,
        "curly_braces_position": {
            "functions_opening_brace": "same_line",
            "classes_opening_brace": "same_line"

        }

    }
}

As per PHP-CS-Fixer Rule, use curly_braces_position

enter image description here

enter image description here

Ref: How with pint can I remove space after negative “!” symbol?

John Lobo
  • 14,355
  • 2
  • 10
  • 20
  • 1
    Thanks, and relating to `if` statement without brackets, I found out its not supported by PHP-CS-FIXER https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/2780 – SymmetricsWeb Feb 19 '23 at 05:24