prettier-plugin-laravel-blade 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,10 +3,10 @@
3
3
  Prettier plugin for formatting Laravel Blade templates, powered by a real AST parser.
4
4
 
5
5
  Unlike regex-based alternatives, this plugin uses a full recursive-descent parser that correctly handles:
6
- - 108 Blade directives
7
- - Blade components (`<x-alert>`) with slots
8
- - Alpine.js attributes (`x-data`, `@click`, `:bind`)
9
- - Livewire attributes (`wire:model`, `wire:click`)
6
+ - 108 Blade directives (`@if`, `@foreach`, `@auth`, `@switch`, `@push`, `@section`, etc.)
7
+ - Blade components (`<x-alert>`) with named slots and nested content
8
+ - Alpine.js attributes (`x-data`, `@click`, `:bind`, `x-show`, `x-transition`)
9
+ - Livewire attributes (`wire:model`, `wire:click`, `wire:poll`)
10
10
  - Echo statements (`{{ }}`, `{!! !!}`)
11
11
  - Nested and interleaved HTML/Blade structures
12
12
  - Error recovery for malformed templates
@@ -19,17 +19,25 @@ npm install --save-dev prettier-plugin-laravel-blade prettier
19
19
 
20
20
  ## Usage
21
21
 
22
- The plugin automatically formats `.blade.php` files:
22
+ Add the plugin to your `.prettierrc`:
23
+
24
+ ```json
25
+ {
26
+ "plugins": ["prettier-plugin-laravel-blade"]
27
+ }
28
+ ```
29
+
30
+ Then format your Blade templates:
23
31
 
24
32
  ```bash
25
33
  # Format all Blade files
26
34
  prettier --write "**/*.blade.php"
27
35
 
28
- # Check formatting
36
+ # Check formatting (CI)
29
37
  prettier --check "**/*.blade.php"
30
38
  ```
31
39
 
32
- Or configure in `.prettierrc`:
40
+ ### Full configuration example
33
41
 
34
42
  ```json
35
43
  {
@@ -39,7 +47,13 @@ Or configure in `.prettierrc`:
39
47
  "files": "*.blade.php",
40
48
  "options": {
41
49
  "tabWidth": 4,
42
- "printWidth": 120
50
+ "printWidth": 120,
51
+ "bladeSlotFormatting": "compact",
52
+ "bladeSlotNameStyle": "colon",
53
+ "bladeSlotSpacing": "after",
54
+ "bladeWrapAttributes": "auto",
55
+ "bladeAttributeSort": "by_type",
56
+ "bladeSelfClosingStyle": "preserve"
43
57
  }
44
58
  }
45
59
  ]
@@ -60,17 +74,19 @@ Or configure in `.prettierrc`:
60
74
 
61
75
  | Option | Default | Choices | Description |
62
76
  |--------|---------|---------|-------------|
63
- | `bladeQuoteStyle` | `"preserve"` | `single`, `double`, `preserve` | Quote style for HTML attributes |
64
- | `bladeDirectiveSpacing` | `"between_blocks"` | `between_blocks`, `none`, `preserve` | Spacing between directive blocks |
65
- | `bladeSlotFormatting` | `"compact"` | `compact`, `block` | Formatting style for component slots |
66
- | `bladeWrapAttributes` | `"auto"` | `auto`, `always`, `never` | When to wrap attributes to multiple lines |
67
- | `bladeAttributeSort` | `"none"` | `none`, `alphabetical`, `by_type` | How to sort HTML attributes |
68
- | `bladeClosingBracketStyle` | `"same_line"` | `same_line`, `new_line` | Closing bracket position when attributes wrap |
69
- | `bladeSelfClosingStyle` | `"preserve"` | `preserve`, `always`, `never` | How to format empty elements |
77
+ | `bladeQuoteStyle` | `"preserve"` | `single`, `double`, `preserve` | `'` vs `"` in attribute values |
78
+ | `bladeDirectiveSpacing` | `"between_blocks"` | `between_blocks`, `none`, `preserve` | Blank lines between `@if`, `@foreach`, etc. |
79
+ | `bladeSlotFormatting` | `"compact"` | `compact`, `block` | Extra newlines inside `<x-slot>` blocks |
80
+ | `bladeSlotNameStyle` | `"colon"` | `colon`, `attribute`, `preserve` | `<x-slot:name>` vs `<x-slot name="...">` |
81
+ | `bladeSlotSpacing` | `"after"` | `none`, `after`, `before`, `around` | Blank lines before/after `<x-slot>` tags |
82
+ | `bladeWrapAttributes` | `"auto"` | `auto`, `always`, `never` | Multi-line attributes when line is too long |
83
+ | `bladeAttributeSort` | `"none"` | `none`, `alphabetical`, `by_type` | Reorder attributes (HTML, Alpine, Livewire) |
84
+ | `bladeClosingBracketStyle` | `"same_line"` | `same_line`, `new_line` | Where `>` sits when attributes wrap |
85
+ | `bladeSelfClosingStyle` | `"preserve"` | `preserve`, `always`, `never` | `<x-icon />` vs `<x-icon></x-icon>` for empty tags |
70
86
 
71
87
  ## How It Works
72
88
 
73
- This plugin compiles a Dart-based Blade parser/formatter to JavaScript (via `dart2js`), running entirely in-process with zero IPC overhead. The parser produces a full AST and the formatter is idempotent and deterministic.
89
+ This plugin compiles a Dart-based Blade parser/formatter to JavaScript via `dart2js`, running entirely in-process with zero IPC overhead. The parser produces a full AST and the formatter is idempotent and deterministic.
74
90
 
75
91
  ## License
76
92