Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for formatting-related requirements of PSR-12 #4

Closed
24 tasks done
lkrms opened this issue Jun 17, 2023 · 1 comment
Closed
24 tasks done

Add support for formatting-related requirements of PSR-12 #4

lkrms opened this issue Jun 17, 2023 · 1 comment

Comments

@lkrms
Copy link
Owner

lkrms commented Jun 17, 2023

PrettyPHP's default formatting is largely PSR-12 compliant, but there are some differences to address.

Parts of PSR-12, e.g. PascalCase class names, fall outside the scope of a formatter and won't be implemented, although exceptions are sometimes made (use import statements are already sorted by default, for example).

  • LF line endings
  • Indent of 4 spaces
  • Line length "SHOULD NOT" exceed 80 characters and "MUST" have a soft limit of 120 characters
  • One statement per line (PreserveOneLineStatements must not be enabled)
  • Blank lines after "header blocks" (SpaceDeclarations and SortImports mandatory):
    • <?php
    • file-level docblock (blank line only applied before namespace currently)
    • declare statements
    • namespace declaration
    • class use statements
    • function use statements
    • constant use statements
  • Allow breaking over multiple lines if every item is on its own line (NoMixedLists mandatory):
    • implements and extends interfaces
      • Trigger if a newline appears after implements or extends, not just between first two interfaces
      • Add a newline before the opening brace of an anonymous class with an interface list that wraps
    • Parameters in function declarations
    • Variables in anonymous function use declarations
    • Arguments in function calls
    • Statements in for loops
  • One-line declare at line 1 of files also containing markup: <?php declare(strict_types=1) ?>
    • Suppress newline before close tag even if present in source
  • Force newlines before and after control structure expressions split over multiple lines
  • Add whitespace between exception types in catch
  • Enforce newline before first method in multiline method chains
@lkrms
Copy link
Owner Author

lkrms commented May 4, 2024

With the exception of line length enforcement, which is being tracked in #1, pretty-php's PSR-12 compliance is complete.

@lkrms lkrms closed this as completed May 4, 2024
@lkrms lkrms unpinned this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant