prettier-plugin-laravel-blade 0.1.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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/blade-formatter.js +4490 -0
- package/package.json +50 -0
- package/src/index.mjs +191 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Helge Sverre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# prettier-plugin-laravel-blade
|
|
2
|
+
|
|
3
|
+
Prettier plugin for formatting Laravel Blade templates, powered by a real AST parser.
|
|
4
|
+
|
|
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`)
|
|
10
|
+
- Echo statements (`{{ }}`, `{!! !!}`)
|
|
11
|
+
- Nested and interleaved HTML/Blade structures
|
|
12
|
+
- Error recovery for malformed templates
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev prettier-plugin-laravel-blade prettier
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
The plugin automatically formats `.blade.php` files:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Format all Blade files
|
|
26
|
+
prettier --write "**/*.blade.php"
|
|
27
|
+
|
|
28
|
+
# Check formatting
|
|
29
|
+
prettier --check "**/*.blade.php"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or configure in `.prettierrc`:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"plugins": ["prettier-plugin-laravel-blade"],
|
|
37
|
+
"overrides": [
|
|
38
|
+
{
|
|
39
|
+
"files": "*.blade.php",
|
|
40
|
+
"options": {
|
|
41
|
+
"tabWidth": 4,
|
|
42
|
+
"printWidth": 120
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Options
|
|
50
|
+
|
|
51
|
+
### Standard Prettier Options
|
|
52
|
+
|
|
53
|
+
| Option | Default | Description |
|
|
54
|
+
|--------|---------|-------------|
|
|
55
|
+
| `tabWidth` | `4` | Number of spaces per indentation level |
|
|
56
|
+
| `useTabs` | `false` | Use tabs instead of spaces |
|
|
57
|
+
| `printWidth` | `120` | Line width before wrapping attributes |
|
|
58
|
+
|
|
59
|
+
### Blade-Specific Options
|
|
60
|
+
|
|
61
|
+
| Option | Default | Choices | Description |
|
|
62
|
+
|--------|---------|---------|-------------|
|
|
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 |
|
|
70
|
+
|
|
71
|
+
## How It Works
|
|
72
|
+
|
|
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.
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|