prettier / prettier/plugin-php

Allow attributes to be placed above constructor properties

オープン
#2,329 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

psr compat
主要言語
PHP
スター
1.9k
フォーク
139
PR マージ指標
30日以内にマージされた PR はありません

説明

Currently, attributes used on constructor properties are forcefully placed inline with the property (or above if it doesn't fit the print width).

This can result in chaotic code where the types and names of the properties are all over the place, making it much harder to scan.

I feel like it would be better to allow the attributes to retain their original placement, as long as everything fits within the print width.

Here's an example of this happening:

@prettier/plugin-php v0.22.2
Playground link

Input:

<?php

class VariantData extends Data
{
    public function __construct(
        #[Exists(Variant::class, 'id')]
        public int|Optional $id,

        public int|null $media_id,

        #[RequiredWithout('id'), Filled, StringType, Max(255)]
        public string $title,

        #[RequiredWithout('id'), Numeric, Min(0)]
        public string $price,

        #[Numeric, Min(0)]
        public string|null $compare_at_price,

        #[Min(0)]
        public int $min_stock,
    ) {
    }
}

Output:

<?php

class VariantData extends Data
{
    public function __construct(
        #[Exists(Variant::class, 'id')] public int|Optional $id,

        public int|null $media_id,

        #[
            RequiredWithout('id'),
            Filled,
            StringType,
            Max(255),
        ]
        public string $title,

        #[RequiredWithout('id'), Numeric, Min(0)] public string $price,

        #[Numeric, Min(0)] public string|null $compare_at_price,

        #[Min(0)] public int $min_stock,
    ) {
    }
}

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた playground の例から始め、入力と出力を比較して、constructor-property の属性が現在どのようにフォーマットされているかを理解します。結果のコードが印刷幅に収まる場合は常に属性が元の配置を維持し、それでも大きすぎる属性は適切にフォーマットされるようになれば、変更は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
php
領域
tooling
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。