Laravel Pint JSON配置不起作用。

huangapple go评论116阅读模式
英文:

Laravel Pint json config not wokring

问题

我一直在尝试使用Laravel Pint,但似乎无法按照我想要的方式使其工作。

我的目标是使大括号与类或函数的定义在同一行,而不是像这样:

function test() 
{
    
}

我想要的格式是这样的:

function test() {
    
}

我在pint.json 文件中使用了以下配置,但没有改变任何东西:

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

我甚至尝试使用psr12 预设,但仍然没有改变任何东西:

{
    "preset": "psr12"
}

此外,我想知道如何允许这种格式:

if ( !$num ) 
    return;

运行Pint之后,它会更改为以下格式(它移除了if条件之间的空格,添加了!后面的空格,并在状态周围添加了括号):

if (! $num) {
    return;
}
英文:

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;
}

答案1

得分: 3

pint.json 文件中的规则将会是:

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

根据 PHP-CS-Fixer 的规则,使用 curly_braces_position

Laravel Pint JSON配置不起作用。

Laravel Pint JSON配置不起作用。

参考:如何在pint中删除负号“!”符号后的空格?

英文:

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

Laravel Pint JSON配置不起作用。

Laravel Pint JSON配置不起作用。

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

huangapple
  • 本文由 发表于 2023年2月19日 12:04:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定