prettier / prettier/plugin-php
Allow attributes to be placed above constructor properties
Personne n'a encore pris cette issue.
- Langage dominant
- PHP
- Étoiles
- 1.9k
- Forks
- 139
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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,
) {
}
}
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par l’exemple de playground lié et comparez l’entrée et la sortie pour comprendre comment les attributs des propriétés du constructeur sont actuellement formatés. La modification est terminée lorsque les attributs conservent leur placement d’origine chaque fois que le code résultant tient dans la largeur d’impression, tout en continuant à formater correctement les attributs trop volumineux.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- php
- Domaine
- tooling
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 42/100